Chanel's edits
Dependencies: max32630fthr USBDevice
bt32630.h
- Committer:
- saleiferis
- Date:
- 2020-03-07
- Revision:
- 10:28b8729cf5dc
- Parent:
- 7:4debec043316
- Child:
- 14:ee2175578993
File content as of revision 10:28b8729cf5dc:
//#include "HeartRateService.h" #include "ECGService.h" 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 int16_t hrmCounter = 100; // init HRM to 100bps //static HeartRateService *hrServicePtr; extern ECGService *hrServicePtr; static EventQueue eventQueue(/* event count */ 16 * EVENTS_EVENT_SIZE); void connectionCallback(const Gap::ConnectionCallbackParams_t *params) { pc.printf("Connected to BLE Client...\n"); } 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; } //hrmCounter = 133; hrServicePtr->updateHeartRate(hrmCounter); */ int16_t ecgsigned16; if(max86150Sensor.check()>0){ ecgsigned16 = (int16_t) (max86150Sensor.getFIFOECG()>>2); max86150Sensor.nextSample(); //hrServicePtr->updateHeartRate(ecgsigned16); pc.printf("%d\n",ecgsigned16); } } 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) { 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); ble.gap().onConnection(connectionCallback); /* Setup primary service. */ //hrServicePtr = new HeartRateService(ble, hrmCounter, HeartRateService::LOCATION_FINGER); hrServicePtr = new ECGService(ble, hrmCounter); pc.printf("Setup primary service ...\n"); /* 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() ... \n"); return; } void scheduleBleEventsProcessing(BLE::OnEventsToProcessCallbackContext* context) { BLE &ble = BLE::Instance(); eventQueue.call(Callback<void()>(&ble, &BLE::processEvents)); }