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
Diff: io.cpp
- Revision:
- 12:beb64aa0da86
- Child:
- 14:56da550a1baa
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/io.cpp Fri Feb 14 12:28:41 2014 +0000 @@ -0,0 +1,68 @@ +#include "io.h" +#include "rtos.h" + +#define S_INIT 0 +#define S_OPEN 1 +#define S_GONE 2 + +void thread_callback(void const*); + +// adjust pin numbers +LM75B tempSensor(p28, p27); +MMA7660 accSensor(p28, p27); +DigitalIn button(p14); + +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; + } +}