Aaron Silva
/
HSP_RPC_GUI
publishing
Diff: HSP/Hsp_BLE/HspBLE.cpp
- Revision:
- 5:0fdc04a80278
- Parent:
- 4:f7d1e5d9c73e
- Child:
- 6:64cee3b9f02e
diff -r f7d1e5d9c73e -r 0fdc04a80278 HSP/Hsp_BLE/HspBLE.cpp --- a/HSP/Hsp_BLE/HspBLE.cpp Fri Mar 10 22:26:07 2017 +0000 +++ b/HSP/Hsp_BLE/HspBLE.cpp Wed Mar 22 19:28:49 2017 +0000 @@ -46,6 +46,8 @@ uint8_t HspBLE::dataCharUUID[] = {0xaa,0x8a,0x19,0x32,0xda,0x49,0x49,0xad,0x91,0xd8,0x80,0x08,0x32,0xe7,0xe9,0x40}; uint8_t HspBLE::commandCharUUID[] = {0x36,0xe5,0x5e,0x37,0x6b,0x5b,0x42,0x0b,0x91,0x07,0x0d,0x34,0xa0,0xe8,0x67,0x5a}; uint8_t HspBLE::ecgCharUUID[] = {0x62,0x1a,0x00,0xe3,0xb0,0x93,0x46,0xbf,0xaa,0xdc,0xab,0xe4,0xc6,0x48,0xc5,0x6a}; +uint8_t HspBLE::ecgTwoCharUUID[] = {0x62,0x1a,0x00,0xe3,0xb0,0x93,0x46,0xbf,0xaa,0xdc,0xab,0xe4,0xc6,0x48,0xc5,0x6b}; + /// define the BLE device name uint8_t HspBLE::deviceName[] = "MAXREFDES100"; @@ -97,10 +99,11 @@ bluetoothLE->addCharacteristic(new Characteristic(32 /* number of bytes */,dataCharUUID,GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE)); bluetoothLE->addCharacteristic(new Characteristic(1 /* number of bytes */,commandCharUUID,GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE)); bluetoothLE->addCharacteristic(new Characteristic(16 /* number of bytes */,ecgCharUUID,GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY)); + bluetoothLE->addCharacteristic(new Characteristic(16 /* number of bytes */,ecgTwoCharUUID,GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY)); bluetoothLE->initService(serialNumberPtr, deviceName, sizeof(deviceName),envServiceUUID); bluetoothLE->onDataWritten(&HspBLE::_onDataWritten); - ticker.attach(this, &HspBLE::tickerHandler, 0.125); + ticker.attach(this, &HspBLE::tickerHandler, 1); } void HspBLE::_onDataWritten(int index) { @@ -174,15 +177,15 @@ data[i] = bytePtr[i]; } break; case CHARACTERISTIC_ECG: { - int i; uint8_t *bytePtr; MAX30001::max30001_ecg ecgData; Peripherals::max30001()->max30001_ReadECGData(&ecgData); if (Peripherals::max30001()->max30001_status.bit.eint == 1 || Peripherals::max30001()->max30001_status.bit.pint == 1) { if(ecgData.etag != 0b110){ bytePtr = reinterpret_cast<uint8_t *>(&Peripherals::max30001()->max30001_ECG_FIFO_buffer); - for (i = 0; i < sizeof(Peripherals::max30001()->max30001_ECG_FIFO_buffer); i++) + for (int i = 0; i < sizeof(Peripherals::max30001()->max30001_ECG_FIFO_buffer) ; i++){ data[i] = bytePtr[i]; + } } } }break; @@ -194,6 +197,29 @@ /** * @brief Timer Callback that updates all sensor characteristic notifications */ +void HspBLE::ecgHandler(void) { + uint8_t *bytePtr; + uint8_t data[128]; +uint8_t tempData[16]; + + if (bluetoothLE->isConnected()) { + bytePtr = reinterpret_cast<uint8_t *>(&Peripherals::max30001()->max30001_ECG_FIFO_buffer); + for (int i = 0; i < sizeof(Peripherals::max30001()->max30001_ECG_FIFO_buffer); i++){ + data[i] = bytePtr[i]; + } + for(int i = 0; i < 8; i++) { + for(int j = 0; j < 16; j++) { + tempData[j] = data[(i*16)+j]; + } + bluetoothLE->notifyCharacteristic(CHARACTERISTIC_ECG, tempData); + } + } +} + + +/** +* @brief Timer Callback that updates all sensor characteristic notifications +*/ void HspBLE::tickerHandler(void) { uint8_t data[128]; if (bluetoothLE->isConnected()) { @@ -203,16 +229,22 @@ //bluetoothLE->notifyCharacteristic(CHARACTERISTIC_TEMP_BOTTOM, data); //pollSensor(CHARACTERISTIC_ACCELEROMETER, data); //bluetoothLE->notifyCharacteristic(CHARACTERISTIC_ACCELEROMETER, data); - //pollSensor(CHARACTERISTIC_HEARTRATE, data); -// bluetoothLE->notifyCharacteristic(CHARACTERISTIC_HEARTRATE, data); - pollSensor(CHARACTERISTIC_ECG, data); - for(int i = 0; i < 8; i++){ - uint8_t tempData[16]; - for(int j = 0; j < 16; j++){ - tempData[j] = data[(i*16)+j]; - } - bluetoothLE->notifyCharacteristic(CHARACTERISTIC_ECG, tempData); - } + pollSensor(CHARACTERISTIC_HEARTRATE, data); + bluetoothLE->notifyCharacteristic(CHARACTERISTIC_HEARTRATE, data); +// pollSensor(CHARACTERISTIC_ECG, data); +// uint8_t tempData[16]; +// for(int i = 0; i < 8; i++){ +// for(int j = 0; j < 16; j++){ +// tempData[j] = data[(i*16)+j]; +// } +// bluetoothLE->notifyCharacteristic(CHARACTERISTIC_ECG, tempData); +// } +// for(int i = 4; i < 8; i++){ +// for(int j = 0; j < 16; j++){ +// tempData[j] = data[(i*16)+j]; +// } +// bluetoothLE->notifyCharacteristic(CHARACTERISTIC_ECG_TWO, tempData); +// } //bluetoothLE->notifyCharacteristic(CHARACTERISTIC_ECG, data); //pollSensor(CHARACTERISTIC_PRESSURE, data); //bluetoothLE->notifyCharacteristic(CHARACTERISTIC_PRESSURE, data);