Lizzy project
Dependencies: aconno_I2C Lis2dh12 adc52832_common aconno_SEGGER_RTT
Diff: tasks/tasks.cpp
- Branch:
- axis_normal
- Revision:
- 15:c0c01188a29b
- Parent:
- 13:2e964fa2a632
- Child:
- 16:482d8f81d6f3
--- a/tasks/tasks.cpp Wed Aug 29 10:52:27 2018 +0000 +++ b/tasks/tasks.cpp Wed Aug 29 14:48:43 2018 +0000 @@ -86,30 +86,51 @@ } #endif +int untilSleep = ACTIVE_PERIOD / MEASURE_INTERVAL_MS; void measureF(Lis2dh12 *mems) { - while (1) + while(1) { - advertisementPacket.header = APPLICATION_ID; - advertisementPacket.type = 0x00; - advertisementPacket.gyroscope[0] = (int16_t)0; - advertisementPacket.gyroscope[1] = (int16_t)0; - advertisementPacket.gyroscope[2] = (int16_t)0; - advertisementPacket.magnetometer[0] = (int16_t)0; - advertisementPacket.magnetometer[1] = (int16_t)0; - advertisementPacket.magnetometer[2] = (int16_t)0; + Thread::signal_wait(START_MEAS); + Thread::signal_clr(START_MEAS); + + BLE::Instance().startAdvertising(); - - advertisementPacket.accelerometer[0] = (int16_t)mems->readXAxis(); - advertisementPacket.accelerometer[1] = (int16_t)mems->readYAxis(); - advertisementPacket.accelerometer[2] = (int16_t)mems->readZAxis(); - - advertisementPacket.acc_lsb_value = LSB_VALUE; - - updateServiceT.signal_set(MEAS_DONE); - bleT.signal_set(MEAS_DONE); - - wait_ms(MEASURE_INTERVAL_MS); + while (1) + { + advertisementPacket.header = APPLICATION_ID; + advertisementPacket.type = 0x00; + advertisementPacket.gyroscope[0] = (int16_t)0; + advertisementPacket.gyroscope[1] = (int16_t)0; + advertisementPacket.gyroscope[2] = (int16_t)0; + advertisementPacket.magnetometer[0] = (int16_t)0; + advertisementPacket.magnetometer[1] = (int16_t)0; + advertisementPacket.magnetometer[2] = (int16_t)0; + +#if NORMAL_AXIS == 1 + advertisementPacket.accelerometer[0] = (int16_t)mems->readXAxis(); + advertisementPacket.accelerometer[1] = (int16_t)mems->readYAxis(); + advertisementPacket.accelerometer[2] = (int16_t)mems->readZAxis(); +#else + advertisementPacket.accelerometer[0] = -(int16_t)mems->readYAxis(); + advertisementPacket.accelerometer[1] = (int16_t)mems->readXAxis(); + advertisementPacket.accelerometer[2] = (int16_t)mems->readZAxis(); +#endif + + advertisementPacket.acc_lsb_value = LSB_VALUE; + + updateServiceT.signal_set(MEAS_DONE); + bleT.signal_set(MEAS_DONE); + + wait_ms(MEASURE_INTERVAL_MS); + untilSleep--; + + if(untilSleep <= 0) + { + BLE::Instance().stopAdvertising(); + break; + } + } } }