Geo beacon for VF.
Dependencies: MMA8452 aconno_bsp adc52832_common
Diff: main.cpp
- Revision:
- 9:2ab2be19add9
- Parent:
- 8:570eb66d50b5
- Child:
- 10:fd91664032d8
--- a/main.cpp Thu Jul 20 11:15:37 2017 +0000 +++ b/main.cpp Thu Jul 20 13:44:49 2017 +0000 @@ -14,8 +14,8 @@ #define DEBUG 1 -#define SLEEP_TIME (0.85) // Sleep time in seconds WAS 0.85 -#define AWAKE_TIME (2.15) // Was 0.15 +#define SLEEP_TIME (2.0) // Sleep time in seconds WAS 0.85 +#define AWAKE_TIME (2.0) // Was 0.15 #define BUZZER (p31) /* Static constants for the BLE example */ @@ -51,6 +51,7 @@ #if DEBUG DigitalOut int_led(p22); + DigitalOut awake(p24); #endif /* Restart Advertising on disconnection*/ @@ -147,7 +148,7 @@ continue; } else{ - return; + //return; } } turnBuzzOffT.detach(); @@ -181,7 +182,7 @@ buzzer.write(0.5f); wait_ms(100); buzzer.write(0.0f); - buzzer_flag = 0; + sleepFlag = 0; } void pulse_handler(void){ @@ -191,8 +192,8 @@ i2c_power.write(1.0F); buzzer_flag = 1; // Be awake some time - WakeSleepT.detach(); - WakeSleepT.attach(goToSleep, AWAKE_TIME); + //WakeSleepT.detach(); + //WakeSleepT.attach(goToSleep, AWAKE_TIME); } int main(void){ @@ -225,7 +226,7 @@ wait_ms(1); /* Setup for the interrupt handler */ - gyro_pulse.rise(&pulse_handler); + //gyro_pulse.rise(&pulse_handler); // ------------------------------------- acc.set_register((char)CTRL_REG_1, (char) 0x01); // Flow data rate and Active mode wait(1); @@ -237,8 +238,20 @@ /* spin loop */ } + while(1){ + ble.waitForEvent(); + awake != awake; + wait_ms(100); + } + while(true){ - if(sleepFlag) __WFI(); - else ble.waitForEvent(); + if(sleepFlag){ + if(!awake) awake = 1; + __WFI(); + } + else{ + if(awake) awake = 0; + ble.waitForEvent(); + } } }