Lizzy project

Dependencies:   aconno_I2C Lis2dh12 adc52832_common aconno_SEGGER_RTT

Committer:
jurica238814
Date:
Wed Mar 07 13:40:28 2018 +0000
Revision:
0:fc77522f4d28
Child:
8:7ba4f82de9b6
Init commit.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jurica238814 0:fc77522f4d28 1 /*
jurica238814 0:fc77522f4d28 2 * Made by Jurica Resetar @ aconno
jurica238814 0:fc77522f4d28 3 * More info @ aconno.de
jurica238814 0:fc77522f4d28 4 *
jurica238814 0:fc77522f4d28 5 */
jurica238814 0:fc77522f4d28 6
jurica238814 0:fc77522f4d28 7 #include "aconno_ble.h"
jurica238814 0:fc77522f4d28 8
jurica238814 0:fc77522f4d28 9 /**
jurica238814 0:fc77522f4d28 10 * Callback triggered when the ble initialization process has finished
jurica238814 0:fc77522f4d28 11 */
jurica238814 0:fc77522f4d28 12
jurica238814 0:fc77522f4d28 13 void bleInitComplete(BLE::InitializationCompleteCallbackContext *params)
jurica238814 0:fc77522f4d28 14 {
jurica238814 0:fc77522f4d28 15 advertising_packet advertisementPacket;
jurica238814 0:fc77522f4d28 16 BLE& ble = params->ble;
jurica238814 0:fc77522f4d28 17 ble_error_t error = params->error;
jurica238814 0:fc77522f4d28 18
jurica238814 0:fc77522f4d28 19 if (error != BLE_ERROR_NONE) {
jurica238814 0:fc77522f4d28 20 return;
jurica238814 0:fc77522f4d28 21 }
jurica238814 0:fc77522f4d28 22
jurica238814 0:fc77522f4d28 23 /* Ensure that it is the default instance of BLE */
jurica238814 0:fc77522f4d28 24 if(ble.getInstanceID() != BLE::DEFAULT_INSTANCE) {
jurica238814 0:fc77522f4d28 25 return;
jurica238814 0:fc77522f4d28 26 }
jurica238814 0:fc77522f4d28 27
jurica238814 0:fc77522f4d28 28 advertisementPacket.header = APPLICATION_ID;
jurica238814 0:fc77522f4d28 29 advertisementPacket.type = 0x00;
jurica238814 0:fc77522f4d28 30 advertisementPacket.gyroscope[0] = (int16_t)0;
jurica238814 0:fc77522f4d28 31 advertisementPacket.gyroscope[1] = (int16_t)0;
jurica238814 0:fc77522f4d28 32 advertisementPacket.gyroscope[2] = (int16_t)0;
jurica238814 0:fc77522f4d28 33 advertisementPacket.accelerometer[0] = (int16_t)0;
jurica238814 0:fc77522f4d28 34 advertisementPacket.accelerometer[1] = (int16_t)0;
jurica238814 0:fc77522f4d28 35 advertisementPacket.accelerometer[2] = (int16_t)0;
jurica238814 0:fc77522f4d28 36 advertisementPacket.magnetometer[0] = (int16_t)0;
jurica238814 0:fc77522f4d28 37 advertisementPacket.magnetometer[1] = (int16_t)0;
jurica238814 0:fc77522f4d28 38 advertisementPacket.magnetometer[2] = (int16_t)0;
jurica238814 0:fc77522f4d28 39
jurica238814 0:fc77522f4d28 40 /* setup advertising */
jurica238814 0:fc77522f4d28 41 ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED);
jurica238814 0:fc77522f4d28 42 ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::MANUFACTURER_SPECIFIC_DATA, (uint8_t *)&advertisementPacket, sizeof(uint8_t)*11);
jurica238814 0:fc77522f4d28 43 ble.gap().setAdvertisingInterval(ADV_INTERVAL_MS);
jurica238814 0:fc77522f4d28 44 ble.gap().startAdvertising();
jurica238814 0:fc77522f4d28 45 }
jurica238814 0:fc77522f4d28 46
jurica238814 0:fc77522f4d28 47 void updatePayload(BLE *ble, advertising_packet *advertisementPacket)
jurica238814 0:fc77522f4d28 48 {
jurica238814 0:fc77522f4d28 49 ble->gap().stopAdvertising();
jurica238814 0:fc77522f4d28 50 GapAdvertisingData advetisementData = GapAdvertisingData();
jurica238814 0:fc77522f4d28 51 advetisementData = ble->getAdvertisingData();
jurica238814 0:fc77522f4d28 52 advetisementData.updateData(advetisementData.MANUFACTURER_SPECIFIC_DATA, (uint8_t *)advertisementPacket, sizeof(advertising_packet));
jurica238814 0:fc77522f4d28 53 ble->setAdvertisingData(advetisementData);
jurica238814 0:fc77522f4d28 54 //ble->gap().startAdvertising();
jurica238814 0:fc77522f4d28 55 }