For Blood Pressure Demo

BLE_BloodPressure_demo implements Blood Pressure Service which enables a collector device to connect and interact with it. the service spec can be found here. User can download the APP 'nRF Connect' or 'nRF Toolbox' available in both App Store and Google Play to scan the adverting and connect to the module.

main.cpp

Committer:
Marcomissyou
Date:
2015-05-29
Revision:
0:546d7178e278
Child:
1:fc03791a9842

File content as of revision 0:546d7178e278:

#include "mbed.h"
#include "BLEDevice.h"
#include "DeviceInformationService.h"
#include "BloodPressureService.h"
 
#define UPDATE_PARAMS_FOR_LONGER_CONNECTION_INTERVAL 0
 
BLEDevice  ble;
DigitalOut led01(LED1);
 
const static char     DEVICE_NAME[]        = "Blood Pressure";
static const uint16_t uuid16_list[]        = {GattService::UUID_BLOOD_PRESSURE_SERVICE,
                                              GattService::UUID_DEVICE_INFORMATION_SERVICE};
static volatile bool  triggerSensorPolling = false;
 
void disconnectionCallback(Gap::Handle_t handle, Gap::DisconnectionReason_t reason)
{
    ble.startAdvertising(); // restart advertising
}
 
void periodicCallback(void)
{
    led01 = !led01; /* Do blinky on LED1 while we're waiting for BLE events */
 
    /* Note that the periodicCallback() executes in interrupt context, so it is safer to do
     * heavy-weight sensor polling from the main thread. */
    triggerSensorPolling = true;
}
 
int main(void)
{
    led01 = 1;
    Ticker ticker;
    ticker.attach(periodicCallback, 1); // blink LED every second
 
    ble.init();
    ble.onDisconnection(disconnectionCallback);
 
    /* Setup primary service. */
    float SystolicValue = 100.0f; //  mmHg
    float DiastolicValue = 70.0f; //  
    float MeanArterialValue = 55.0f; //
    
    BloodPressureService BloPressureService(ble, SystolicValue, DiastolicValue, MeanArterialValue, 0);
 
    /* Setup auxiliary service. */
    DeviceInformationService deviceInfo(ble, "ARM", "Model1", "SN1", "hw-rev1", "fw-rev1", "soft-rev1");
 
    /* Setup advertising. */
    ble.accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED | GapAdvertisingData::LE_GENERAL_DISCOVERABLE);
    ble.accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_16BIT_SERVICE_IDS, (uint8_t *)uuid16_list, sizeof(uuid16_list));
    ble.accumulateAdvertisingPayload(GapAdvertisingData::GENERIC_BLOOD_PRESSURE);
    ble.accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LOCAL_NAME, (uint8_t *)DEVICE_NAME, sizeof(DEVICE_NAME));
    ble.setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED);
    ble.setAdvertisingInterval(1000);
    ble.startAdvertising();
 
    while (1) {
        // check for trigger from periodicCallback()
        if (triggerSensorPolling && ble.getGapState().connected) {
            triggerSensorPolling = false;
 
            // Do blocking calls or whatever is necessary for sensor polling.
            // In our case, we simply update the HRM measurement. 
            SystolicValue++;
            DiastolicValue++;
            MeanArterialValue++;
            
            if (SystolicValue == 140.0f) {
                SystolicValue = 90.0f;
            }
            if (DiastolicValue == 90.0f) {
                DiastolicValue = 50.0f;
            }
            if (MeanArterialValue == 105.0f) {
                MeanArterialValue = 70.0f;
            }
            // update Blood Pressure 
            BloPressureService.updateBloodPressureMeasurement(SystolicValue, DiastolicValue, MeanArterialValue);
        } else {
            ble.waitForEvent(); // low power wait for event
        }
    }
}