aconno acnsensa project for iOS devices with iBeacon packets support.
Dependencies: LSM9DS1 Si7006A20 aconno_SEGGER_RTT aconno_bsp adc52832_common
Diff: main.cpp
- Revision:
- 3:78ceda8ef565
- Parent:
- 2:c0654c5fb771
- Child:
- 4:634796e5b8c3
--- a/main.cpp Wed Dec 13 09:46:08 2017 +0000 +++ b/main.cpp Fri Mar 02 12:37:27 2018 +0000 @@ -63,9 +63,9 @@ static bool sleepFlag = true; -static vector3_s memsAccInit; -static vector3_s memsGyrInit; -static vector3_s memsMagInit; +static vector3_s memsAccelerometerInit; +static vector3_s memsGyroscopeInit; +static vector3_s memsMagnetometerInit; static BLE &ble = BLE::Instance(); static GapAdvertisingData adv_data = GapAdvertisingData(); @@ -75,9 +75,9 @@ uint8_t type; union{ struct{ - int16_t gyr[3]; - int16_t acc[3]; - int16_t mag[3]; + int16_t gyroscope[3]; + int16_t accelerometer[3]; + int16_t magnetometer[3]; }; struct{ float temperature; @@ -87,7 +87,7 @@ }; }; }; -static advertising_packet advPacket; +static advertising_packet advertisementPacket; void disconnectionCallback(const Gap::DisconnectionCallbackParams_t *params){ // Restart Advertising on disconnection @@ -101,12 +101,6 @@ sleepFlag = false; } -void onBleInitError(BLE &ble, ble_error_t error){ - /* Avoid compiler warnings */ - (void) ble; - (void) error; -} - /** * Callback triggered when the ble initialization process has finished */ @@ -114,13 +108,12 @@ BLE& ble = params->ble; ble_error_t error = params->error; - if (error != BLE_ERROR_NONE) { - onBleInitError(ble, error); + if (error != BLE_ERROR_NONE){ return; } /* Ensure that it is the default instance of BLE */ - if(ble.getInstanceID() != BLE::DEFAULT_INSTANCE) { + if(ble.getInstanceID() != BLE::DEFAULT_INSTANCE){ return; } @@ -128,7 +121,7 @@ /* setup advertising */ ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED); - ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::MANUFACTURER_SPECIFIC_DATA, (uint8_t *)&advPacket, sizeof(advPacket)); + ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::MANUFACTURER_SPECIFIC_DATA, (uint8_t *)&advertisementPacket, sizeof(advertisementPacket)); ble.gap().setAdvertisingType(GapAdvertisingParams::ADV_NON_CONNECTABLE_UNDIRECTED); ble.gap().setAdvertisingInterval(ADV_INTERVAL); ble.gap().startAdvertising(); @@ -152,68 +145,68 @@ return result; } -void readGyr(vector3_s *gyro_data){ - mems->readGyro((int16_t *)gyro_data); - *gyro_data -= memsGyrInit; +void readGyroscope(vector3_s *gyroscopeData){ + mems->readGyroscope((int16_t *)gyroscopeData); + *gyroscopeData -= memsGyroscopeInit; } -void readAcc(vector3_s *acc_data){ - mems->readAcc((int16_t *)acc_data); - *acc_data -= memsAccInit; +void readAccelerometer(vector3_s *accelerometerData){ + mems->readAccelerometer((int16_t *)accelerometerData); + *accelerometerData -= memsAccelerometerInit; } -void readMag(vector3_s *magneto_data){ - mems->readMag((int16_t *)magneto_data); - *magneto_data -= memsMagInit; +void readMagnetometer(vector3_s *magnetometerData){ + mems->readMagnetometer((int16_t *)magnetometerData); + *magnetometerData -= memsMagnetometerInit; } -void calibrateAcc(){ - vector3_s acc_data; +void calibrateAccelerometer(){ + vector3_s accelerometerData; for(uint8_t counter = 0; counter < CALIBRATION_STEPS; ++counter){ - readAcc(&acc_data); - memsAccInit += acc_data; + readAccelerometer(&accelerometerData); + memsAccelerometerInit += accelerometerData; } - memsAccInit /= CALIBRATION_STEPS; + memsAccelerometerInit /= CALIBRATION_STEPS; } -void calibrateGyr(){ - vector3_s gyro_data; +void calibrateGyroscope(){ + vector3_s gyroscopeData; for(uint8_t counter = 0; counter < CALIBRATION_STEPS; ++counter){ - readGyr(&gyro_data); - memsGyrInit += gyro_data; + readGyroscope(&gyroscopeData); + memsGyroscopeInit += gyroscopeData; } - memsGyrInit /= CALIBRATION_STEPS; + memsGyroscopeInit /= CALIBRATION_STEPS; } void calibrateMag(){ - vector3_s mag_data; + vector3_s magnetometerData; for(uint8_t counter = 0; counter < CALIBRATION_STEPS; ++counter){ - readMag(&mag_data); - memsMagInit += mag_data; + readMagnetometer(&magnetometerData); + memsMagnetometerInit += magnetometerData; } - memsMagInit /= CALIBRATION_STEPS; + memsMagnetometerInit /= CALIBRATION_STEPS; } void updateData(){ - static uint8_t adv_type = 0; + static uint8_t advertisementType = 0; - if(adv_type < 1){ - advPacket.type = 0x00; - readGyr((vector3_s *)advPacket.gyr); - readAcc((vector3_s *)advPacket.acc); - readMag((vector3_s *)advPacket.mag); + if(advertisementType < 1){ + advertisementPacket.type = 0x00; + readGyroscope((vector3_s *)advertisementPacket.gyroscope); + readAccelerometer((vector3_s *)advertisementPacket.accelerometer); + readMagnetometer((vector3_s *)advertisementPacket.magnetometer); } else{ - advPacket.type = 0x01; - advPacket.temperature = getTemperature(); - advPacket.light = getLight(); - advPacket.humidity = getHumidity(); - advPacket.pressure = mpl115a1->getPressure(); + advertisementPacket.type = 0x01; + advertisementPacket.temperature = getTemperature(); + advertisementPacket.light = getLight(); + advertisementPacket.humidity = getHumidity(); + advertisementPacket.pressure = mpl115a1->getPressure(); } - if(++adv_type > 2) adv_type = 0; + if(++advertisementType > 2) advertisementType = 0; adv_data = ble.getAdvertisingData(); - adv_data.updateData(adv_data.MANUFACTURER_SPECIFIC_DATA, (uint8_t *)&advPacket, sizeof(advPacket)); + adv_data.updateData(adv_data.MANUFACTURER_SPECIFIC_DATA, (uint8_t *)&advertisementPacket, sizeof(advertisementPacket)); ble.setAdvertisingData(adv_data); } @@ -225,7 +218,7 @@ lightPower = 1; shdn = 1; // Wake up the pressure sensor - advPacket.header = APPLICATION_ID; + advertisementPacket.header = APPLICATION_ID; ble.init(bleInitComplete); @@ -235,9 +228,9 @@ spi = new SPI(SPI_MOSI, SPI_MISO, SPI_SCLK); mpl115a1 = new MPL115A1(*spi, cs); - mems->startAcc(); - mems->startGyro(); - mems->startMag(); + mems->startAccelerometer(); + mems->startGyroscope(); + mems->startMagnetometer(); led = 1;