Geo beacon for VF.
Dependencies: MMA8452 aconno_bsp adc52832_common
Diff: main.cpp
- Revision:
- 12:6b072c2a061c
- Parent:
- 11:92a9fffd5015
- Parent:
- 7:89c9abaa257e
- Child:
- 13:d51127eed926
--- a/main.cpp Tue Jul 25 11:29:01 2017 +0000 +++ b/main.cpp Tue Jul 25 12:19:39 2017 +0000 @@ -2,7 +2,7 @@ * * Made by Jurica Resetar @ aconno * aconno.de - * All rights reserved + * All rights reserved. * */ @@ -20,16 +20,21 @@ #define SCAN_TIMER_TIME (0.5) // Scanning time (in s) #define FREE_TIME (0.01) // Time between end of a scanning and sleep mode #define AWAKE_TIME (ADV_TIMER_TIME+SCAN_TIMER_TIME+FREE_TIME) // Was 0.15 +#define SHORT_SLEEP_TIME (0.5) // Shorter sleep time (s) +#define SHORT_SLEEP_TIME_PERIOD (60) // Time after a last scanned advertisment. In the period, sleep time is SHORT_SLEEP_TIME + /* Static constants for the BLE example */ #define MAX_BLE_PACKET_SIZE (31) #define MSD_SIZE (18) #define MSD_ID (0xFF) + #define BUZZ_TIME (1.0) // Buzz time in s #define ADV_INTERVAL (100) // Advertising interval (in ms) #define SCAN_INTERVAL (100) // Scan interval (in ms) #define SCAN_WINDOW (50) + /* Static constants for the accelerometer */ #define WHO_AM_I 0x0D // Type 'read' : This should return the device id of 0x2A #define OUT_Z_MSB 0x05 // Type 'read' : z axis - 8 most significatn bit of a 12 bit sample @@ -39,6 +44,7 @@ #define BUZZER (p31) uint8_t sleepFlag = 0; +uint8_t tempSleepTime = SLEEP_TIME; 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] = {}; @@ -59,6 +65,7 @@ Ticker WakeSleepT; Ticker turnBuzzOffT; +Ticker sleepChanger; PwmOut buzzer(BUZZER); PwmOut gyro_power(p7); PwmOut i2c_power(p5); // I2C Pull-ups power pin @@ -81,6 +88,7 @@ //BLE::Instance().gap().startAdvertising(); } + /** * This function is called when the ble initialization process has failed */ @@ -175,14 +183,24 @@ } } + +/* Call this function few minutes (TBD) after a last scanned advertisment */ +void changeSleepTime(){ + tempSleepTime = SLEEP_TIME; + sleepChanger.detach(); +} + + /** * The function is called when ticker generates interrupt */ void turnBuzzOff(void){ buzzer.write(0.0F); + tempSleepTime = SHORT_SLEEP_TIME; turnBuzzOffT.detach(); ble.gap().startScan(advertisementCallback); WakeSleepT.attach(goToSleep, AWAKE_TIME); + sleepChanger.attach(changeSleepTime, SHORT_SLEEP_TIME_PERIOD); } void startAdvertising(){ @@ -239,7 +257,7 @@ void goToSleep(){ WakeSleepT.detach(); - WakeSleepT.attach(WakeMeUp, SLEEP_TIME); + WakeSleepT.attach(WakeMeUp, tempSleepTime); ble.gap().stopAdvertising(); ble.gap().stopScan(); sleepFlag = 1; @@ -278,7 +296,7 @@ //ble.gap().setScanTimeout(0.5); //ble.gap().startScan(advertisementCallback); - buzzer.period(0.001F); + buzzer.period(0.0009F); buzzer.write(0.0F); gyro_power.period(0.01F); gyro_power.write(1.0F);