For Blood Pressure Demo
Embed:
(wiki syntax)
Show/hide line numbers
main.cpp
00001 #include "mbed.h" 00002 #include "BLE.h" 00003 #include "DeviceInformationService.h" 00004 #include "BloodPressureService.h" 00005 00006 BLEDevice ble; 00007 DigitalOut led01(LED1); 00008 00009 const static char DEVICE_NAME[] = "Blood Pressure"; 00010 static const uint16_t uuid16_list[] = {GattService::UUID_BLOOD_PRESSURE_SERVICE, 00011 GattService::UUID_DEVICE_INFORMATION_SERVICE}; 00012 static volatile bool triggerSensorPolling = false; 00013 00014 void disconnectionCallback(const Gap::DisconnectionCallbackParams_t *params) 00015 { 00016 ble.startAdvertising(); // restart advertising 00017 } 00018 00019 void periodicCallback(void) 00020 { 00021 led01 = !led01; /* Do blinky on LED1 while we're waiting for BLE events */ 00022 00023 /* Note that the periodicCallback() executes in interrupt context, so it is safer to do 00024 * heavy-weight sensor polling from the main thread. */ 00025 triggerSensorPolling = true; 00026 } 00027 00028 int main(void) 00029 { 00030 led01 = 1; 00031 Ticker ticker; 00032 ticker.attach(periodicCallback, 1); // blink LED every second 00033 00034 ble.init(); 00035 ble.gap().onDisconnection(disconnectionCallback); 00036 00037 /* Setup primary service. */ 00038 float SystolicValue = 100.0f; // mmHg 00039 float DiastolicValue = 70.0f; // 00040 float MeanArterialValue = 55.0f; // 00041 00042 BloodPressureService BloPressureService(ble, SystolicValue, DiastolicValue, MeanArterialValue, 0); 00043 00044 /* Setup auxiliary service. */ 00045 DeviceInformationService deviceInfo(ble, "ARM", "Model1", "SN1", "hw-rev1", "fw-rev1", "soft-rev1"); 00046 00047 /* Setup advertising. */ 00048 ble.accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED | GapAdvertisingData::LE_GENERAL_DISCOVERABLE); 00049 ble.accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_16BIT_SERVICE_IDS, (uint8_t *)uuid16_list, sizeof(uuid16_list)); 00050 ble.accumulateAdvertisingPayload(GapAdvertisingData::GENERIC_BLOOD_PRESSURE); 00051 ble.accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LOCAL_NAME, (uint8_t *)DEVICE_NAME, sizeof(DEVICE_NAME)); 00052 ble.setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED); 00053 ble.setAdvertisingInterval(1000); 00054 ble.startAdvertising(); 00055 00056 while (1) { 00057 // check for trigger from periodicCallback() 00058 if (triggerSensorPolling && ble.getGapState().connected) { 00059 triggerSensorPolling = false; 00060 00061 // Do blocking calls or whatever is necessary for sensor polling. 00062 // In our case, we simply update the HRM measurement. 00063 SystolicValue++; 00064 DiastolicValue++; 00065 MeanArterialValue++; 00066 00067 if (SystolicValue == 140.0f) { 00068 SystolicValue = 90.0f; 00069 } 00070 if (DiastolicValue == 90.0f) { 00071 DiastolicValue = 50.0f; 00072 } 00073 if (MeanArterialValue == 105.0f) { 00074 MeanArterialValue = 70.0f; 00075 } 00076 // update Blood Pressure 00077 BloPressureService.updateBloodPressureMeasurement(SystolicValue, DiastolicValue, MeanArterialValue); 00078 } else { 00079 ble.waitForEvent(); // low power wait for event 00080 } 00081 } 00082 }
Generated on Wed Jul 13 2022 18:14:47 by 1.7.2