Geo beacon for VF.
Dependencies: MMA8452 aconno_bsp adc52832_common
Revision 22:8d106fd5fa84, committed 2017-08-28
- Comitter:
- jurica238814
- Date:
- Mon Aug 28 19:58:11 2017 +0000
- Parent:
- 21:10c3b8176be0
- Child:
- 23:729717272b31
- Commit message:
- pwm->gpio buzzer. This version works stable. Problems: beeping is not loud enough. Scanner power is huge (>7mA).
Changed in this revision
| adc52832_common.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/adc52832_common.lib Mon Aug 28 19:58:11 2017 +0000 @@ -0,0 +1,1 @@ +https://developer.mbed.org/teams/aconno-dev-team/code/adc52832_common/#522ed4572c53
--- a/main.cpp Mon Aug 28 14:12:10 2017 +0000
+++ b/main.cpp Mon Aug 28 19:58:11 2017 +0000
@@ -13,6 +13,7 @@
#include "mma8452.h"
#include "AckService.h"
#include "nrf52_uart.h"
+#include "nrf52_digital.h"
#define DEBUG (0)
#define DEBUG_ACC (0)
@@ -21,9 +22,9 @@
#define DEBUG_CONNECTION (0)
#define USE_ACC (0)
-#define SLEEP_TIME_S (5.0) /* Sleep time (in s) */
-#define ADV_TIMER_TIME_S (5.0) /* Advertising time (in s) */
-#define SCAN_TIMER_TIME_S (5.0) /* Scanning time (in s) */
+#define SLEEP_TIME_S (9.0) /* Sleep time (in s) */
+#define ADV_TIMER_TIME_S (0.5) /* Advertising time (in s) */
+#define SCAN_TIMER_TIME_S (0.5) /* Scanning time (in s) */
#define FREE_TIME_S (0.1) /* Time between end of a scanning and sleep mode */
#define AWAKE_TIME_S (ADV_TIMER_TIME_S+SCAN_TIMER_TIME_S+FREE_TIME_S) /* Was 0.15 */
#define SHORT_SLEEP_TIME_S (0.5) /* Shorter sleep time (s) */
@@ -84,7 +85,6 @@
Ticker WakeSleepT;
Ticker turnBuzzOffT;
Ticker sleepChanger;
-//PwmOut buzzer(BUZZER);
NRF52_DigitalOut buzzer(BUZZER);
#if USE_ACC
DigitalOut accPower(p7);
@@ -95,7 +95,7 @@
BLE &ble = BLE::Instance();
ACKService<4> *ackServicePtr;
-#if DEBUG || DEBUG_MAC
+#if DEBUG || DEBUG_MAC || DEBUG_CONNECTION
DigitalOut advLED(p22); // Red
DigitalOut scanLED(p23); // Blue
DigitalOut connectedLED(p24); // Green
@@ -105,6 +105,16 @@
DigitalOut int_led(p22);
#endif
+void buzz(uint16_t period_us, uint32_t duration_ms){
+ int32_t counter;
+ for(counter=0; counter<((duration_ms*1000)/(period_us*1.0)); counter++){
+ buzzer.toggle();
+ wait_us(period_us/2);
+ buzzer.toggle();
+ wait_us(period_us/2);
+ }
+ buzzer = 0;
+}
void onConnectionCallback(const Gap::ConnectionCallbackParams_t *params){
#if DEBUG_CONNECTION
@@ -166,11 +176,9 @@
connectedLED = 1;
wait_ms(100);
#endif
- //buzzer.period(0.0009F);
- //buzzer.write(0.5F);
+ buzz(900,1000);
WakeSleepT.detach();
- turnBuzzOffT.detach();
- turnBuzzOffT.attach(TurnBuzzOff, BUZZ_TIME_S);
+ WakeSleepT.attach(WakeMeUp, FREE_TIME_S);
/*
This function should make advertiser stop
*/
@@ -304,11 +312,9 @@
if ((params->advertisingData[msdOffset+2]) == 0x00){
if(CheckMac(params, myMacAddress, msdOffset)){
//ble.gap().stopScan();
- //buzzer.period(0.0009F);
- //buzzer.write(0.5F);
+ buzz(900,1000);
WakeSleepT.detach();
- turnBuzzOffT.detach();
- turnBuzzOffT.attach(TurnBuzzOff, BUZZ_TIME_S);
+ WakeSleepT.attach(WakeMeUp, FREE_TIME_S);
}
}
}

