I am trying to calculate my Heart Rate using a PPG/ECG sensor (I am using an AFE49I30 sensor) using the Xamarin form Application.
- I have one Bluetooth device and the Bluetooth device is connected to the Xamarin form Application using Plugin.BLE package.
- After the connection, I am getting all services and service characteristics of the Bluetooth device.
- After getting the characteristics of PPG/ECG. I am getting a byte array of PPG/ECG. Now, what can I do to get the Heart Rate count from this byte array?
Below Shown some screenshots of my code to get a bytes array of my Heart rate.
- PPG getting bytes array data using this code:
public async void GetPPGLiveData() { if (App.device != null) { var temp = App.DeviceDetailsModel.FirstOrDefault(a => a.DeviceService.Id.StartsWith("00005c00")); var PPGservices = await App.device.GetServiceAsync(new Guid(temp.DeviceService.Id)); if (PPGservices != null) { var PPGcharacter = temp.DeviceServiceCharacs.FirstOrDefault(a => a.Id.StartsWith("00005c02")); var PPGList = await PPGservices.GetCharacteristicAsync(new Guid(PPGcharacter.Id)); PPGList.ValueUpdated += (o, args) => { var receivedBytes = args.Characteristic.Value; Xamarin.Essentials.MainThread.BeginInvokeOnMainThread(async () => { //Need to write some Heart Rate calculation Logic. }); }; await PPGList.StartUpdatesAsync(); } } }
- ECG getting bytes array data using this code:
public async void GetECGLiveData()
{
if (App.device != null)
{
var temp = App.DeviceDetailsModel.FirstOrDefault(a => a.DeviceService.Id.StartsWith("00005c00"));
var ECGservices = await App.device.GetServiceAsync(new Guid(temp.DeviceService.Id));
if (ECGservices != null)
{
var ECGcharacter = temp.DeviceServiceCharacs.FirstOrDefault(a => a.Id.StartsWith("00005c01"));
var ECGList = await ECGservices.GetCharacteristicAsync(new Guid(ECGcharacter.Id));
ECGList.ValueUpdated += (o, args) =>
{
var receivedBytes = args.Characteristic.Value;
Xamarin.Essentials.MainThread.InvokeOnMainThreadAsync(async () =>
{
//Need to Write Some calculation logic here.
});
};
await ECGList.StartUpdatesAsync();
}
}
}