aconno acnsensa project for iOS devices with iBeacon packets support.
Dependencies: LSM9DS1 Si7006A20 aconno_SEGGER_RTT aconno_bsp adc52832_common
Diff: main.cpp
- Revision:
- 26:834af521af0a
- Parent:
- 21:71f2f1b314f2
- Child:
- 27:67467a7a56b3
--- a/main.cpp Fri Aug 03 14:41:28 2018 +0200 +++ b/main.cpp Mon Aug 06 07:59:33 2018 +0000 @@ -55,7 +55,6 @@ static NRF52_DigitalOut lightPower(p28); static NRF52_DigitalOut temperaturePower(p31); static NRF52_DigitalOut shdn(p6); -static NRF52_DigitalOut led(p23); static NRF52_DigitalOut power(p2); static NRF52_DigitalOut cs(p7); static Si7006 *si; @@ -74,27 +73,31 @@ #define printf(...) #endif -static bool sleepFlag = true; - static vector3_s memsAccelerometerInit; static vector3_s memsGyroscopeInit; static vector3_s memsMagnetometerInit; static GapAdvertisingData adv_data = GapAdvertisingData(); -typedef struct __attribute__((packed, aligned(1))) +struct __attribute__((packed, aligned(1))) iBeaconMSD_t { // AppleID is constant - uint16_t appleID = 0x004C; + uint16_t appleID; // secondID is constant - uint8_t secondID = 0x02; + uint8_t secondID; // DataSize is constant - uint8_t DataSize = 0x15; - uint8_t UUID[16] = {UUID_INIT}; - uint16_t major = MAJOR; - uint16_t minor = MINOR; - int8_t RSSI = RSSI_INIT; -}IBeaconMSD; + uint8_t dataSize; + uint8_t UUID[16]; + uint16_t major; + uint16_t minor; + int8_t RSSI; +}static iBeaconMSD = {.appleID = 0x004C, + .secondID = 0x02, + .dataSize = 0x15, + .UUID = {UUID_INIT}, + .major = MAJOR, + .minor = MINOR, + .RSSI = RSSI_INIT}; struct __attribute__((packed, aligned(1))) advertising_packet { @@ -124,7 +127,6 @@ } static advertising_packet advertisementPacket; -IBeaconMSD ibeaconMSD; void disconnectionCallback(const Gap::DisconnectionCallbackParams_t *params) { @@ -133,14 +135,6 @@ BLE::Instance().gap().startAdvertising(); } -/** - * Function for waking the core up - */ -void wakeMeUp() -{ - sleepFlag = false; -} - void onConnectionCallback(const Gap::ConnectionCallbackParams_t *params) { printf("Connection callback.\n"); @@ -343,7 +337,7 @@ GapAdvertisingData::BREDR_NOT_SUPPORTED); ble.gap().accumulateAdvertisingPayload( GapAdvertisingData::MANUFACTURER_SPECIFIC_DATA, - (uint8_t*)&ibeaconMSD, sizeof(ibeaconMSD)); + (uint8_t*)&iBeaconMSD, sizeof(iBeaconMSD_t)); ble.gap().startAdvertising(); } if(++advertisementType > 2) advertisementType = 0; @@ -365,16 +359,6 @@ analogIn.addChannel(7); // Temp analogIn.calibrate(); - advertisementPacket.header = APPLICATION_ID; - - ibeaconMSD.appleID = 0x004C; - ibeaconMSD.secondID = 0x02; - ibeaconMSD.DataSize = 0x15; - ibeaconMSD.UUID[0] = 0x11; - ibeaconMSD.UUID[1] = 0x22; - ibeaconMSD.UUID[2] = 0x33; - ibeaconMSD.RSSI = -4; - BLE &ble = BLE::Instance(); ble.init(bleInitCompleteSensors); while(ble.hasInitialized() == false){ @@ -392,11 +376,6 @@ mems->startGyroscope(); mems->startMagnetometer(); - led = 1; - - Ticker ticker; - ticker.attach(wakeMeUp, SLEEP_TIME); // Wake the device up - eventQueue.call_every(500, updateData); // This call stops main thread