Geo beacon for VF.

Dependencies:   MMA8452 aconno_bsp adc52832_common

Committer:
jurica238814
Date:
Tue Jul 25 09:22:32 2017 +0000
Revision:
10:fd91664032d8
Parent:
9:2ab2be19add9
Child:
11:92a9fffd5015
Scanner works exclusively with advertiser. ; Timing is bad (long periods) but seems to work stable with the app.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jurica238814 1:5f34885f5cff 1 /*
jurica238814 0:f8c1e0b2d473 2 *
jurica238814 1:5f34885f5cff 3 * Made by Jurica Resetar @ aconno
jurica238814 1:5f34885f5cff 4 * aconno.de
jurica238814 6:d14e3df498f4 5 * All rights reserved
jurica238814 0:f8c1e0b2d473 6 *
jurica238814 0:f8c1e0b2d473 7 */
jurica238814 0:f8c1e0b2d473 8
jurica238814 0:f8c1e0b2d473 9 #include "mbed.h"
jurica238814 0:f8c1e0b2d473 10 #include "ble/BLE.h"
jurica238814 1:5f34885f5cff 11 #include "GapAdvertisingData.h"
jurica238814 0:f8c1e0b2d473 12 #include "acd52832_bsp.h"
jurica238814 6:d14e3df498f4 13 #include "mma8452.h"
jurica238814 1:5f34885f5cff 14
jurica238814 10:fd91664032d8 15 #define DEBUG (1)
jurica238814 10:fd91664032d8 16 #define DEBUG_ACC (0)
jurica238814 8:570eb66d50b5 17
jurica238814 10:fd91664032d8 18 #define SLEEP_TIME (2.0) // Sleep time in seconds WAS 0.85
jurica238814 10:fd91664032d8 19 #define AWAKE_TIME (3.0) // Was 0.15
jurica238814 10:fd91664032d8 20 #define ADV_TIMER_TIME (1.0) // Advertising time (in s)
jurica238814 10:fd91664032d8 21 #define SCAN_TIMER_TIME (2.0) // Scanning time (in s)
jurica238814 10:fd91664032d8 22 #define FREE_TIME (0.01) // Time between end of a scanning and sleep mode
jurica238814 0:f8c1e0b2d473 23
jurica238814 1:5f34885f5cff 24 /* Static constants for the BLE example */
jurica238814 3:2a4ac5b87046 25 #define MAX_BLE_PACKET_SIZE (31)
jurica238814 3:2a4ac5b87046 26 #define MSD_SIZE (18)
jurica238814 3:2a4ac5b87046 27 #define MSD_ID (0xFF)
jurica238814 3:2a4ac5b87046 28 #define BUZZ_TIME (1.0) // Buzz time in s
jurica238814 10:fd91664032d8 29 #define ADV_INTERVAL (100) // Advertising interval (in ms)
jurica238814 10:fd91664032d8 30 #define SCAN_INTERVAL (100) // Scan interval (in ms)
jurica238814 10:fd91664032d8 31 #define SCAN_WINDOW (50)
jurica238814 1:5f34885f5cff 32
jurica238814 6:d14e3df498f4 33 /* Static constants for the accelerometer */
jurica238814 6:d14e3df498f4 34 #define WHO_AM_I 0x0D // Type 'read' : This should return the device id of 0x2A
jurica238814 6:d14e3df498f4 35 #define OUT_Z_MSB 0x05 // Type 'read' : z axis - 8 most significatn bit of a 12 bit sample
jurica238814 6:d14e3df498f4 36 #define I2C_DATA (p29)
jurica238814 6:d14e3df498f4 37 #define I2C_CLK (p2)
jurica238814 6:d14e3df498f4 38 #define INT2_PIN (p4)
jurica238814 10:fd91664032d8 39 #define BUZZER (p31)
jurica238814 0:f8c1e0b2d473 40
jurica238814 10:fd91664032d8 41 uint8_t sleepFlag = 0;
jurica238814 0:f8c1e0b2d473 42 int8_t txPower = 4;
jurica238814 1:5f34885f5cff 43 uint8_t MSD[MSD_SIZE] = {0x59, 0x00, 0xE1, 0x61, 0x35, 0xBA, 0xC0, 0xEC, 0x47, 0x2A, 0x98, 0x00, 0xAF, 0x18, 0x43, 0xFF, 0x05, 0x00};
jurica238814 6:d14e3df498f4 44 uint8_t my_mac_address[6] = {};
jurica238814 6:d14e3df498f4 45 uint8_t buzzer_flag = 0;
jurica238814 0:f8c1e0b2d473 46
jurica238814 10:fd91664032d8 47 enum _radioState{
jurica238814 10:fd91664032d8 48 OFF,
jurica238814 10:fd91664032d8 49 ADVERTISING,
jurica238814 10:fd91664032d8 50 SCANNING
jurica238814 10:fd91664032d8 51 };
jurica238814 10:fd91664032d8 52 enum _radioState radioState = OFF;
jurica238814 10:fd91664032d8 53
jurica238814 2:5504b714c9ae 54 void turnBuzzOff(void);
jurica238814 2:5504b714c9ae 55 void goToSleep();
jurica238814 10:fd91664032d8 56 void startAdvertising();
jurica238814 10:fd91664032d8 57 void startScanning();
jurica238814 10:fd91664032d8 58 void WakeMeUp();
jurica238814 0:f8c1e0b2d473 59
jurica238814 2:5504b714c9ae 60 Ticker WakeSleepT;
jurica238814 2:5504b714c9ae 61 Ticker turnBuzzOffT;
jurica238814 1:5f34885f5cff 62 PwmOut buzzer(BUZZER);
jurica238814 6:d14e3df498f4 63 PwmOut gyro_power(p7);
jurica238814 6:d14e3df498f4 64 PwmOut i2c_power(p5); // I2C Pull-ups power pin
jurica238814 6:d14e3df498f4 65 InterruptIn gyro_pulse(INT2_PIN);
jurica238814 6:d14e3df498f4 66 Acc_MMA8452 acc(I2C_DATA, I2C_CLK, MMA8452_ADDRESS);
jurica238814 1:5f34885f5cff 67 BLE &ble = BLE::Instance();
jurica238814 2:5504b714c9ae 68
jurica238814 10:fd91664032d8 69
jurica238814 8:570eb66d50b5 70 #if DEBUG
jurica238814 10:fd91664032d8 71 DigitalOut advLED(p22);
jurica238814 10:fd91664032d8 72 DigitalOut scanLED(p23);
jurica238814 10:fd91664032d8 73 DigitalOut awake(p24);
jurica238814 10:fd91664032d8 74 #endif
jurica238814 10:fd91664032d8 75 #if DEBUG_ACC
jurica238814 8:570eb66d50b5 76 DigitalOut int_led(p22);
jurica238814 8:570eb66d50b5 77 #endif
jurica238814 8:570eb66d50b5 78
jurica238814 0:f8c1e0b2d473 79 /* Restart Advertising on disconnection*/
jurica238814 0:f8c1e0b2d473 80 void disconnectionCallback(const Gap::DisconnectionCallbackParams_t *params){
jurica238814 10:fd91664032d8 81 //BLE::Instance().gap().startAdvertising();
jurica238814 1:5f34885f5cff 82 }
jurica238814 0:f8c1e0b2d473 83
jurica238814 0:f8c1e0b2d473 84 /**
jurica238814 0:f8c1e0b2d473 85 * This function is called when the ble initialization process has failed
jurica238814 0:f8c1e0b2d473 86 */
jurica238814 0:f8c1e0b2d473 87 void onBleInitError(BLE &ble, ble_error_t error){
jurica238814 0:f8c1e0b2d473 88 /* Avoid compiler warnings */
jurica238814 0:f8c1e0b2d473 89 (void) ble;
jurica238814 0:f8c1e0b2d473 90 (void) error;
jurica238814 0:f8c1e0b2d473 91 /* Initialization error handling should go here */
jurica238814 0:f8c1e0b2d473 92 }
jurica238814 0:f8c1e0b2d473 93
jurica238814 0:f8c1e0b2d473 94 /**
jurica238814 0:f8c1e0b2d473 95 * Callback triggered when the ble initialization process has finished
jurica238814 0:f8c1e0b2d473 96 */
jurica238814 0:f8c1e0b2d473 97 void bleInitComplete(BLE::InitializationCompleteCallbackContext *params){
jurica238814 0:f8c1e0b2d473 98 BLE& ble = params->ble;
jurica238814 0:f8c1e0b2d473 99 ble_error_t error = params->error;
jurica238814 0:f8c1e0b2d473 100
jurica238814 0:f8c1e0b2d473 101 if (error != BLE_ERROR_NONE) {
jurica238814 0:f8c1e0b2d473 102 /* In case of error, forward the error handling to onBleInitError */
jurica238814 0:f8c1e0b2d473 103 onBleInitError(ble, error);
jurica238814 0:f8c1e0b2d473 104 return;
jurica238814 0:f8c1e0b2d473 105 }
jurica238814 0:f8c1e0b2d473 106
jurica238814 0:f8c1e0b2d473 107 /* Ensure that it is the default instance of BLE */
jurica238814 0:f8c1e0b2d473 108 if(ble.getInstanceID() != BLE::DEFAULT_INSTANCE) {
jurica238814 0:f8c1e0b2d473 109 return;
jurica238814 0:f8c1e0b2d473 110 }
jurica238814 0:f8c1e0b2d473 111
jurica238814 0:f8c1e0b2d473 112 ble.gap().onDisconnection(disconnectionCallback);
jurica238814 0:f8c1e0b2d473 113
jurica238814 1:5f34885f5cff 114 /* Get my MAC address */
jurica238814 1:5f34885f5cff 115 BLEProtocol::AddressType_t temp_address_type;
jurica238814 1:5f34885f5cff 116 ble.gap().getAddress(&temp_address_type, my_mac_address);
jurica238814 1:5f34885f5cff 117
jurica238814 1:5f34885f5cff 118
jurica238814 0:f8c1e0b2d473 119 /* setup advertising */
jurica238814 10:fd91664032d8 120
jurica238814 0:f8c1e0b2d473 121 ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED);
jurica238814 1:5f34885f5cff 122 ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::MANUFACTURER_SPECIFIC_DATA, (uint8_t *)MSD, MSD_SIZE);
jurica238814 0:f8c1e0b2d473 123 ble.gap().setAdvertisingType(GapAdvertisingParams::ADV_NON_CONNECTABLE_UNDIRECTED);
jurica238814 10:fd91664032d8 124 ble.gap().setAdvertisingInterval(ADV_INTERVAL); // --> Has to be at least 100ms!
jurica238814 10:fd91664032d8 125 //ble.gap().startAdvertising();
jurica238814 0:f8c1e0b2d473 126 }
jurica238814 0:f8c1e0b2d473 127
jurica238814 3:2a4ac5b87046 128
jurica238814 3:2a4ac5b87046 129 uint8_t findMSDIndex(const Gap::AdvertisementCallbackParams_t *params){
jurica238814 1:5f34885f5cff 130 uint8_t i=0;
jurica238814 3:2a4ac5b87046 131 uint8_t len;
jurica238814 3:2a4ac5b87046 132
jurica238814 3:2a4ac5b87046 133 do{
jurica238814 3:2a4ac5b87046 134 len = params->advertisingData[i];
jurica238814 3:2a4ac5b87046 135 i++;
jurica238814 3:2a4ac5b87046 136 if(params->advertisingData[i] == MSD_ID) return i;
jurica238814 3:2a4ac5b87046 137 else i += (len-1);
jurica238814 3:2a4ac5b87046 138 }while(i<MAX_BLE_PACKET_SIZE);
jurica238814 3:2a4ac5b87046 139
jurica238814 3:2a4ac5b87046 140 return 0;
jurica238814 3:2a4ac5b87046 141 }
jurica238814 3:2a4ac5b87046 142
jurica238814 3:2a4ac5b87046 143 /**
jurica238814 3:2a4ac5b87046 144 * Function is called when BLE radio discovers any kind of advertisment
jurica238814 3:2a4ac5b87046 145 */
jurica238814 3:2a4ac5b87046 146 void advertisementCallback(const Gap::AdvertisementCallbackParams_t *params){
jurica238814 3:2a4ac5b87046 147 uint8_t i=0;
jurica238814 3:2a4ac5b87046 148 uint8_t msdOffset;
jurica238814 3:2a4ac5b87046 149
jurica238814 10:fd91664032d8 150 ble.gap().stopScan();
jurica238814 3:2a4ac5b87046 151 msdOffset = findMSDIndex(params);
jurica238814 3:2a4ac5b87046 152 if(msdOffset == 0){
jurica238814 3:2a4ac5b87046 153 // There's no MSD in BLE advertisement data
jurica238814 3:2a4ac5b87046 154 return;
jurica238814 3:2a4ac5b87046 155 }
jurica238814 3:2a4ac5b87046 156
jurica238814 3:2a4ac5b87046 157 if ((params->advertisingData[msdOffset]) == MSD_ID){
jurica238814 1:5f34885f5cff 158 // Follows Manufacturer Specific Data
jurica238814 3:2a4ac5b87046 159 if ((params->advertisingData[msdOffset+1]) == 0x59){
jurica238814 3:2a4ac5b87046 160 if ((params->advertisingData[msdOffset+2]) == 0x00){
jurica238814 1:5f34885f5cff 161 for(i=0; i<6; i++){
jurica238814 10:fd91664032d8 162 if((params->advertisingData[msdOffset+i+3]) == my_mac_address[5-i] || 1){
jurica238814 1:5f34885f5cff 163 continue;
jurica238814 1:5f34885f5cff 164 }
jurica238814 1:5f34885f5cff 165 else{
jurica238814 10:fd91664032d8 166 return;
jurica238814 1:5f34885f5cff 167 }
jurica238814 1:5f34885f5cff 168 }
jurica238814 2:5504b714c9ae 169 turnBuzzOffT.detach();
jurica238814 2:5504b714c9ae 170 WakeSleepT.detach();
jurica238814 2:5504b714c9ae 171 buzzer.write(0.5F);
jurica238814 2:5504b714c9ae 172 turnBuzzOffT.attach(turnBuzzOff, BUZZ_TIME);
jurica238814 10:fd91664032d8 173 //wait_ms(40);
jurica238814 10:fd91664032d8 174 //buzzer.write(0.0F);
jurica238814 1:5f34885f5cff 175 }
jurica238814 1:5f34885f5cff 176 }
jurica238814 2:5504b714c9ae 177 }
jurica238814 2:5504b714c9ae 178 }
jurica238814 2:5504b714c9ae 179
jurica238814 10:fd91664032d8 180 /**
jurica238814 10:fd91664032d8 181 * The function is called when ticker generates interrupt
jurica238814 10:fd91664032d8 182 */
jurica238814 10:fd91664032d8 183 void turnBuzzOff(void){
jurica238814 10:fd91664032d8 184 buzzer.write(0.0F);
jurica238814 10:fd91664032d8 185 turnBuzzOffT.detach();
jurica238814 10:fd91664032d8 186 ble.gap().startScan(advertisementCallback);
jurica238814 2:5504b714c9ae 187 WakeSleepT.attach(goToSleep, AWAKE_TIME);
jurica238814 10:fd91664032d8 188 }
jurica238814 10:fd91664032d8 189
jurica238814 10:fd91664032d8 190 void startAdvertising(){
jurica238814 10:fd91664032d8 191 ble.gap().startAdvertising();
jurica238814 10:fd91664032d8 192 radioState = ADVERTISING;
jurica238814 10:fd91664032d8 193 #if DEBUG
jurica238814 10:fd91664032d8 194 advLED = 0;
jurica238814 10:fd91664032d8 195 scanLED = 1;
jurica238814 10:fd91664032d8 196 #endif
jurica238814 10:fd91664032d8 197 WakeSleepT.detach();
jurica238814 10:fd91664032d8 198 WakeSleepT.attach(WakeMeUp, ADV_TIMER_TIME); // Call the wakeMeUp function
jurica238814 10:fd91664032d8 199 }
jurica238814 10:fd91664032d8 200
jurica238814 10:fd91664032d8 201 void startScanning(){
jurica238814 10:fd91664032d8 202 ble.gap().stopAdvertising();
jurica238814 10:fd91664032d8 203 ble.gap().setScanParams(SCAN_INTERVAL, SCAN_WINDOW);
jurica238814 10:fd91664032d8 204 ble.gap().setScanTimeout(SCAN_TIMER_TIME);
jurica238814 2:5504b714c9ae 205 ble.gap().startScan(advertisementCallback);
jurica238814 10:fd91664032d8 206 radioState = SCANNING;
jurica238814 10:fd91664032d8 207 #if DEBUG
jurica238814 10:fd91664032d8 208 advLED = 1;
jurica238814 10:fd91664032d8 209 scanLED = 0;
jurica238814 10:fd91664032d8 210 #endif
jurica238814 10:fd91664032d8 211 WakeSleepT.detach();
jurica238814 10:fd91664032d8 212 WakeSleepT.attach(WakeMeUp, SCAN_TIMER_TIME);
jurica238814 10:fd91664032d8 213 }
jurica238814 10:fd91664032d8 214
jurica238814 10:fd91664032d8 215 void WakeMeUp(){
jurica238814 8:570eb66d50b5 216 sleepFlag = 0;
jurica238814 10:fd91664032d8 217 switch(radioState){
jurica238814 10:fd91664032d8 218 case OFF:{
jurica238814 10:fd91664032d8 219 startAdvertising();
jurica238814 10:fd91664032d8 220 break;
jurica238814 10:fd91664032d8 221 }
jurica238814 10:fd91664032d8 222 case ADVERTISING:{
jurica238814 10:fd91664032d8 223 startScanning();
jurica238814 10:fd91664032d8 224 break;
jurica238814 10:fd91664032d8 225 }
jurica238814 10:fd91664032d8 226 case SCANNING:{
jurica238814 10:fd91664032d8 227 radioState = OFF;
jurica238814 10:fd91664032d8 228 ble.gap().stopAdvertising(); // Just in case
jurica238814 10:fd91664032d8 229 ble.gap().stopScan();
jurica238814 10:fd91664032d8 230 WakeSleepT.detach();
jurica238814 10:fd91664032d8 231 WakeSleepT.attach(goToSleep, FREE_TIME);
jurica238814 10:fd91664032d8 232 #if DEBUG
jurica238814 10:fd91664032d8 233 advLED = 1;
jurica238814 10:fd91664032d8 234 scanLED = 1;
jurica238814 10:fd91664032d8 235 #endif
jurica238814 10:fd91664032d8 236 break;
jurica238814 10:fd91664032d8 237 }
jurica238814 10:fd91664032d8 238 default: return;
jurica238814 10:fd91664032d8 239 }
jurica238814 2:5504b714c9ae 240 }
jurica238814 2:5504b714c9ae 241
jurica238814 2:5504b714c9ae 242 void goToSleep(){
jurica238814 2:5504b714c9ae 243 WakeSleepT.detach();
jurica238814 2:5504b714c9ae 244 WakeSleepT.attach(WakeMeUp, SLEEP_TIME);
jurica238814 2:5504b714c9ae 245 ble.gap().stopAdvertising();
jurica238814 2:5504b714c9ae 246 ble.gap().stopScan();
jurica238814 8:570eb66d50b5 247 sleepFlag = 1;
jurica238814 1:5f34885f5cff 248 }
jurica238814 1:5f34885f5cff 249
jurica238814 6:d14e3df498f4 250 void buzz(void){
jurica238814 6:d14e3df498f4 251 buzzer.write(0.5f);
jurica238814 6:d14e3df498f4 252 wait_ms(100);
jurica238814 6:d14e3df498f4 253 buzzer.write(0.0f);
jurica238814 9:2ab2be19add9 254 sleepFlag = 0;
jurica238814 6:d14e3df498f4 255 }
jurica238814 6:d14e3df498f4 256
jurica238814 6:d14e3df498f4 257 void pulse_handler(void){
jurica238814 10:fd91664032d8 258 #if DEBUG_ACC
jurica238814 6:d14e3df498f4 259 int_led = !int_led;
jurica238814 6:d14e3df498f4 260 #endif
jurica238814 6:d14e3df498f4 261 i2c_power.write(1.0F);
jurica238814 6:d14e3df498f4 262 buzzer_flag = 1;
jurica238814 8:570eb66d50b5 263 // Be awake some time
jurica238814 9:2ab2be19add9 264 //WakeSleepT.detach();
jurica238814 9:2ab2be19add9 265 //WakeSleepT.attach(goToSleep, AWAKE_TIME);
jurica238814 6:d14e3df498f4 266 }
jurica238814 6:d14e3df498f4 267
jurica238814 10:fd91664032d8 268 int main(void){
jurica238814 10:fd91664032d8 269 #if DEBUG
jurica238814 10:fd91664032d8 270 awake = 1;
jurica238814 10:fd91664032d8 271 advLED = 1;
jurica238814 10:fd91664032d8 272 scanLED = 1;
jurica238814 10:fd91664032d8 273 #endif
jurica238814 2:5504b714c9ae 274 WakeSleepT.attach(goToSleep, AWAKE_TIME);
jurica238814 0:f8c1e0b2d473 275 ble.init(bleInitComplete);
jurica238814 0:f8c1e0b2d473 276 ble.gap().setTxPower(txPower);
jurica238814 0:f8c1e0b2d473 277 GapAdvertisingData postavke = GapAdvertisingData();
jurica238814 0:f8c1e0b2d473 278
jurica238814 10:fd91664032d8 279 //ble.gap().setScanParams(SCAN_INTERVAL, SCAN_WINDOW);
jurica238814 10:fd91664032d8 280 //ble.gap().setScanTimeout(0.5);
jurica238814 10:fd91664032d8 281 //ble.gap().startScan(advertisementCallback);
jurica238814 1:5f34885f5cff 282
jurica238814 1:5f34885f5cff 283 buzzer.period(0.001F);
jurica238814 1:5f34885f5cff 284 buzzer.write(0.0F);
jurica238814 6:d14e3df498f4 285 gyro_power.period(0.01F);
jurica238814 6:d14e3df498f4 286 gyro_power.write(1.0F);
jurica238814 6:d14e3df498f4 287 i2c_power.period(0.01F);
jurica238814 6:d14e3df498f4 288 i2c_power.write(1.0F);
jurica238814 6:d14e3df498f4 289 wait_ms(1000);
jurica238814 6:d14e3df498f4 290
jurica238814 6:d14e3df498f4 291 /* Pulse interrupt detection */
jurica238814 6:d14e3df498f4 292 acc.set_register((char)CTRL_REG_4, (char) 0x04); // INT_EN_FF_MT Freefall/motion interrupt enabled
jurica238814 6:d14e3df498f4 293 wait_ms(1);
jurica238814 6:d14e3df498f4 294 acc.set_register((char)FF_MT_CFG, (char) 0b01011000); //ELE, Motion Flag ON, YEFE, X Event Flag Enable
jurica238814 6:d14e3df498f4 295 wait_ms(1);
jurica238814 6:d14e3df498f4 296 acc.set_register((char)CTRL_REG_5, (char) 0x00); // INT_EN_FF_MT interrupt is router t0 INT2
jurica238814 6:d14e3df498f4 297 wait_ms(1);
jurica238814 6:d14e3df498f4 298 acc.set_register((char)FF_COUNT, (char) 0x08); // Set Counter degister value (10ms)
jurica238814 6:d14e3df498f4 299 wait_ms(1);
jurica238814 6:d14e3df498f4 300 acc.set_register((char)FF_MT_THS, (char) 0x90); // Set TH value for motion detection on 1 G (1/0.063) and DBCNTM = 1 (Increments or clears counter)
jurica238814 6:d14e3df498f4 301 wait_ms(1);
jurica238814 6:d14e3df498f4 302
jurica238814 6:d14e3df498f4 303 /* Setup for the interrupt handler */
jurica238814 9:2ab2be19add9 304 //gyro_pulse.rise(&pulse_handler); // -------------------------------------
jurica238814 6:d14e3df498f4 305 acc.set_register((char)CTRL_REG_1, (char) 0x01); // Flow data rate and Active mode
jurica238814 6:d14e3df498f4 306 wait(1);
jurica238814 0:f8c1e0b2d473 307
jurica238814 2:5504b714c9ae 308 __enable_irq();
jurica238814 2:5504b714c9ae 309
jurica238814 0:f8c1e0b2d473 310 /* SpinWait for initialization to complete. This is necessary because the
jurica238814 0:f8c1e0b2d473 311 * BLE object is used in the main loop below. */
jurica238814 3:2a4ac5b87046 312 while (ble.hasInitialized() == false){
jurica238814 3:2a4ac5b87046 313 /* spin loop */
jurica238814 3:2a4ac5b87046 314 }
jurica238814 9:2ab2be19add9 315
jurica238814 1:5f34885f5cff 316 while(true){
jurica238814 9:2ab2be19add9 317 if(sleepFlag){
jurica238814 9:2ab2be19add9 318 if(!awake) awake = 1;
jurica238814 9:2ab2be19add9 319 __WFI();
jurica238814 9:2ab2be19add9 320 }
jurica238814 9:2ab2be19add9 321 else{
jurica238814 9:2ab2be19add9 322 if(awake) awake = 0;
jurica238814 9:2ab2be19add9 323 ble.waitForEvent();
jurica238814 9:2ab2be19add9 324 }
jurica238814 0:f8c1e0b2d473 325 }
jurica238814 0:f8c1e0b2d473 326 }