Chanel's edits
Dependencies: max32630fthr USBDevice
bt32630.h
- Committer:
- saleiferis
- Date:
- 2020-02-23
- Revision:
- 5:30495ab95b86
- Parent:
- 4:4233f5538abf
- Child:
- 6:2f1d4a9e201f
File content as of revision 5:30495ab95b86:
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 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; }*/ //pc.printf("Inside update sensor value \n"); if(max86150Sensor.check()>0) { hrServicePtr->updateHeartRate((uint16_t)max86150Sensor.getFIFOECG()); 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) { pc.printf("In ERROR if ...\n"); onBleInitError(ble, error); return; } if (ble.getInstanceID() != BLE::DEFAULT_INSTANCE) { pc.printf("In InstanceID ERROR if ...\n"); return; } ble.gap().onDisconnection(disconnectionCallback); ble.gap().onConnection(connectionCallback); pc.printf("Set connection/disconnection callbacks ...\n"); /* Setup primary service. */ //hrServicePtr = new HeartRateService(ble, hrmCounter, HeartRateService::LOCATION_FINGER); hrServicePtr = new EcgService(ble, hrmCounter, HeartRateService::LOCATION_FINGER); 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)); pc.printf("Accumulate asvertising payload done ...\n"); ble.gap().setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED); ble.gap().setAdvertisingInterval(1000); /* 1000ms */ pc.printf("Before startAdvertising() ...\n"); ble.gap().startAdvertising(); pc.printf("After startAdvertising() ...\n"); pc.printf("Exiting bleInitComplete() ... \n"); return; } void scheduleBleEventsProcessing(BLE::OnEventsToProcessCallbackContext* context) { BLE &ble = BLE::Instance(); eventQueue.call(Callback<void()>(&ble, &BLE::processEvents)); }