Chanel's edits

Dependencies:   max32630fthr USBDevice

Revision:
1:6e6f7e3cc1e1
Child:
2:a96a53e6c6a3
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/bt32630.h	Wed Feb 12 07:35:43 2020 +0000
@@ -0,0 +1,86 @@
+extern MAX86150 max86150Sensor;
+extern Serial pc;
+const static char     DEVICE_NAME[] = "Nordic_HRM";
+static const uint16_t uuid16_list[] = {GattService::UUID_HEART_RATE_SERVICE};
+
+static uint8_t hrmCounter = 100; // init HRM to 100bps
+static HeartRateService *hrServicePtr;
+
+static EventQueue eventQueue(/* event count */ 16 * EVENTS_EVENT_SIZE);
+
+
+void disconnectionCallback(const Gap::DisconnectionCallbackParams_t *params)
+{
+    BLE::Instance().gap().startAdvertising(); // restart advertising
+}
+
+void updateSensorValue() {
+    // Do blocking calls or whatever is necessary for sensor polling.
+    // In our case, we simply update the HRM measurement.
+   /* hrmCounter++;
+
+    //  100 <= HRM bps <=175
+    if (hrmCounter == 175) {
+        hrmCounter = 100;
+    }*/
+    pc.printf("Inside update sensor value \n");
+    if(max86150Sensor.check()>0)
+        {
+        hrServicePtr->updateHeartRate(max86150Sensor.readPartID());
+        return;
+        }
+    hrmCounter = 133;
+    hrServicePtr->updateHeartRate(hrmCounter);
+}
+
+void periodicCallback(void)
+{
+
+    if (BLE::Instance().getGapState().connected) {
+        eventQueue.call(updateSensorValue);
+    }
+}
+
+void onBleInitError(BLE &ble, ble_error_t error)
+{
+    (void)ble;
+    (void)error;
+   /* Initialization error handling should go here */
+}
+
+void bleInitComplete(BLE::InitializationCompleteCallbackContext *params)
+{
+    pc.printf("In bleInitComplete() ...\n");
+    BLE&        ble   = params->ble;
+    ble_error_t error = params->error;
+
+    if (error != BLE_ERROR_NONE) {
+        onBleInitError(ble, error);
+        return;
+    }
+
+    if (ble.getInstanceID() != BLE::DEFAULT_INSTANCE) {
+        return;
+    }
+
+    ble.gap().onDisconnection(disconnectionCallback);
+
+    /* Setup primary service. */
+    hrServicePtr = new HeartRateService(ble, hrmCounter, HeartRateService::LOCATION_FINGER);
+
+    /* 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::GENERIC_HEART_RATE_SENSOR);
+    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();
+    
+    pc.printf("Exiting bleInitComplete()");
+}
+
+void scheduleBleEventsProcessing(BLE::OnEventsToProcessCallbackContext* context) {
+    BLE &ble = BLE::Instance();
+    eventQueue.call(Callback<void()>(&ble, &BLE::processEvents));
+}
\ No newline at end of file