Geo beacon for VF.
Dependencies: MMA8452 aconno_bsp adc52832_common
Diff: main.cpp
- Revision:
- 8:570eb66d50b5
- Parent:
- 6:d14e3df498f4
- Child:
- 9:2ab2be19add9
--- a/main.cpp Wed Jul 19 12:07:23 2017 +0000 +++ b/main.cpp Thu Jul 20 11:15:37 2017 +0000 @@ -12,8 +12,10 @@ #include "acd52832_bsp.h" #include "mma8452.h" +#define DEBUG 1 + #define SLEEP_TIME (0.85) // Sleep time in seconds WAS 0.85 -#define AWAKE_TIME (0.15) // Was 0.15 +#define AWAKE_TIME (2.15) // Was 0.15 #define BUZZER (p31) /* Static constants for the BLE example */ @@ -29,8 +31,7 @@ #define I2C_CLK (p2) #define INT2_PIN (p4) - -//uint8_t SLEEP = true; +uint8_t sleepFlag = 1; int8_t txPower = 4; uint8_t MSD[MSD_SIZE] = {0x59, 0x00, 0xE1, 0x61, 0x35, 0xBA, 0xC0, 0xEC, 0x47, 0x2A, 0x98, 0x00, 0xAF, 0x18, 0x43, 0xFF, 0x05, 0x00}; uint8_t my_mac_address[6] = {}; @@ -48,6 +49,10 @@ Acc_MMA8452 acc(I2C_DATA, I2C_CLK, MMA8452_ADDRESS); BLE &ble = BLE::Instance(); +#if DEBUG + DigitalOut int_led(p22); +#endif + /* Restart Advertising on disconnection*/ void disconnectionCallback(const Gap::DisconnectionCallbackParams_t *params){ BLE::Instance().gap().startAdvertising(); @@ -160,7 +165,7 @@ ble.gap().startScan(advertisementCallback); ble.gap().startAdvertising(); - SLEEP = false; + sleepFlag = 0; } void goToSleep(){ @@ -169,7 +174,7 @@ ble.gap().stopAdvertising(); ble.gap().stopScan(); - SLEEP = true; + sleepFlag = 1; } void buzz(void){ @@ -185,6 +190,9 @@ #endif i2c_power.write(1.0F); buzzer_flag = 1; + // Be awake some time + WakeSleepT.detach(); + WakeSleepT.attach(goToSleep, AWAKE_TIME); } int main(void){ @@ -230,8 +238,7 @@ } while(true){ - if(SLEEP) __WFI(); - else if(buzzer_flag) buzz(); + if(sleepFlag) __WFI(); else ble.waitForEvent(); } }