test fork

Dependencies:   C12832

Fork of seoul-iot-hackathon-demo by Seoul IoT Hackathon Admins

Committer:
sarahmarshy
Date:
Mon Oct 02 14:56:42 2017 +0000
Revision:
6:8e31aead85c3
Parent:
1:bab7fe330b43
Add spaces for new code

Who changed what in which revision?

UserRevisionLine numberNew contents of line
sarahmarshy 0:6b7ffde9f287 1 //----------------------------------------------------------------------------
sarahmarshy 0:6b7ffde9f287 2 // The confidential and proprietary information contained in this file may
sarahmarshy 0:6b7ffde9f287 3 // only be used by a person authorised under and to the extent permitted
sarahmarshy 0:6b7ffde9f287 4 // by a subsisting licensing agreement from ARM Limited or its affiliates.
sarahmarshy 0:6b7ffde9f287 5 //
sarahmarshy 0:6b7ffde9f287 6 // (C) COPYRIGHT 2016 ARM Limited or its affiliates.
sarahmarshy 0:6b7ffde9f287 7 // ALL RIGHTS RESERVED
sarahmarshy 0:6b7ffde9f287 8 //
sarahmarshy 0:6b7ffde9f287 9 // This entire notice must be reproduced on all copies of this file
sarahmarshy 0:6b7ffde9f287 10 // and copies of this file may only be made by a person if such person is
sarahmarshy 0:6b7ffde9f287 11 // permitted to do so under the terms of a subsisting license agreement
sarahmarshy 0:6b7ffde9f287 12 // from ARM Limited or its affiliates.
sarahmarshy 0:6b7ffde9f287 13 //----------------------------------------------------------------------------
sarahmarshy 0:6b7ffde9f287 14 #include "simplem2mclient.h"
sarahmarshy 0:6b7ffde9f287 15 #include "mbed.h"
sarahmarshy 0:6b7ffde9f287 16 #include "C12832.h"
sarahmarshy 0:6b7ffde9f287 17
sarahmarshy 0:6b7ffde9f287 18 C12832 lcd(D11, D13, D6, D7, D10);
sarahmarshy 0:6b7ffde9f287 19 AnalogIn pot1(A0);
sarahmarshy 0:6b7ffde9f287 20 EventQueue queue;
sarahmarshy 0:6b7ffde9f287 21 DigitalOut led(D9, 1);
sarahmarshy 0:6b7ffde9f287 22
sarahmarshy 0:6b7ffde9f287 23 // DECLARE RESOURCES HERE
sarahmarshy 0:6b7ffde9f287 24
sarahmarshy 0:6b7ffde9f287 25 void lcd_print(const char* message) {
sarahmarshy 0:6b7ffde9f287 26 lcd.cls();
sarahmarshy 0:6b7ffde9f287 27 lcd.locate(0,3);
sarahmarshy 0:6b7ffde9f287 28 lcd.printf(message);
sarahmarshy 0:6b7ffde9f287 29 }
sarahmarshy 0:6b7ffde9f287 30
sarahmarshy 0:6b7ffde9f287 31 void blink_led() {
sarahmarshy 0:6b7ffde9f287 32 led = !led;
sarahmarshy 0:6b7ffde9f287 33 }
sarahmarshy 0:6b7ffde9f287 34
sarahmarshy 0:6b7ffde9f287 35 void set_blink_led(int *) {
sarahmarshy 0:6b7ffde9f287 36 static int blink_id = NULL;
sarahmarshy 0:6b7ffde9f287 37 // GET VALUE OF LED RESOURCE
sarahmarshy 6:8e31aead85c3 38
sarahmarshy 6:8e31aead85c3 39
sarahmarshy 0:6b7ffde9f287 40 if (blink == 1 && blink_id == NULL) {
sarahmarshy 0:6b7ffde9f287 41 blink_id = queue.call_every(500, blink_led);
sarahmarshy 0:6b7ffde9f287 42 }
sarahmarshy 0:6b7ffde9f287 43 else if (blink == 0) {
sarahmarshy 0:6b7ffde9f287 44 queue.cancel(blink_id);
sarahmarshy 0:6b7ffde9f287 45 blink_id = NULL;
sarahmarshy 0:6b7ffde9f287 46 led = 1;
sarahmarshy 0:6b7ffde9f287 47 }
sarahmarshy 0:6b7ffde9f287 48 }
sarahmarshy 0:6b7ffde9f287 49
sarahmarshy 0:6b7ffde9f287 50 // MESSAGE RESOURCE PUT HANDLER
sarahmarshy 0:6b7ffde9f287 51
sarahmarshy 6:8e31aead85c3 52
sarahmarshy 0:6b7ffde9f287 53 // DISPLAY RESOURCE POST HANDLER
sarahmarshy 0:6b7ffde9f287 54
sarahmarshy 6:8e31aead85c3 55
sarahmarshy 0:6b7ffde9f287 56 void read_potentiometer() {
sarahmarshy 0:6b7ffde9f287 57 static float potentiometer_val = 0;
sarahmarshy 0:6b7ffde9f287 58 if ((float)pot1 != potentiometer_val) {
sarahmarshy 0:6b7ffde9f287 59 potentiometer_val = (float)pot1;
sarahmarshy 0:6b7ffde9f287 60 char val[13];
sarahmarshy 0:6b7ffde9f287 61 sprintf(val, "%.2f", potentiometer_val);
sarahmarshy 0:6b7ffde9f287 62 // UPDATE RESOURCE VALUE
sarahmarshy 6:8e31aead85c3 63
sarahmarshy 6:8e31aead85c3 64
sarahmarshy 0:6b7ffde9f287 65 }
sarahmarshy 0:6b7ffde9f287 66 }
sarahmarshy 0:6b7ffde9f287 67
sarahmarshy 0:6b7ffde9f287 68 int main()
sarahmarshy 0:6b7ffde9f287 69 {
sarahmarshy 0:6b7ffde9f287 70 // SimpleClient is used for registering and unregistering resources to a server.
sarahmarshy 0:6b7ffde9f287 71 SimpleM2MClient mbedClient;
sarahmarshy 0:6b7ffde9f287 72
sarahmarshy 0:6b7ffde9f287 73 if (!mbedClient.init()) {
sarahmarshy 0:6b7ffde9f287 74 printf("Initialization failed, exiting application!\n");
sarahmarshy 0:6b7ffde9f287 75 return 1;
sarahmarshy 0:6b7ffde9f287 76 }
sarahmarshy 0:6b7ffde9f287 77
sarahmarshy 0:6b7ffde9f287 78 // ADD RESOURCES HERE
sarahmarshy 0:6b7ffde9f287 79
sarahmarshy 0:6b7ffde9f287 80 mbedClient.start_client();
sarahmarshy 0:6b7ffde9f287 81 queue.call_every(100, read_potentiometer);
sarahmarshy 0:6b7ffde9f287 82 while(mbedClient.is_register_called()){
sarahmarshy 0:6b7ffde9f287 83 wait_ms(100);
sarahmarshy 0:6b7ffde9f287 84 queue.dispatch(0);
sarahmarshy 0:6b7ffde9f287 85 }
sarahmarshy 1:bab7fe330b43 86 }