An application to log WiFi SSIDs for position lookup testing
Dependencies: C027_Support SWO mbed-rtos mbed picojson
Fork of lpc4088_ebb_ublox_Cellular_PubNubDemo_rtos by
Diff: device/DeviceFeedback.cpp
- Revision:
- 1:cac9b2960637
diff -r 713518ea5028 -r cac9b2960637 device/DeviceFeedback.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/device/DeviceFeedback.cpp Sun Feb 15 22:04:12 2015 +0000 @@ -0,0 +1,71 @@ +#include "DeviceFeedback.h" +#include <stdlib.h> +#include <string.h> + +#define MSG_SHOW_SUCCESS 1 +#define MSG_SHOW_FAILURE 2 + +DeviceFeedback::DeviceFeedback(PwmOut led) : + _led(led), + _thread(DeviceFeedback::thread_func, this) +{ +} + +void DeviceFeedback::showSuccess() +{ + sendMessage(MSG_SHOW_SUCCESS); +} + +void DeviceFeedback::showFailure() +{ + sendMessage(MSG_SHOW_FAILURE); +} + +void DeviceFeedback::sendMessage(uint8_t msg) +{ + uint8_t *msgPtr; + + msgPtr = _mail.alloc(); + *msgPtr = msg; + _mail.put(msgPtr); +} + +void DeviceFeedback::thread() +{ + osEvent evt; + uint8_t *msg; + + while (true) { + if ((evt = _mail.get(1000)).status == osEventMail) { + msg = (uint8_t*)evt.value.p; + switch (*msg) { + case MSG_SHOW_SUCCESS: + for (float i=2000.0; i<10000.0; i+=2000.0) { + _led.period(1.0/i); + _led = 0.5; + Thread::wait(200); + _led = 0.0; + Thread::wait(50); + } + break; + case MSG_SHOW_FAILURE: + for (float i=10000.0; i>2000.0; i-=2000.0) { + _led.period(1.0/i); + _led = 0.5; + Thread::wait(200); + _led = 0.0; + Thread::wait(50); + } + break; + } + _mail.free(msg); + } + } +} + +void DeviceFeedback::thread_func(void const *arg) +{ + DeviceFeedback *that; + that = (DeviceFeedback*)arg; + that->thread(); +}