Hackathon Repo

Dependencies:   C12832

Committer:
sarahmarshy
Date:
Thu Sep 28 18:39:18 2017 +0000
Revision:
1:bab7fe330b43
Parent:
0:6b7ffde9f287
Child:
6:8e31aead85c3
Set simple mbed_app.json for non-cloud application

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 0:6b7ffde9f287 38 if (blink == 1 && blink_id == NULL) {
sarahmarshy 0:6b7ffde9f287 39 blink_id = queue.call_every(500, blink_led);
sarahmarshy 0:6b7ffde9f287 40 }
sarahmarshy 0:6b7ffde9f287 41 else if (blink == 0) {
sarahmarshy 0:6b7ffde9f287 42 queue.cancel(blink_id);
sarahmarshy 0:6b7ffde9f287 43 blink_id = NULL;
sarahmarshy 0:6b7ffde9f287 44 led = 1;
sarahmarshy 0:6b7ffde9f287 45 }
sarahmarshy 0:6b7ffde9f287 46 }
sarahmarshy 0:6b7ffde9f287 47
sarahmarshy 0:6b7ffde9f287 48 // MESSAGE RESOURCE PUT HANDLER
sarahmarshy 0:6b7ffde9f287 49
sarahmarshy 0:6b7ffde9f287 50 // DISPLAY RESOURCE POST HANDLER
sarahmarshy 0:6b7ffde9f287 51
sarahmarshy 0:6b7ffde9f287 52 void read_potentiometer() {
sarahmarshy 0:6b7ffde9f287 53 static float potentiometer_val = 0;
sarahmarshy 0:6b7ffde9f287 54 if ((float)pot1 != potentiometer_val) {
sarahmarshy 0:6b7ffde9f287 55 potentiometer_val = (float)pot1;
sarahmarshy 0:6b7ffde9f287 56 char val[13];
sarahmarshy 0:6b7ffde9f287 57 sprintf(val, "%.2f", potentiometer_val);
sarahmarshy 0:6b7ffde9f287 58 // UPDATE RESOURCE VALUE
sarahmarshy 0:6b7ffde9f287 59 }
sarahmarshy 0:6b7ffde9f287 60 }
sarahmarshy 0:6b7ffde9f287 61
sarahmarshy 0:6b7ffde9f287 62 int main()
sarahmarshy 0:6b7ffde9f287 63 {
sarahmarshy 0:6b7ffde9f287 64 // SimpleClient is used for registering and unregistering resources to a server.
sarahmarshy 0:6b7ffde9f287 65 SimpleM2MClient mbedClient;
sarahmarshy 0:6b7ffde9f287 66
sarahmarshy 0:6b7ffde9f287 67 if (!mbedClient.init()) {
sarahmarshy 0:6b7ffde9f287 68 printf("Initialization failed, exiting application!\n");
sarahmarshy 0:6b7ffde9f287 69 return 1;
sarahmarshy 0:6b7ffde9f287 70 }
sarahmarshy 0:6b7ffde9f287 71
sarahmarshy 0:6b7ffde9f287 72 // ADD RESOURCES HERE
sarahmarshy 0:6b7ffde9f287 73
sarahmarshy 0:6b7ffde9f287 74 mbedClient.start_client();
sarahmarshy 0:6b7ffde9f287 75 queue.call_every(100, read_potentiometer);
sarahmarshy 0:6b7ffde9f287 76 while(mbedClient.is_register_called()){
sarahmarshy 0:6b7ffde9f287 77 wait_ms(100);
sarahmarshy 0:6b7ffde9f287 78 queue.dispatch(0);
sarahmarshy 0:6b7ffde9f287 79 }
sarahmarshy 1:bab7fe330b43 80 }