SmartREST client reference implementation for the u-blox C027 mbed compatible device.

Dependencies:   C027 C027_Support mbed mbed-rtos MbedSmartRest LM75B MMA7660 C12832

Fork of MbedSmartRestTest by Vincent Wochnik

io.cpp

Committer:
vwochnik
Date:
2014-02-18
Revision:
14:56da550a1baa
Parent:
12:beb64aa0da86
Child:
15:0ccf0f530a05

File content as of revision 14:56da550a1baa:

#include "io.h"
#include "rtos.h"

#define S_INIT 0
#define S_OPEN 1
#define S_GONE 2

void thread_callback(void const*);

// Using Arduino pin notation
LM75B tempSensor(SDA, SCL);
MMA7660 accSensor(p28, p27);
DigitalIn button(p14);
//C12832 lcdDisplay(D11, D13, D12, D7, D10);

Thread worker(thread_callback);

uint8_t tempState = S_INIT;
uint8_t accState = S_INIT;
uint32_t count = 0;

float temperature()
{
    if ((tempState == S_INIT) && (tempSensor.open()))
        tempState = S_OPEN;
    else
        tempState = S_GONE;
    
    if (tempState == S_OPEN)
        return tempSensor.temp();

    return 0.0;
}

acceleration_t acceleration()
{
    float data[3];
    acceleration_t ret = { 0.0, 0.0, 0.0 };

    if ((accState == S_INIT) && (accSensor.testConnection()))
        accState = S_OPEN;
    else
        accState = S_GONE;
    
    if (accState == S_OPEN) {
        accSensor.readData(data);
        ret.x = data[0];
        ret.y = data[1];
        ret.z = data[2];
    }

    return ret;
}

uint32_t counter()
{
    return count;
}

void thread_callback(void const*)
{
     bool pressed = false;
     
    while (true) {
        if ((!pressed) && (button))
            count++;
        pressed = button;
    }
}