Geo beacon for VF.
Dependencies: MMA8452 aconno_bsp adc52832_common
Revision 20:d534b9c18482, committed 2017-08-28
- Comitter:
- jurica238814
- Date:
- Mon Aug 28 07:06:20 2017 +0000
- Parent:
- 19:abf14a5ada93
- Commit message:
- Power consumption is still a problem... (not sure if the version works...).
Changed in this revision
--- a/aconno_nrf52_uart.lib Tue Aug 22 07:35:03 2017 +0000 +++ b/aconno_nrf52_uart.lib Mon Aug 28 07:06:20 2017 +0000 @@ -1,1 +1,1 @@ -https://developer.mbed.org/users/Dautor/code/aconno_nrf52_uart/#ebebc790336a +https://developer.mbed.org/users/Dautor/code/aconno_nrf52_uart/#0014952b2b75
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/adc52832_common.lib Mon Aug 28 07:06:20 2017 +0000 @@ -0,0 +1,1 @@ +http://developer.mbed.org/teams/aconno-dev-team/code/adc52832_common/#522ed4572c53
--- a/main.cpp Tue Aug 22 07:35:03 2017 +0000
+++ b/main.cpp Mon Aug 28 07:06:20 2017 +0000
@@ -16,14 +16,14 @@
#define DEBUG (0)
#define DEBUG_ACC (0)
-#define PRINT (0)
+#define PRINT (1)
#define DEBUG_MAC (0)
#define DEBUG_CONNECTION (0)
#define USE_ACC (0)
-#define SLEEP_TIME_S (3.0) /* Sleep time (in s) */
-#define ADV_TIMER_TIME_S (3.0) /* Advertising time (in s) */
-#define SCAN_TIMER_TIME_S (1.0) /* Scanning time (in s) */
+#define SLEEP_TIME_S (5.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) */
@@ -50,10 +50,12 @@
#if PRINT
/* Defines for debugging over uart */
- #define TX (p25)
- #define RX (p26)
- NRF52_UART uart(TX,RX, Baud9600);
- char printBuffer[30] = {};
+ #define TX (p29)
+ #define RX (p30)
+ NRF52_UART serial(TX,RX, Baud9600);
+ char buffer[255] = {0};
+ uint8_t buffer_s;
+ int printBufferLen;
#endif
@@ -61,7 +63,7 @@
bool shushShush = false;
const static uint16_t ACK_CHARA_UUID = 0xA001;
-uint8_t txPower = 4;
+int8_t txPower = 4;
uint8_t sleepFlag = false;
uint8_t tempSleepTime = SLEEP_TIME_S;
uint8_t msd[MSD_SIZE] = {0x59, 0x00, 0xE1, 0x61, 0x35, 0xBA, 0xC0, 0xEC, 0x47, 0x2A, 0x98, 0x00, 0xAF, 0x18, 0x43, 0xFF, 0x05, 0x00};
@@ -76,21 +78,21 @@
enum RadioState radioState = OFF;
void TurnBuzzOff(void);
-void GoToSleep();
+void goToSleep();
void StartAdvertising();
void startScanning();
void WakeMeUp();
Ticker WakeSleepT;
-Ticker turnBuzzOffT;
-Ticker sleepChanger;
-PwmOut buzzer(BUZZER);
+//Ticker turnBuzzOffT;
+//Ticker sleepChanger;
+//PwmOut buzzer(BUZZER);
+//DigitalOut accPower(p7);
+//DigitalOut i2cPower(p5);
#if USE_ACC
- DigitalOut accPower(p7);
- DigitalOut i2cPower(p5);
InterruptIn accPulse(INT2_PIN);
+ Acc_MMA8452 acc(I2C_DATA, I2C_CLK, MMA8452_ADDRESS);
#endif
-Acc_MMA8452 acc(I2C_DATA, I2C_CLK, MMA8452_ADDRESS);
BLE &ble = BLE::Instance();
ACKService<4> *ackServicePtr;
@@ -104,7 +106,6 @@
DigitalOut int_led(p22);
#endif
-
void onConnectionCallback(const Gap::ConnectionCallbackParams_t *params){
#if DEBUG_CONNECTION
@@ -166,11 +167,11 @@
connectedLED = 1;
wait_ms(100);
#endif
- buzzer.period(0.0009F);
- buzzer.write(0.5F);
+ //buzzer.period(0.0009F);
+ //buzzer.write(0.5F);
WakeSleepT.detach();
- turnBuzzOffT.detach();
- turnBuzzOffT.attach(TurnBuzzOff, BUZZ_TIME_S);
+ //turnBuzzOffT.detach();
+ //turnBuzzOffT.attach(TurnBuzzOff, BUZZ_TIME_S);
/*
This function should make advertiser stop
*/
@@ -227,7 +228,6 @@
ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::MANUFACTURER_SPECIFIC_DATA, (uint8_t *)msd, MSD_SIZE);
ble.gap().setAdvertisingInterval(ADV_INTERVAL); // --> Has to be at least 100ms!
//ble.gap().startAdvertising();
-
}
@@ -306,12 +306,12 @@
if ((params->advertisingData[msdOffset+1]) == 0x59){
if ((params->advertisingData[msdOffset+2]) == 0x00){
if(CheckMac(params, myMacAddress, msdOffset)){
- //ble.gap().stopScan();
- buzzer.period(0.0009F);
- buzzer.write(0.5F);
+ ble.gap().stopScan();
+ //buzzer.period(0.0009F);
+ //buzzer.write(0.5F);
WakeSleepT.detach();
- turnBuzzOffT.detach();
- turnBuzzOffT.attach(TurnBuzzOff, BUZZ_TIME_S);
+ //turnBuzzOffT.detach();
+ //turnBuzzOffT.attach(TurnBuzzOff, BUZZ_TIME_S);
}
}
}
@@ -322,7 +322,7 @@
/* Call this function few minutes (TBD) after a last scanned advertisment */
void changeSleepTime(){
tempSleepTime = SLEEP_TIME_S;
- sleepChanger.detach();
+ //sleepChanger.detach();
}
@@ -330,20 +330,16 @@
* The function is called when ticker generates interrupt
*/
void TurnBuzzOff(void){
- buzzer.period(0.00F);
- buzzer.write(0.0F);
- NRF_PWM0->TASKS_STOP = 1;
- NRF_PWM1->TASKS_STOP = 1;
- NRF_PWM2->TASKS_STOP = 1;
+ //buzzer.period(0.00F);
+ //buzzer.write(0.0F);
tempSleepTime = SHORT_SLEEP_TIME_S;
- turnBuzzOffT.detach();
+ //turnBuzzOffT.detach();
WakeSleepT.detach();
- sleepChanger.attach(changeSleepTime, SHORT_SLEEP_TIME_PERIOD_S);
+ //sleepChanger.attach(changeSleepTime, SHORT_SLEEP_TIME_PERIOD_S);
WakeSleepT.attach(WakeMeUp, FREE_TIME_S);
}
void startAdvertising(){
- NRF_PWM0->TASKS_SEQSTART[0] = 1;
#if USE_ACC
i2cPower = 1;
#endif
@@ -357,11 +353,8 @@
}
else{
ble.gap().startAdvertising();
- buzzer.period(0.00F);
- buzzer.write(0.0F);
- NRF_PWM0->TASKS_STOP = 1;
- NRF_PWM1->TASKS_STOP = 1;
- NRF_PWM2->TASKS_STOP = 1;
+ //buzzer.period(0.00F);
+ //buzzer.write(0.0F);
#if DEBUG
advLED = 0;
scanLED = 1;
@@ -376,11 +369,8 @@
ble.gap().setScanParams(SCAN_INTERVAL, SCAN_WINDOW);
ble.gap().setScanTimeout(SCAN_TIMER_TIME_S);
ble.gap().startScan(advertisementCallback);
- buzzer.period(0.00F);
- buzzer.write(0.0F);
- NRF_PWM0->TASKS_STOP = 1;
- NRF_PWM1->TASKS_STOP = 1;
- NRF_PWM2->TASKS_STOP = 1;
+ //buzzer.period(0.00F);
+ //buzzer.write(0.0F);
#if DEBUG
advLED = 1;
scanLED = 0;
@@ -405,22 +395,21 @@
case SCANNING:{
radioState = OFF;
WakeSleepT.detach();
- //WakeSleepT.attach(GoToSleep, FREE_TIME_S);
- GoToSleep();
+ WakeSleepT.attach(goToSleep, FREE_TIME_S);
+ goToSleep();
break;
}
default: return;
}
}
-void GoToSleep(){
- buzzer.period(0.00F);
- buzzer.write(0.0f);
- NRF_PWM0->TASKS_STOP = 1;
- NRF_PWM1->TASKS_STOP = 1;
- NRF_PWM2->TASKS_STOP = 1;
+void goToSleep(){
+ //buzzer.period(0.00F);
+ //buzzer.write(0.0f);
+ printBufferLen = sprintf(buffer, "In goToSleep...\r\n");
+ serial.send(buffer, printBufferLen);
WakeSleepT.detach();
- WakeSleepT.attach(WakeMeUp, tempSleepTime);
+ WakeSleepT.attach(goToSleep, tempSleepTime);
ble.gap().stopAdvertising();
ble.gap().stopScan();
sleepFlag = 1;
@@ -435,37 +424,31 @@
#if DEBUG_ACC
int_led = !int_led;
#endif
- buzzer.period(0.0009F);
- buzzer.write(0.5f);
+ //buzzer.period(0.0009F);
+ //buzzer.write(0.5f);
}
#endif
-int main(void){
+int main(void){
#if DEBUG || DEBUG_MAC
advLED = 1;
scanLED = 1;
connectedLED = 1;
#endif
- buzzer.period(0.0009F);
- buzzer.write(0.0F);
+ //buzzer.period(0.0009F);
+ //buzzer.write(0.0F);
+
+ #if !USE_ACC
+ //accPower = 0;
+ //i2cPower = 0;
+ #endif
+
#if USE_ACC
accPower = 1;
i2cPower = 1;
#endif
- #if PRINT
- int i;
- for(i=0; i<10; i++){
- printBuffer[0] = 'B';
- printBuffer[1] = 'o';
- printBuffer[2] = 'k';
- uart.send(printBuffer, 3);
- wait_ms(100);
- }
- #endif
-
- WakeSleepT.attach(GoToSleep, AWAKE_TIME_S);
ble.init(bleInitComplete);
ble.gap().setTxPower(txPower);
GapAdvertisingData postavke = GapAdvertisingData();
@@ -489,39 +472,37 @@
wait(1);
#endif
- __enable_irq();
-
/* SpinWait for initialization to complete. This is necessary because the BLE object is used in the main loop below. */
while (ble.hasInitialized() == false){
- /* spin loop */
+ // spin loop
}
-
+
+ __enable_irq();
+ buffer_s = 0x0C;
+ serial.send(&buffer_s, sizeof(buffer_s));
+
+ printBufferLen = sprintf(buffer, "Going to sleep first time...\r\n");
+ serial.send(buffer, printBufferLen);
+ goToSleep();
+
+ //buzzer.period(0.0F);
+ //buzzer.write(0.0F);
+
while(true){
- if(sleepFlag){
- NRF_GPIO->PIN_CNF[31] = 0x00000003;
- NRF_PWM0->TASKS_STOP = 1;
- NRF_PWM1->TASKS_STOP = 1;
- NRF_PWM2->TASKS_STOP = 1;
- NRF_PPI->TASKS_CHG[0].DIS = 1;
- NRF_PPI->TASKS_CHG[1].DIS = 1;
- NRF_PPI->TASKS_CHG[2].DIS = 1;
- NRF_PPI->TASKS_CHG[3].DIS = 1;
- NRF_PPI->TASKS_CHG[4].DIS = 1;
- NRF_GPIOTE->TASKS_CLR[0] = 1;
- NRF_GPIOTE->TASKS_CLR[1] = 1;
- NRF_GPIOTE->TASKS_CLR[2] = 1;
- NRF_GPIOTE->TASKS_CLR[3] = 1;
- NRF_GPIOTE->TASKS_CLR[4] = 1;
- NRF_GPIOTE->TASKS_CLR[5] = 1;
- NRF_GPIOTE->TASKS_CLR[6] = 1;
- NRF_GPIOTE->TASKS_CLR[7] = 1;
+ if(0){
+ //buzzer.period(0.0F);
+ //buzzer.write(0.0F);
#if USE_ACC
i2cPower = 0;
#endif
+ ble.waitForEvent();
__WFI();
}
else{
+ printBufferLen = sprintf(buffer, "Second else...\r\n");
+ serial.send(buffer, printBufferLen);
ble.waitForEvent();
+ __WFI();
}
}
}

