Geo beacon for VF.
Dependencies: MMA8452 aconno_bsp adc52832_common
Revision 7:89c9abaa257e, committed 2017-07-19
- Comitter:
- jurica238814
- Date:
- Wed Jul 19 12:48:14 2017 +0000
- Parent:
- 4:331dddea780e
- Child:
- 12:6b072c2a061c
- Commit message:
- Short sleep time mechanism added.
Changed in this revision
| MMA8452.lib | Show annotated file Show diff for this revision Revisions of this file |
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/MMA8452.lib Wed Jul 19 12:48:14 2017 +0000 @@ -0,0 +1,1 @@ +https://developer.mbed.org/users/jurica238814/code/MMA8452/#bda670d7a481
--- a/main.cpp Wed Jul 19 11:17:48 2017 +0000
+++ b/main.cpp Wed Jul 19 12:48:14 2017 +0000
@@ -11,18 +11,21 @@
#include "GapAdvertisingData.h"
#include "acd52832_bsp.h"
-#define SLEEP_TIME (0.85) // Sleep time in seconds WAS 0.85
-#define AWAKE_TIME (0.15) // Was 0.15
-#define BUZZER (p31)
+#define SLEEP_TIME (5.0) // Sleep time in seconds
+#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
+#define AWAKE_TIME (0.25) // Was 0.15 -> Was not enough
+#define BUZZER (p31)
/* 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 BUZZ_TIME (2.0) // Buzz time in s
bool SLEEP = true;
+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] = {};
@@ -32,6 +35,7 @@
Ticker WakeSleepT;
Ticker turnBuzzOffT;
+Ticker sleepChanger;
PwmOut buzzer(BUZZER);
BLE &ble = BLE::Instance();
@@ -40,14 +44,6 @@
BLE::Instance().gap().startAdvertising();
}
-/**
- * The function is called when ticker generates interrupt
- */
-void turnBuzzOff(void){
- buzzer.write(0.0F);
- turnBuzzOffT.detach();
- WakeSleepT.attach(goToSleep, AWAKE_TIME);
-}
/**
* This function is called when the ble initialization process has failed
@@ -141,6 +137,23 @@
}
}
+/* 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();
+ WakeSleepT.attach(goToSleep, AWAKE_TIME);
+ sleepChanger.attach(changeSleepTime, SHORT_SLEEP_TIME_PERIOD);
+}
+
void WakeMeUp(){
WakeSleepT.detach();
WakeSleepT.attach(goToSleep, AWAKE_TIME);
@@ -152,7 +165,7 @@
void goToSleep(){
WakeSleepT.detach();
- WakeSleepT.attach(WakeMeUp, SLEEP_TIME);
+ WakeSleepT.attach(WakeMeUp, tempSleepTime);
ble.gap().stopAdvertising();
ble.gap().stopScan();
@@ -168,7 +181,7 @@
ble.gap().setScanParams(100, 100);
ble.gap().startScan(advertisementCallback);
- buzzer.period(0.001F);
+ buzzer.period(0.0009F);
buzzer.write(0.0F);
__enable_irq();

