Revision Commit

Dependencies:   C12832

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

2_connected_app/main.h

Committer:
sarahmarshy
Date:
2017-09-28
Revision:
0:6b7ffde9f287
Child:
1:bab7fe330b43

File content as of revision 0:6b7ffde9f287:

//----------------------------------------------------------------------------
// The confidential and proprietary information contained in this file may
// only be used by a person authorised under and to the extent permitted
// by a subsisting licensing agreement from ARM Limited or its affiliates.
//
// (C) COPYRIGHT 2016 ARM Limited or its affiliates.
// ALL RIGHTS RESERVED
//
// This entire notice must be reproduced on all copies of this file
// and copies of this file may only be made by a person if such person is
// permitted to do so under the terms of a subsisting license agreement
// from ARM Limited or its affiliates.
//----------------------------------------------------------------------------
#include "simplem2mclient.h"
#include "mbed.h"
#include "C12832.h"

C12832 lcd(D11, D13, D6, D7, D10);
AnalogIn pot1(A0);
EventQueue queue;
DigitalOut led(D9, 1);

// DECLARE RESOURCES HERE

void lcd_print(const char* message) {
    lcd.cls();
    lcd.locate(0,3);
    lcd.printf(message);
}

void blink_led() {
    led = !led;
}

void set_blink_led(int *) {
    static int blink_id = NULL;
    // GET VALUE OF LED RESOURCE
    if (blink == 1 && blink_id == NULL) {
        blink_id = queue.call_every(500, blink_led);
    }
    else if (blink == 0) {
        queue.cancel(blink_id);
        blink_id = NULL;
        led = 1;
    }
}

// MESSAGE RESOURCE PUT HANDLER

// DISPLAY RESOURCE POST HANDLER

void read_potentiometer() {
    static float potentiometer_val = 0;
    if ((float)pot1 != potentiometer_val) {
        potentiometer_val = (float)pot1;
        char val[13];
        sprintf(val, "%.2f", potentiometer_val);
        // UPDATE RESOURCE VALUE
    }
 }

int main()
{
    // SimpleClient is used for registering and unregistering resources to a server.
    SimpleM2MClient mbedClient;

    if (!mbedClient.init()) {
        printf("Initialization failed, exiting application!\n");
        return 1;
    }

    // ADD RESOURCES HERE

    mbedClient.start_client();
    queue.call_every(100, read_potentiometer);
    while(mbedClient.is_register_called()){
        wait_ms(100);
        queue.dispatch(0);
    }
}