![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
SEDO subject project
Dependencies: ds3231 mbed-rtos mbed DHT
Diff: light_sensor.cpp
- Revision:
- 12:1d544cdab2cf
diff -r a9f41d6489c9 -r 1d544cdab2cf light_sensor.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/light_sensor.cpp Mon May 15 18:30:20 2017 +0000 @@ -0,0 +1,48 @@ +/* + * Light sensor operations + */ +#include "mbed.h" +#include "rtos.h" +#include "main.h" +#include "light_sensor.h" + +AnalogIn LDR(A5); + +uint32_t light_init(void const *args) +{ + return 1; +} +void light_thread(void const *args) +{ +//DEBUG + mutexPCComm.lock(); + pc.printf("LDR: thread init\n"); + mutexPCComm.unlock(); + float lightCurr; + int8_t error = 0; + int8_t attempts=0; + while(true) { + Thread::signal_wait(0x1); + mutexPCComm.lock(); + pc.printf("LDR: loop\n"); + mutexPCComm.unlock(); + error = -1; + attempts=0; + while(error!=0 && attempts<MAX_READ_ATTEMPTS_LIGHT && sensors_running == true) { + lightCurr=LDR.read(); + error = 0; + if(error==0) { + mutexData.lock(); + data.light = lightCurr; + data.lightError = 0; + mutexData.unlock(); + } else { + mutexData.lock(); + data.lightError = 0; + mutexData.unlock(); + attempts++; + Thread::wait(3000); + } + } // while read attempts + } // main thread while +} // thread function