se
Dependencies: SDFileSystem circular_buffer MPU6050 SoftSerial
source/main.cpp
- Committer:
- OsmanKameric
- Date:
- 2017-01-10
- Revision:
- 0:a4de55cab4e2
- Child:
- 1:2cc1c9a45be7
File content as of revision 0:a4de55cab4e2:
#include <events/mbed_events.h> #include <mbed.h> #include "ble/BLE.h" #include "ble/Gap.h" #include "ble/services/BatteryService.h" #include "MPU6050.h" #include "MPUService.h" DigitalOut alivenessLED(LED1, 0); DigitalOut actuatedLED(LED2, 0); Serial pc(p6, p8); MPU6050 mpu6050; static MPUService *mpuServicePtr; static float x =0.0; const static char DEVICE_NAME[] = "MPU"; static const uint16_t uuid16_list[] = {MPUService::MPU_SERVICE_UUID}; static EventQueue eventQueue(/* event count */ 10 * /* event size */ 32); //InterruptIn button(BUTTON1); void scheduleBleEventsProcessing(BLE::OnEventsToProcessCallbackContext* context) { BLE& ble = BLE::Instance(); eventQueue.call(Callback<void()>(&ble, &BLE::processEvents)); } void disconnectionCallback(const Gap::DisconnectionCallbackParams_t *params) { (void) params; BLE::Instance().gap().startAdvertising(); } void onBleInitError(BLE &ble, ble_error_t error) { /* Initialization error handling should go here */ } void updateSensorValue() { x=x+0.1; alivenessLED = !alivenessLED; mpuServicePtr->updateSensorValue(x); } void periodicCallback(void) { if (BLE::Instance().getGapState().connected) { eventQueue.call(updateSensorValue); } } void bleInitComplete(BLE::InitializationCompleteCallbackContext* params) { BLE& ble = params->ble; ble_error_t error = params->error; if (error != BLE_ERROR_NONE) { /* In case of error, forward the error handling to onBleInitError */ onBleInitError(ble, error); return; } /* Ensure that it is the default instance of BLE */ if (ble.getInstanceID() != BLE::DEFAULT_INSTANCE) { return; } ble.gap().onDisconnection(disconnectionCallback); mpuServicePtr = new MPUService(ble, x); /* setup advertising */ ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED | GapAdvertisingData::LE_GENERAL_DISCOVERABLE); ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_16BIT_SERVICE_IDS, (uint8_t*)uuid16_list, sizeof(uuid16_list)); ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LOCAL_NAME, (uint8_t*)DEVICE_NAME, sizeof(DEVICE_NAME)); ble.gap().setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED); ble.gap().setAdvertisingInterval(1000); /* 1000ms. */ ble.gap().startAdvertising(); } int main() { eventQueue.call_every(500, periodicCallback); BLE& ble = BLE::Instance(); ble.onEventsToProcess(scheduleBleEventsProcessing); ble.init(bleInitComplete); eventQueue.dispatch_forever(); return 0; }