Nora Vazbyte
/
99Problems-BLEAint1
app critics will say it's money, cash, toes
Diff: source/main.cpp
- Revision:
- 1:df8884d38960
- Parent:
- 0:07212de2fec1
- Child:
- 2:1957a4985d6e
--- a/source/main.cpp Sun Oct 28 12:36:21 2018 +0000 +++ b/source/main.cpp Sun Oct 28 12:51:59 2018 +0000 @@ -16,17 +16,33 @@ #include <events/mbed_events.h> #include <mbed.h> +#include "MPU9250.h" #include "ble/BLE.h" #include "ble/Gap.h" -#include "ble/services/BatteryService.h" +#include "ble/services/HeartRateService.h" + +#define Kp 2.0f * 5.0f // these are the free parameters in the Mahony filter and fusion scheme, Kp for proportional feedback, Ki for integral +#define Ki 0.0f + +//****************************************************************************** +MPU9250::MPU9250(PinName sda, PinName scl) +{ + i2c_ = new I2C(sda, scl); + i2c_->frequency(400000); +} + +//****************************************************************************** +MPU9250::MPU9250(I2C *i2c):i2c_(i2c){} + +//****************************************************************************** DigitalOut led1(LED1, 1); -const static char DEVICE_NAME[] = "BATTERY"; -static const uint16_t uuid16_list[] = {GattService::UUID_BATTERY_SERVICE}; +const static char DEVICE_NAME[] = "ProVaida"; +static const uint16_t uuid16_list[] = {GattService::UUID_HEART_RATE_SERVICE}; -static uint8_t batteryLevel = 50; -static BatteryService* batteryServicePtr; +uint8_t hrmCounter = 100; +static HeartRateService* hrService; static EventQueue eventQueue(/* event count */ 16 * EVENTS_EVENT_SIZE); @@ -35,13 +51,18 @@ BLE::Instance().gap().startAdvertising(); } + + + + + + void updateSensorValue() { - batteryLevel++; - if (batteryLevel > 100) { - batteryLevel = 20; + hrmCounter++; + if (hrmCounter > 175) { + hrmCounter = 100; } - - batteryServicePtr->updateBatteryLevel(batteryLevel); + hrService->updateHeartRate(hrmCounter); } void blinkCallback(void) @@ -55,7 +76,7 @@ } /** - * This function is called when the ble initialization process has failled + * This function is called when the ble initialization process has failed */ void onBleInitError(BLE &ble, ble_error_t error) { @@ -97,7 +118,7 @@ ble.gap().onDisconnection(disconnectionCallback); /* Setup primary service */ - batteryServicePtr = new BatteryService(ble, batteryLevel); + hrService = new HeartRateService(ble, hrmCounter, HeartRateService::LOCATION_FINGER); /* Setup advertising */ ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED | GapAdvertisingData::LE_GENERAL_DISCOVERABLE);