Lizzy project
Dependencies: aconno_I2C Lis2dh12 adc52832_common aconno_SEGGER_RTT
Diff: tasks/tasks.cpp
- Branch:
- testing-ignore
- Revision:
- 24:7539258b015c
- Parent:
- 23:bf9c1dd2b5cb
- Child:
- 26:6101bb09f70d
--- a/tasks/tasks.cpp Mon Sep 17 12:46:41 2018 +0000 +++ b/tasks/tasks.cpp Thu Sep 20 07:34:35 2018 +0000 @@ -1,4 +1,5 @@ #include "main.h" +#include "bsp.h" #include "bsp_buzz.h" #include "bsp_led.h" #include "aconno_ble.h" @@ -12,6 +13,9 @@ DigitalOut blueLed(BLUE_LED_PIN); #endif +extern Lis2dh12 mems; +extern InterruptIn INT1; + Buzz buzzer(NRF_PWM2, BUZZER_PIN); static advertising_packet advertisementPacket; @@ -22,6 +26,19 @@ Ticker test_ticker; #endif +LowPowerTicker longDelaysT; + + +inline void startLongDelay(uint32_t delay) +{ + longDelaysT.attach(longDelaysC, delay); +} + +inline void stopLongDelay() +{ + longDelaysT.detach(); +} + void tasks_init() { @@ -86,14 +103,19 @@ } #endif -int untilSleep = ACTIVE_PERIOD / MEASURE_INTERVAL_MS; void measureF(Lis2dh12 *mems) { + int untilSleep; + while(1) { Thread::signal_wait(START_MEAS); Thread::signal_clr(START_MEAS); + INT1.disable_irq(); + + untilSleep = ACTIVE_PERIOD_MS / MEASURE_INTERVAL_MS; + BLE::Instance().startAdvertising(); while (1) @@ -123,12 +145,12 @@ bleT.signal_set(MEAS_DONE); wait_ms(MEASURE_INTERVAL_MS); - //Thread::wait(MEASURE_INTERVAL_MS); untilSleep--; if( (untilSleep <= 0) && !bleIsClientConnected() ) { BLE::Instance().stopAdvertising(); + startLongDelay(LONG_SLEEP_S); break; } } @@ -236,4 +258,13 @@ getBLEEventQueue()->dispatch_forever(); Thread::wait(0xFFFFFFFF); } +} + +void longDelaysC(void) +{ + mems.clearIntFlag(); + + INT1.enable_irq(); + + stopLongDelay(); } \ No newline at end of file