From b4aad8f5a9a55c2cee1e4b7db277d68978844ca7 Mon Sep 17 00:00:00 2001 From: MishalJasmine Date: Wed, 6 Nov 2024 16:29:51 +0530 Subject: [PATCH 01/10] changed to 8 bits shifting --- app/src/data_module.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/src/data_module.c b/app/src/data_module.c index 49ec4ae..e4d3453 100644 --- a/app/src/data_module.c +++ b/app/src/data_module.c @@ -406,12 +406,12 @@ void buffer_ecg_data_for_serial(int32_t *ecg_data_in, int ecg_len, int32_t *bioz { for (int i = 0; i < ecg_len; i++) { - ecg_serial_streaming[serial_ecg_counter++] = (int16_t)(ecg_data_in[i] >> 16); + ecg_serial_streaming[serial_ecg_counter++] = (int16_t)(ecg_data_in[i] >> 8); } for (int i = 0; i < bioz_len; i++) { - resp_serial_streaming[serial_bioz_counter++] = (int16_t)(bioz_data_in[i] >> 16); + resp_serial_streaming[serial_bioz_counter++] = (int16_t)(bioz_data_in[i] >> 8); } } else @@ -423,13 +423,13 @@ void buffer_ecg_data_for_serial(int32_t *ecg_data_in, int ecg_len, int32_t *bioz memset(resp_serial_streaming, 0, sizeof(resp_serial_streaming)); for (int i = 0; i < bioz_len; i++) { - resp_serial_streaming[serial_bioz_counter++] = (int16_t)(bioz_data_in[i] >> 16); + resp_serial_streaming[serial_bioz_counter++] = (int16_t)(bioz_data_in[i] >> 8); // resp_serial_streaming[serial_bioz_counter++] = (int16_t) 50; } for (int i = 0; i < ecg_len; i++) { - ecg_serial_streaming[serial_ecg_counter++] = (int16_t)(ecg_data_in[i] >> 16); + ecg_serial_streaming[serial_ecg_counter++] = (int16_t)(ecg_data_in[i] >> 8); } } } From 5c4b0386fa00ffeb98790af392e22ee56e15859e Mon Sep 17 00:00:00 2001 From: Ashwin K Whitchurch Date: Wed, 6 Nov 2024 17:02:26 +0530 Subject: [PATCH 02/10] MAX30001 driver change --- app/src/data_module.c | 27 +++++++++++------------- drivers/sensor/max30001/max30001_async.c | 4 ++-- 2 files changed, 14 insertions(+), 17 deletions(-) diff --git a/app/src/data_module.c b/app/src/data_module.c index e4d3453..ccb893d 100644 --- a/app/src/data_module.c +++ b/app/src/data_module.c @@ -137,9 +137,9 @@ void send_data_ov3_format() { uint8_t pkt_pos_counter = 0; - //struct hpi_ecg_bioz_sensor_data_t ecg_bioz_sensor_sample; - //struct hpi_ppg_sensor_data_t ppg_sensor_sample; - //struct hpi_temp_sensor_data_t temp_sensor_sample; + // struct hpi_ecg_bioz_sensor_data_t ecg_bioz_sensor_sample; + // struct hpi_ppg_sensor_data_t ppg_sensor_sample; + // struct hpi_temp_sensor_data_t temp_sensor_sample; for (int i = 0; i < HPI_OV3_DATA_ECG_LEN; i++) { @@ -406,12 +406,12 @@ void buffer_ecg_data_for_serial(int32_t *ecg_data_in, int ecg_len, int32_t *bioz { for (int i = 0; i < ecg_len; i++) { - ecg_serial_streaming[serial_ecg_counter++] = (int16_t)(ecg_data_in[i] >> 8); + ecg_serial_streaming[serial_ecg_counter++] = (int16_t)(ecg_data_in[i] >> 4); } for (int i = 0; i < bioz_len; i++) { - resp_serial_streaming[serial_bioz_counter++] = (int16_t)(bioz_data_in[i] >> 8); + resp_serial_streaming[serial_bioz_counter++] = (int16_t)(bioz_data_in[i] >> 2); } } else @@ -421,15 +421,16 @@ void buffer_ecg_data_for_serial(int32_t *ecg_data_in, int ecg_len, int32_t *bioz serial_bioz_counter = 0; // memset(ecg_serial_streaming,0,sizeof(ecg_serial_streaming)); memset(resp_serial_streaming, 0, sizeof(resp_serial_streaming)); - for (int i = 0; i < bioz_len; i++) + + for (int i = 0; i < ecg_len; i++) { - resp_serial_streaming[serial_bioz_counter++] = (int16_t)(bioz_data_in[i] >> 8); - // resp_serial_streaming[serial_bioz_counter++] = (int16_t) 50; + ecg_serial_streaming[serial_ecg_counter++] = (int16_t)(ecg_data_in[i] >> 4); } - for (int i = 0; i < ecg_len; i++) + for (int i = 0; i < bioz_len; i++) { - ecg_serial_streaming[serial_ecg_counter++] = (int16_t)(ecg_data_in[i] >> 8); + resp_serial_streaming[serial_bioz_counter++] = (int16_t)(bioz_data_in[i] >> 2); + // resp_serial_streaming[serial_bioz_counter++] = (int16_t) 50; } } } @@ -519,7 +520,6 @@ void data_thread(void) rr_serial = globalRespirationRate; - // #ifdef CONFIG_BT if (settings_send_ble_enabled) { @@ -546,7 +546,6 @@ void data_thread(void) k_msgq_put(&q_plot_ecg_bioz, &ecg_bioz_sensor_sample, K_NO_WAIT); } #endif - } /* Get Sample from PPG sampling queue */ @@ -556,7 +555,7 @@ void data_thread(void) if (settings_send_usb_enabled) { buffer_ppg_data_for_serial(ppg_sensor_sample.ppg_red_samples, PPG_POINTS_PER_SAMPLE); - + // buffer_bioz_data_for_serial(ecg_bioz_sensor_sample.bioz_samples, ecg_bioz_sensor_sample.bioz_num_samples); } @@ -605,8 +604,6 @@ void data_thread(void) spo2_serial = m_spo2; } // #endif - - } if (validHeartRate) diff --git a/drivers/sensor/max30001/max30001_async.c b/drivers/sensor/max30001/max30001_async.c index a857246..a43570d 100644 --- a/drivers/sensor/max30001/max30001_async.c +++ b/drivers/sensor/max30001/max30001_async.c @@ -85,7 +85,7 @@ static int max30001_async_sample_fetch(const struct device *dev, uecgtemp = (uint32_t)(uecgtemp << 8); int32_t secgtemp = (int32_t)uecgtemp; - secgtemp = (int32_t)secgtemp >> 6; + secgtemp = (int32_t)secgtemp >> 14; ecg_samples[i] = (int32_t)(secgtemp); //((secgtemp*1000*1000)/2621440); // Convert to microvolts // printf("%d ", ecg_samples[i]); @@ -116,7 +116,7 @@ static int max30001_async_sample_fetch(const struct device *dev, u_bioz_temp = (uint32_t)(u_bioz_temp << 8); int32_t s_bioz_temp = (int32_t)u_bioz_temp; - s_bioz_temp = (int32_t)(s_bioz_temp >> 4); + s_bioz_temp = (int32_t)(s_bioz_temp >> 12); // printf("%d ", secgtemp); bioz_samples[i] = s_bioz_temp; From 469f39c487a5fe9188b7bd1ba1585d545e1318cb Mon Sep 17 00:00:00 2001 From: MishalJasmine Date: Wed, 6 Nov 2024 18:05:42 +0530 Subject: [PATCH 03/10] ECG and bioz changed to 32bit --- app/src/data_module.c | 51 +++++++++++++++---------------------------- 1 file changed, 18 insertions(+), 33 deletions(-) diff --git a/app/src/data_module.c b/app/src/data_module.c index ccb893d..aa03f0f 100644 --- a/app/src/data_module.c +++ b/app/src/data_module.c @@ -58,7 +58,7 @@ char DataPacket[DATA_LEN]; const uint8_t DataPacketHeader[5] = {CES_CMDIF_PKT_START_1, CES_CMDIF_PKT_START_2, DATA_LEN, 0, CES_CMDIF_TYPE_DATA}; const uint8_t DataPacketFooter[2] = {0, CES_CMDIF_PKT_STOP}; -#define HPI_OV3_DATA_LEN 45 +#define HPI_OV3_DATA_LEN 69 #define HPI_OV3_DATA_ECG_LEN 8 #define HPI_OV3_DATA_BIOZ_LEN 4 #define HPI_OV3_DATA_RED_LEN 8 @@ -97,7 +97,7 @@ int16_t resWaveBuff, respFilterout; long timeElapsed = 0; int32_t ecg_sample_buffer[64]; -int16_t ecg_serial_streaming[8]; +int32_t ecg_serial_streaming[8]; int sample_buffer_count = 0; int16_t ppg_sample_buffer[64]; @@ -105,7 +105,7 @@ int16_t ppg_serial_streaming[8]; int ppg_sample_buffer_count = 0; int32_t resp_sample_buffer[64]; -int16_t resp_serial_streaming[4]; +int32_t resp_serial_streaming[4]; int resp_sample_buffer_count = 0; // Externs @@ -145,12 +145,16 @@ void send_data_ov3_format() { hpi_ov3_data[pkt_pos_counter++] = (uint8_t)ecg_serial_streaming[i]; hpi_ov3_data[pkt_pos_counter++] = (uint8_t)(ecg_serial_streaming[i] >> 8); + hpi_ov3_data[pkt_pos_counter++] = (uint8_t)(ecg_serial_streaming[i] >> 16); + hpi_ov3_data[pkt_pos_counter++] = (uint8_t)(ecg_serial_streaming[i] >> 24); } for (int i = 0; i < HPI_OV3_DATA_BIOZ_LEN; i++) { hpi_ov3_data[pkt_pos_counter++] = (uint8_t)resp_serial_streaming[i]; hpi_ov3_data[pkt_pos_counter++] = (uint8_t)(resp_serial_streaming[i] >> 8); + hpi_ov3_data[pkt_pos_counter++] = (uint8_t)(resp_serial_streaming[i] >> 16); + hpi_ov3_data[pkt_pos_counter++] = (uint8_t)(resp_serial_streaming[i] >> 24); } for (int i = 0; i < HPI_OV3_DATA_RED_LEN; i++) @@ -358,26 +362,6 @@ void record_session_add_ecg_point(int32_t *ecg_samples, uint8_t ecg_len, int32_t } } -void buffer_bioz_data_for_serial(int32_t *bioz_data_in, int bioz_len) -{ - if (serial_bioz_counter < HPI_OV3_DATA_BIOZ_LEN) - { - for (int i = 0; i < bioz_len; i++) - { - resp_serial_streaming[serial_bioz_counter++] = (int16_t)0; - // resp_serial_streaming[serial_bioz_counter++] = (int16_t) 50; - } - } - else - { - serial_bioz_counter = 0; - for (int i = 0; i < bioz_len; i++) - { - resp_serial_streaming[serial_bioz_counter++] = (int16_t)bioz_data_in[i] >> 8; - // resp_serial_streaming[serial_bioz_counter++] = (int16_t) 50; - } - } -} void buffer_ppg_data_for_serial(int16_t *ppg_data_in, int ppg_len) { @@ -406,12 +390,12 @@ void buffer_ecg_data_for_serial(int32_t *ecg_data_in, int ecg_len, int32_t *bioz { for (int i = 0; i < ecg_len; i++) { - ecg_serial_streaming[serial_ecg_counter++] = (int16_t)(ecg_data_in[i] >> 4); + ecg_serial_streaming[serial_ecg_counter++] = ecg_data_in[i]; } for (int i = 0; i < bioz_len; i++) { - resp_serial_streaming[serial_bioz_counter++] = (int16_t)(bioz_data_in[i] >> 2); + resp_serial_streaming[serial_bioz_counter++] = bioz_data_in[i]; } } else @@ -424,13 +408,12 @@ void buffer_ecg_data_for_serial(int32_t *ecg_data_in, int ecg_len, int32_t *bioz for (int i = 0; i < ecg_len; i++) { - ecg_serial_streaming[serial_ecg_counter++] = (int16_t)(ecg_data_in[i] >> 4); + ecg_serial_streaming[serial_ecg_counter++] = ecg_data_in[i]; } for (int i = 0; i < bioz_len; i++) { - resp_serial_streaming[serial_bioz_counter++] = (int16_t)(bioz_data_in[i] >> 2); - // resp_serial_streaming[serial_bioz_counter++] = (int16_t) 50; + resp_serial_streaming[serial_bioz_counter++] = bioz_data_in[i]; } } } @@ -518,8 +501,6 @@ void data_thread(void) resp_process_sample(resp_i16_buf, resp_i16_filt_out); resp_algo_process(resp_i16_filt_out, &globalRespirationRate); - rr_serial = globalRespirationRate; - // #ifdef CONFIG_BT if (settings_send_ble_enabled) { @@ -532,6 +513,8 @@ void data_thread(void) if (settings_send_usb_enabled) { buffer_ecg_data_for_serial(ecg_bioz_sensor_sample.ecg_samples, ecg_bioz_sensor_sample.ecg_num_samples, ecg_bioz_sensor_sample.bioz_samples, ecg_bioz_sensor_sample.bioz_num_samples); + hr_serial = ecg_bioz_sensor_sample.hr; + rr_serial = globalRespirationRate; } if (settings_log_data_enabled && sd_card_present) @@ -556,7 +539,6 @@ void data_thread(void) { buffer_ppg_data_for_serial(ppg_sensor_sample.ppg_red_samples, PPG_POINTS_PER_SAMPLE); - // buffer_bioz_data_for_serial(ecg_bioz_sensor_sample.bioz_samples, ecg_bioz_sensor_sample.bioz_num_samples); } // #ifdef CONFIG_BT @@ -611,7 +593,7 @@ void data_thread(void) #ifdef CONFIG_HEALTHYPI_DISPLAY_ENABLED hpi_scr_home_update_pr(m_hr); #endif - hr_serial = m_hr; + } for (int i = FreqS; i < BUFFER_SIZE; i++) @@ -622,7 +604,10 @@ void data_thread(void) } } - temp_serial = hpi_hw_read_temp(); + if (settings_send_usb_enabled) + { + temp_serial = hpi_hw_read_temp(); + } k_sleep(K_MSEC(1)); } From 153f14deb41935b639ed2df71c0d0e442730b230 Mon Sep 17 00:00:00 2001 From: MishalJasmine Date: Thu, 7 Nov 2024 15:44:42 +0530 Subject: [PATCH 04/10] ppg and ecg streamed as separate packet --- app/src/data_module.c | 107 +++++++++++++++++++++++------------------- 1 file changed, 60 insertions(+), 47 deletions(-) diff --git a/app/src/data_module.c b/app/src/data_module.c index aa03f0f..8c0d9d1 100644 --- a/app/src/data_module.c +++ b/app/src/data_module.c @@ -33,9 +33,9 @@ LOG_MODULE_REGISTER(data_module, CONFIG_SENSOR_LOG_LEVEL); // ProtoCentral data formats #define CES_CMDIF_PKT_START_1 0x0A #define CES_CMDIF_PKT_START_2 0xFA -#define CES_CMDIF_TYPE_DATA 0x02 +#define CES_CMDIF_TYPE_ECG_BIOZ_DATA 0x03 +#define CES_CMDIF_TYPE_PPG_DATA 0x04 #define CES_CMDIF_PKT_STOP 0x0B -#define DATA_LEN 22 #define SAMPLING_FREQ 104 // in Hz. #define TEMP_CALC_BUFFER_LENGTH 125 @@ -53,21 +53,20 @@ enum hpi5_data_format } hpi5_data_format_t; -char DataPacket[DATA_LEN]; -const uint8_t DataPacketHeader[5] = {CES_CMDIF_PKT_START_1, CES_CMDIF_PKT_START_2, DATA_LEN, 0, CES_CMDIF_TYPE_DATA}; -const uint8_t DataPacketFooter[2] = {0, CES_CMDIF_PKT_STOP}; - -#define HPI_OV3_DATA_LEN 69 +#define HPI_OV3_DATA_ECG_BIOZ_LEN 50 +#define HPI_OV3_DATA_PPG_LEN 19 #define HPI_OV3_DATA_ECG_LEN 8 #define HPI_OV3_DATA_BIOZ_LEN 4 #define HPI_OV3_DATA_RED_LEN 8 #define HPI_OV3_DATA_IR_LEN 8 -const uint8_t hpi_ov3_packet_header[5] = {CES_CMDIF_PKT_START_1, CES_CMDIF_PKT_START_2, HPI_OV3_DATA_LEN, 0, CES_CMDIF_TYPE_DATA}; +const uint8_t hpi_ov3_ecg_bioz_packet_header[5] = {CES_CMDIF_PKT_START_1, CES_CMDIF_PKT_START_2, HPI_OV3_DATA_ECG_BIOZ_LEN, 0, CES_CMDIF_TYPE_ECG_BIOZ_DATA}; +const uint8_t hpi_ov3_ppg_packet_header[5] = {CES_CMDIF_PKT_START_1, CES_CMDIF_PKT_START_2, HPI_OV3_DATA_PPG_LEN, 0, CES_CMDIF_TYPE_PPG_DATA}; const uint8_t hpi_ov3_packet_footer[2] = {0, CES_CMDIF_PKT_STOP}; -uint8_t hpi_ov3_data[HPI_OV3_DATA_LEN]; +uint8_t hpi_ov3_ecg_bioz_data[HPI_OV3_DATA_ECG_BIOZ_LEN]; +uint8_t hpi_ov3_ppg_data[HPI_OV3_DATA_PPG_LEN]; static bool settings_send_usb_enabled = true; static bool settings_send_ble_enabled = true; @@ -133,46 +132,64 @@ int16_t hr_serial; int16_t rr_serial; int16_t temp_serial; -void send_data_ov3_format() +void send_ppg_data_ov3_format() { - uint8_t pkt_pos_counter = 0; + uint8_t pkt_ppg_pos_counter = 0; + + for (int i = 0; i < HPI_OV3_DATA_IR_LEN; i++) + { + hpi_ov3_ppg_data[pkt_ppg_pos_counter++] = (uint8_t)ppg_serial_streaming[i]; + hpi_ov3_ppg_data[pkt_ppg_pos_counter++] = (uint8_t)(ppg_serial_streaming[i] >> 8); + } + + hpi_ov3_ppg_data[pkt_ppg_pos_counter++] = (uint8_t)spo2_serial; - // struct hpi_ecg_bioz_sensor_data_t ecg_bioz_sensor_sample; - // struct hpi_ppg_sensor_data_t ppg_sensor_sample; - // struct hpi_temp_sensor_data_t temp_sensor_sample; + hpi_ov3_ppg_data[pkt_ppg_pos_counter++] = (uint8_t)(temp_serial >> 8); + hpi_ov3_ppg_data[pkt_ppg_pos_counter++] = (uint8_t)(temp_serial >> 8); - for (int i = 0; i < HPI_OV3_DATA_ECG_LEN; i++) + if (settings_send_usb_enabled) { - hpi_ov3_data[pkt_pos_counter++] = (uint8_t)ecg_serial_streaming[i]; - hpi_ov3_data[pkt_pos_counter++] = (uint8_t)(ecg_serial_streaming[i] >> 8); - hpi_ov3_data[pkt_pos_counter++] = (uint8_t)(ecg_serial_streaming[i] >> 16); - hpi_ov3_data[pkt_pos_counter++] = (uint8_t)(ecg_serial_streaming[i] >> 24); + send_usb_cdc(hpi_ov3_ppg_packet_header, 5); + send_usb_cdc(hpi_ov3_ppg_data, pkt_ppg_pos_counter); + send_usb_cdc(hpi_ov3_packet_footer, 2); } - for (int i = 0; i < HPI_OV3_DATA_BIOZ_LEN; i++) + if (settings_send_rpi_uart_enabled) { - hpi_ov3_data[pkt_pos_counter++] = (uint8_t)resp_serial_streaming[i]; - hpi_ov3_data[pkt_pos_counter++] = (uint8_t)(resp_serial_streaming[i] >> 8); - hpi_ov3_data[pkt_pos_counter++] = (uint8_t)(resp_serial_streaming[i] >> 16); - hpi_ov3_data[pkt_pos_counter++] = (uint8_t)(resp_serial_streaming[i] >> 24); + // send_rpi_uart(DataPacketHeader, 5); + // send_rpi_uart(DataPacket, DATA_LEN); + // send_rpi_uart(DataPacketFooter, 2); } - for (int i = 0; i < HPI_OV3_DATA_RED_LEN; i++) +} + +void send_ecg_bioz_data_ov3_format(int32_t *ecg_data, int32_t ecg_sample_count, int32_t *bioz_samples,int32_t bioz_sample_count, uint8_t hr,uint8_t rr) +{ + uint8_t pkt_ecg_bioz_pos_counter = 0; + + for (int i = 0; i < ecg_sample_count; i++) + { + hpi_ov3_ecg_bioz_data[pkt_ecg_bioz_pos_counter++] = (uint8_t)ecg_data[i]; + hpi_ov3_ecg_bioz_data[pkt_ecg_bioz_pos_counter++] = (uint8_t)(ecg_data[i] >> 8); + hpi_ov3_ecg_bioz_data[pkt_ecg_bioz_pos_counter++] = (uint8_t)(ecg_data[i] >> 16); + hpi_ov3_ecg_bioz_data[pkt_ecg_bioz_pos_counter++] = (uint8_t)(ecg_data[i] >> 24); + } + + for (int i = 0; i < bioz_sample_count; i++) { - hpi_ov3_data[pkt_pos_counter++] = (uint8_t)ppg_serial_streaming[i]; - hpi_ov3_data[pkt_pos_counter++] = (uint8_t)(ppg_serial_streaming[i] >> 8); + hpi_ov3_ecg_bioz_data[pkt_ecg_bioz_pos_counter++] = (uint8_t)bioz_samples[i]; + hpi_ov3_ecg_bioz_data[pkt_ecg_bioz_pos_counter++] = (uint8_t)(bioz_samples[i] >> 8); + hpi_ov3_ecg_bioz_data[pkt_ecg_bioz_pos_counter++] = (uint8_t)(bioz_samples[i] >> 16); + hpi_ov3_ecg_bioz_data[pkt_ecg_bioz_pos_counter++] = (uint8_t)(bioz_samples[i] >> 24); } - hpi_ov3_data[pkt_pos_counter++] = (uint8_t)temp_serial; - hpi_ov3_data[pkt_pos_counter++] = (uint8_t)(temp_serial >> 8); - hpi_ov3_data[pkt_pos_counter++] = spo2_serial; - hpi_ov3_data[pkt_pos_counter++] = hr_serial; - hpi_ov3_data[pkt_pos_counter++] = rr_serial; + hpi_ov3_ecg_bioz_data[pkt_ecg_bioz_pos_counter++] = hr_serial; + hpi_ov3_ecg_bioz_data[pkt_ecg_bioz_pos_counter++] = rr_serial; if (settings_send_usb_enabled) { - send_usb_cdc(hpi_ov3_packet_header, 5); - send_usb_cdc(hpi_ov3_data, pkt_pos_counter); + send_usb_cdc(hpi_ov3_ecg_bioz_packet_header, 5); + send_usb_cdc(hpi_ov3_ecg_bioz_data, pkt_ecg_bioz_pos_counter); send_usb_cdc(hpi_ov3_packet_footer, 2); } @@ -184,7 +201,7 @@ void send_data_ov3_format() } } -void sendData(int32_t ecg_sample, int32_t bioz_samples, int32_t raw_red, int32_t raw_ir, int32_t temp, uint8_t hr, +/*void sendData(int32_t ecg_sample, int32_t bioz_samples, int32_t raw_red, int32_t raw_ir, int32_t temp, uint8_t hr, uint8_t rr, uint8_t spo2, bool _bioZSkipSample) { @@ -237,7 +254,7 @@ void sendData(int32_t ecg_sample, int32_t bioz_samples, int32_t raw_red, int32_t // send_rpi_uart(DataPacket, DATA_LEN); // send_rpi_uart(DataPacketFooter, 2); } -} +}*/ void send_data_text(int32_t ecg_sample, int32_t bioz_samples, int32_t raw_red) { @@ -374,9 +391,9 @@ void buffer_ppg_data_for_serial(int16_t *ppg_data_in, int ppg_len) } else { - send_data_ov3_format(); + send_ppg_data_ov3_format(); serial_ppg_counter = 0; - // memset(ppg_serial_streaming,0,sizeof(ppg_serial_streaming)); + memset(ppg_serial_streaming,0,sizeof(ppg_serial_streaming)); for (int i = 0; i < ppg_len; i++) { ppg_serial_streaming[serial_ppg_counter++] = ppg_data_in[i]; @@ -403,8 +420,8 @@ void buffer_ecg_data_for_serial(int32_t *ecg_data_in, int ecg_len, int32_t *bioz // send_data_ov3_format(); serial_ecg_counter = 0; serial_bioz_counter = 0; - // memset(ecg_serial_streaming,0,sizeof(ecg_serial_streaming)); - memset(resp_serial_streaming, 0, sizeof(resp_serial_streaming)); + //memset(ecg_serial_streaming,0,sizeof(ecg_serial_streaming)); + //memset(resp_serial_streaming, 0, sizeof(resp_serial_streaming)); for (int i = 0; i < ecg_len; i++) { @@ -512,9 +529,9 @@ void data_thread(void) if (settings_send_usb_enabled) { - buffer_ecg_data_for_serial(ecg_bioz_sensor_sample.ecg_samples, ecg_bioz_sensor_sample.ecg_num_samples, ecg_bioz_sensor_sample.bioz_samples, ecg_bioz_sensor_sample.bioz_num_samples); hr_serial = ecg_bioz_sensor_sample.hr; rr_serial = globalRespirationRate; + send_ecg_bioz_data_ov3_format(ecg_bioz_sensor_sample.ecg_samples, ecg_bioz_sensor_sample.ecg_num_samples, ecg_bioz_sensor_sample.bioz_samples, ecg_bioz_sensor_sample.bioz_num_samples,hr_serial,rr_serial); } if (settings_log_data_enabled && sd_card_present) @@ -534,11 +551,10 @@ void data_thread(void) /* Get Sample from PPG sampling queue */ if (k_msgq_get(&q_ppg_sample, &ppg_sensor_sample, K_NO_WAIT) == 0) { - if (settings_send_usb_enabled) { + temp_serial = hpi_hw_read_temp(); buffer_ppg_data_for_serial(ppg_sensor_sample.ppg_red_samples, PPG_POINTS_PER_SAMPLE); - } // #ifdef CONFIG_BT @@ -604,10 +620,7 @@ void data_thread(void) } } - if (settings_send_usb_enabled) - { - temp_serial = hpi_hw_read_temp(); - } + k_sleep(K_MSEC(1)); } From 571d9c046ec62c084e72a970fb1246bc39a57b58 Mon Sep 17 00:00:00 2001 From: MishalJasmine Date: Fri, 8 Nov 2024 15:34:09 +0530 Subject: [PATCH 05/10] DC component of respiration signal removed and sent to display --- app/src/resp_process.c | 12 ++++++++++++ app/src/resp_process.h | 1 + app/src/ui/screens/scr_resp.c | 6 +++++- 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/app/src/resp_process.c b/app/src/resp_process.c index 5d49ede..d5287b3 100644 --- a/app/src/resp_process.c +++ b/app/src/resp_process.c @@ -62,6 +62,18 @@ void resp_filt(int16_t *RESP_WorkingBuff, int16_t *CoeffBuf, int16_t *FilterOut) *FilterOut = (int16_t)(acc >> 15); } +void resp_remove_dc_component(int32_t CurrAqsSample, int32_t respFiltered) +{ + int32_t temp1; //, RESPData; + int32_t RESPData; + + temp1 = NRCOEFF * Pvev_DC_Sample; + Pvev_DC_Sample = (CurrAqsSample - Pvev_Sample) + temp1; + Pvev_Sample = CurrAqsSample; + RESPData = (int32_t)Pvev_DC_Sample; + respFiltered = RESPData; +} + void resp_process_sample(int16_t *CurrAqsSample, int16_t *respFiltered) { static uint16_t bufStart = 0, bufCur = FILTERORDER - 1; diff --git a/app/src/resp_process.h b/app/src/resp_process.h index 13908cc..0d2b298 100644 --- a/app/src/resp_process.h +++ b/app/src/resp_process.h @@ -4,3 +4,4 @@ void resp_filt(int16_t * RESP_WorkingBuff, int16_t * CoeffBuf, int16_t* FilterOu void resp_process_sample(int16_t *CurrAqsSample, int16_t *respFiltered); void resp_algo_process(int16_t *CurrSample,volatile uint8_t *RespirationRate); void resp_rate_detect(int16_t Resp_wave,volatile uint8_t *RespirationRate); +void resp_remove_dc_component(int32_t CurrAqsSample, int32_t respFiltered); diff --git a/app/src/ui/screens/scr_resp.c b/app/src/ui/screens/scr_resp.c index ee74f8b..51361cd 100644 --- a/app/src/ui/screens/scr_resp.c +++ b/app/src/ui/screens/scr_resp.c @@ -9,6 +9,7 @@ #include "display_module.h" #include "sampling_module.h" #include "data_module.h" +#include "resp_process.h" static lv_obj_t *scr_resp; @@ -89,7 +90,10 @@ void hpi_resp_disp_draw_plot_resp(int32_t *data_resp, int num_samples, bool resp { for (int i = 0; i < num_samples; i++) { - int32_t data_resp_i = ((data_resp[i])); // / 10066); // in mV// (data_resp[i]); + + int32_t resp_i16_filt_out; + resp_remove_dc_component(data_resp[i], resp_i16_filt_out); + int32_t data_resp_i = resp_i16_filt_out; // / 10066); // in mV// (data_resp[i]); /* 2^19 524288 BIOZ GAIN 40 V/V CG_MAG 48 uA From 8d2fd3227ba778685229ccd7b5853ef44a1803c0 Mon Sep 17 00:00:00 2001 From: Ashwin K Whitchurch Date: Fri, 8 Nov 2024 17:38:52 +0530 Subject: [PATCH 06/10] Change PPG sampling to single sample --- app/src/ble_module.c | 23 ++++--------- app/src/ble_module.h | 2 +- app/src/data_module.c | 37 ++++++++------------ app/src/display/display_module.c | 2 +- app/src/display/display_module.h | 2 +- app/src/sampling_module.c | 47 ++++++-------------------- app/src/sampling_module.h | 6 ++-- app/src/ui/screens/scr_ppg.c | 2 +- drivers/sensor/afe4400/afe4400.c | 8 ++--- drivers/sensor/afe4400/afe4400.h | 8 ++--- drivers/sensor/afe4400/afe4400_async.c | 14 ++++---- 11 files changed, 53 insertions(+), 98 deletions(-) diff --git a/app/src/ble_module.c b/app/src/ble_module.c index df2f081..09a871a 100644 --- a/app/src/ble_module.c +++ b/app/src/ble_module.c @@ -36,7 +36,6 @@ extern struct k_msgq q_cmd_msg; #define CMD_RX_CHARACTERISTIC_UUID 0xdc, 0xad, 0x7f, 0xc4, 0x23, 0x90, 0x4d, 0xd4, \ 0x96, 0x8d, 0x0f, 0x97, 0x27, 0x15, 0xbf, 0x01 - #define HPI_SPO2_SERVICE BT_UUID_DECLARE_16(BT_UUID_POS_VAL) #define HPI_SPO2_CHAR BT_UUID_DECLARE_16(BT_UUID_GATT_PLX_SCM_VAL) @@ -64,7 +63,6 @@ extern struct k_msgq q_cmd_msg; #define CMD_SERVICE_UUID 0xdc, 0xad, 0x7f, 0xc4, 0x23, 0x90, 0x4d, 0xd4, \ 0x96, 0x8d, 0x0f, 0x97, 0x92, 0x74, 0xbf, 0x01 - #define CMD_TX_CHARACTERISTIC_UUID 0xdc, 0xad, 0x7f, 0xc4, 0x23, 0x90, 0x4d, 0xd4, \ 0x96, 0x8d, 0x0f, 0x97, 0x28, 0x15, 0xbf, 0x01 @@ -127,7 +125,7 @@ static void cmd_on_cccd_changed(const struct bt_gatt_attr *attr, uint16_t value) } } -static ssize_t on_receive_cmd(struct bt_conn *conn, const struct bt_gatt_attr *attr,const void *buf,uint16_t len,uint16_t offset,uint8_t flags) +static ssize_t on_receive_cmd(struct bt_conn *conn, const struct bt_gatt_attr *attr, const void *buf, uint16_t len, uint16_t offset, uint8_t flags) { const uint8_t *buffer = buf; @@ -150,7 +148,6 @@ static ssize_t on_receive_cmd(struct bt_conn *conn, const struct bt_gatt_attr *a return len; } - static const struct bt_data ad[] = { BT_DATA_BYTES(BT_DATA_FLAGS, (BT_LE_AD_GENERAL | BT_LE_AD_NO_BREDR)), BT_DATA_BYTES(BT_DATA_UUID16_ALL, @@ -267,17 +264,14 @@ void ble_bioz_notify(int32_t *resp_data, uint8_t len) bt_gatt_notify(NULL, &hpi_ecg_resp_service.attrs[4], &out_data, len * 4); } -void ble_ppg_notify(int16_t *ppg_data, uint8_t len) +void ble_ppg_notify(int16_t ppg_data) { uint8_t out_data[128]; - for (int i = 0; i < len; i++) - { - out_data[i * 2] = (uint8_t)ppg_data[i]; - out_data[i * 2 + 1] = (uint8_t)(ppg_data[i] >> 8); - } + out_data[0] = (uint8_t)ppg_data; + out_data[1] = (uint8_t)(ppg_data >> 8); - bt_gatt_notify(NULL, &hpi_ppg_resp_service.attrs[1], &out_data, len * 2); + bt_gatt_notify(NULL, &hpi_ppg_resp_service.attrs[1], &out_data, 2); } void ble_temp_notify(int16_t temp_val) @@ -442,14 +436,11 @@ void ble_module_init() // bt_conn_auth_cb_register(&auth_cb_display); } - void healthypi5_service_send_data(const uint8_t *data, uint16_t len) { const struct bt_gatt_attr *attr = &hpi_cmd_service.attrs[4]; - //printk("Sending response %d \n", data); + // printk("Sending response %d \n", data); bt_gatt_notify(NULL, attr, data, len); - //printk("Response sent\n"); + // printk("Response sent\n"); } - - diff --git a/app/src/ble_module.h b/app/src/ble_module.h index 410e60f..3746f0a 100644 --- a/app/src/ble_module.h +++ b/app/src/ble_module.h @@ -9,5 +9,5 @@ void ble_hrs_notify(uint16_t hr_val); void ble_resp_rate_notify(uint16_t resp_rate); void ble_ecg_notify(int32_t *ecg_data, uint8_t len); -void ble_ppg_notify(int16_t *ppg_data, uint8_t len); +void ble_ppg_notify(int16_t ppg_data); void ble_bioz_notify(int32_t *resp_data, uint8_t len); diff --git a/app/src/data_module.c b/app/src/data_module.c index 8c0d9d1..c567f6b 100644 --- a/app/src/data_module.c +++ b/app/src/data_module.c @@ -53,7 +53,6 @@ enum hpi5_data_format } hpi5_data_format_t; - #define HPI_OV3_DATA_ECG_BIOZ_LEN 50 #define HPI_OV3_DATA_PPG_LEN 19 #define HPI_OV3_DATA_ECG_LEN 8 @@ -160,10 +159,9 @@ void send_ppg_data_ov3_format() // send_rpi_uart(DataPacket, DATA_LEN); // send_rpi_uart(DataPacketFooter, 2); } - } -void send_ecg_bioz_data_ov3_format(int32_t *ecg_data, int32_t ecg_sample_count, int32_t *bioz_samples,int32_t bioz_sample_count, uint8_t hr,uint8_t rr) +void send_ecg_bioz_data_ov3_format(int32_t *ecg_data, int32_t ecg_sample_count, int32_t *bioz_samples, int32_t bioz_sample_count, uint8_t hr, uint8_t rr) { uint8_t pkt_ecg_bioz_pos_counter = 0; @@ -379,7 +377,6 @@ void record_session_add_ecg_point(int32_t *ecg_samples, uint8_t ecg_len, int32_t } } - void buffer_ppg_data_for_serial(int16_t *ppg_data_in, int ppg_len) { if (serial_ppg_counter < HPI_OV3_DATA_IR_LEN) @@ -393,7 +390,7 @@ void buffer_ppg_data_for_serial(int16_t *ppg_data_in, int ppg_len) { send_ppg_data_ov3_format(); serial_ppg_counter = 0; - memset(ppg_serial_streaming,0,sizeof(ppg_serial_streaming)); + memset(ppg_serial_streaming, 0, sizeof(ppg_serial_streaming)); for (int i = 0; i < ppg_len; i++) { ppg_serial_streaming[serial_ppg_counter++] = ppg_data_in[i]; @@ -420,8 +417,8 @@ void buffer_ecg_data_for_serial(int32_t *ecg_data_in, int ecg_len, int32_t *bioz // send_data_ov3_format(); serial_ecg_counter = 0; serial_bioz_counter = 0; - //memset(ecg_serial_streaming,0,sizeof(ecg_serial_streaming)); - //memset(resp_serial_streaming, 0, sizeof(resp_serial_streaming)); + // memset(ecg_serial_streaming,0,sizeof(ecg_serial_streaming)); + // memset(resp_serial_streaming, 0, sizeof(resp_serial_streaming)); for (int i = 0; i < ecg_len; i++) { @@ -477,13 +474,10 @@ void data_thread(void) { if (k_msgq_get(&q_ppg_sample, &ppg_sensor_sample, K_FOREVER) == 0) { - // printk("PPG %d\n",ppg_sensor_sample.ppg_num_samples); - for (int i = 0; i < ppg_sensor_sample.ppg_num_samples; i++) - { - irBuffer[init_buffer_count] = ppg_sensor_sample.ppg_ir_samples[i]; - redBuffer[init_buffer_count] = ppg_sensor_sample.ppg_red_samples[i]; - init_buffer_count++; - } + + irBuffer[init_buffer_count] = ppg_sensor_sample.ppg_ir_sample; + redBuffer[init_buffer_count] = ppg_sensor_sample.ppg_red_sample; + init_buffer_count++; } } @@ -531,7 +525,7 @@ void data_thread(void) { hr_serial = ecg_bioz_sensor_sample.hr; rr_serial = globalRespirationRate; - send_ecg_bioz_data_ov3_format(ecg_bioz_sensor_sample.ecg_samples, ecg_bioz_sensor_sample.ecg_num_samples, ecg_bioz_sensor_sample.bioz_samples, ecg_bioz_sensor_sample.bioz_num_samples,hr_serial,rr_serial); + send_ecg_bioz_data_ov3_format(ecg_bioz_sensor_sample.ecg_samples, ecg_bioz_sensor_sample.ecg_num_samples, ecg_bioz_sensor_sample.bioz_samples, ecg_bioz_sensor_sample.bioz_num_samples, hr_serial, rr_serial); } if (settings_log_data_enabled && sd_card_present) @@ -554,13 +548,13 @@ void data_thread(void) if (settings_send_usb_enabled) { temp_serial = hpi_hw_read_temp(); - buffer_ppg_data_for_serial(ppg_sensor_sample.ppg_red_samples, PPG_POINTS_PER_SAMPLE); + buffer_ppg_data_for_serial(ppg_sensor_sample.ppg_red_sample); } // #ifdef CONFIG_BT if (settings_send_ble_enabled) { - ble_ppg_notify(ppg_sensor_sample.ppg_red_samples, PPG_POINTS_PER_SAMPLE); + ble_ppg_notify(ppg_sensor_sample.ppg_red_sample); } // #endif @@ -573,14 +567,14 @@ void data_thread(void) if (settings_log_data_enabled && sd_card_present) { - record_session_add_ppg_point(ppg_sensor_sample.ppg_ir_samples, PPG_POINTS_PER_SAMPLE); + record_session_add_ppg_point(ppg_sensor_sample.ppg_ir_sample); } // Buffer the PPG data for SPO2 calculation if (spo2_time_count < FreqS) { - irBuffer[BUFFER_SIZE - FreqS + spo2_time_count] = ppg_sensor_sample.ppg_ir_samples[0]; - redBuffer[BUFFER_SIZE - FreqS + spo2_time_count] = ppg_sensor_sample.ppg_red_samples[0]; + irBuffer[BUFFER_SIZE - FreqS + spo2_time_count] = ppg_sensor_sample.ppg_ir_sample; + redBuffer[BUFFER_SIZE - FreqS + spo2_time_count] = ppg_sensor_sample.ppg_red_sample; spo2_time_count++; } @@ -609,7 +603,6 @@ void data_thread(void) #ifdef CONFIG_HEALTHYPI_DISPLAY_ENABLED hpi_scr_home_update_pr(m_hr); #endif - } for (int i = FreqS; i < BUFFER_SIZE; i++) @@ -620,8 +613,6 @@ void data_thread(void) } } - - k_sleep(K_MSEC(1)); } } diff --git a/app/src/display/display_module.c b/app/src/display/display_module.c index e2cd8ff..fcfada4 100644 --- a/app/src/display/display_module.c +++ b/app/src/display/display_module.c @@ -584,7 +584,7 @@ void display_screens_thread(void) { if (curr_screen == SCR_PPG) { - hpi_ppg_disp_draw_plot_ppg(ppg_sensor_sample.ppg_red_samples, ppg_sensor_sample.ppg_ir_samples, ppg_sensor_sample.ppg_num_samples, ppg_sensor_sample.ppg_lead_off); + hpi_ppg_disp_draw_plot_ppg(ppg_sensor_sample.ppg_red_sample, ppg_sensor_sample.ppg_ir_sample, ppg_sensor_sample.ppg_lead_off); } } diff --git a/app/src/display/display_module.h b/app/src/display/display_module.h index dc57d12..4055c9e 100644 --- a/app/src/display/display_module.h +++ b/app/src/display/display_module.h @@ -65,7 +65,7 @@ void hpi_resp_disp_draw_plot_resp(int32_t *data_resp, int num_samples, bool resp // PPG Screen functions void draw_scr_ppg(enum scroll_dir m_scroll_dir); -void hpi_ppg_disp_draw_plot_ppg(int32_t *data_ppg_red, int32_t *data_ppg_ir, int num_samples, bool ppg_lead_off); +void hpi_ppg_disp_draw_plot_ppg(int32_t *data_ppg_red, int32_t *data_ppg_ir, bool ppg_lead_off); void hpi_scr_home_update_pr(int pr); //void draw_scr_chart_resp(void); diff --git a/app/src/sampling_module.c b/app/src/sampling_module.c index 8826245..46f9645 100644 --- a/app/src/sampling_module.c +++ b/app/src/sampling_module.c @@ -28,19 +28,19 @@ SENSOR_DT_READ_IODEV(max30001_iodev, DT_ALIAS(max30001), SENSOR_CHAN_VOLTAGE); SENSOR_DT_READ_IODEV(afe4400_iodev, DT_ALIAS(afe4400), SENSOR_CHAN_RED); RTIO_DEFINE_WITH_MEMPOOL(max30001_read_rtio_ctx, - 16, /* submission queue size */ - 16, /* completion queue size */ - 64, /* number of memory blocks */ + 16, /* submission queue size */ + 16, /* completion queue size */ + 64, /* number of memory blocks */ 32, /* size of each memory block */ - 4 /* memory alignment */ + 4 /* memory alignment */ ); RTIO_DEFINE_WITH_MEMPOOL(afe4400_read_rtio_ctx, - 16, /* submission queue size */ - 16, /* completion queue size */ - 64, /* number of memory blocks */ + 16, /* submission queue size */ + 16, /* completion queue size */ + 64, /* number of memory blocks */ 32, /* size of each memory block */ - 4 /* memory alignment */ + 4 /* memory alignment */ ); /* @@ -109,34 +109,9 @@ static void sensor_ppg_process_cb(int result, uint8_t *buf, uint32_t buf_len, vo struct hpi_ppg_sensor_data_t ppg_sensor_sample; - /*uint32_t un_ir_mean; - - // calculates DC mean and subtract DC from ir - un_ir_mean = 0; - for (k = 0; k < n_ir_buffer_length; k++) - un_ir_mean += pun_ir_buffer[k]; - un_ir_mean = un_ir_mean / n_ir_buffer_length; - - // remove DC and invert signal so that we can use peak detector as valley detector - for (k = 0; k < n_ir_buffer_length; k++) - an_x[k] = -1 * (pun_ir_buffer[k] - un_ir_mean); - */ - - - if (edata->num_samples > 0) - { - ppg_sensor_sample.ppg_num_samples = edata->num_samples; - - // Add DC removal code here - - - for (int i = 0; i < edata->num_samples; i++) - { - ppg_sensor_sample.ppg_red_samples[i] = edata->raw_samples_red[i]; - ppg_sensor_sample.ppg_ir_samples[i] = edata->raw_samples_ir[i]; - } - k_msgq_put(&q_ppg_sample, &ppg_sensor_sample, K_MSEC(1)); - } + ppg_sensor_sample.ppg_red_samples = edata->raw_sample_red; + ppg_sensor_sample.ppg_ir_samples = edata->raw_sample_ir; + k_msgq_put(&q_ppg_sample, &ppg_sensor_sample, K_MSEC(1)); } static void sensor_ecg_bioz_processing_cb(int result, uint8_t *buf, diff --git a/app/src/sampling_module.h b/app/src/sampling_module.h index 0c37576..cf65fda 100644 --- a/app/src/sampling_module.h +++ b/app/src/sampling_module.h @@ -13,7 +13,6 @@ struct hpi_sensor_data_t { #define ECG_POINTS_PER_SAMPLE 8 #define BIOZ_POINTS_PER_SAMPLE 4 -#define PPG_POINTS_PER_SAMPLE 1 struct hpi_ecg_bioz_sensor_data_t { @@ -30,9 +29,8 @@ struct hpi_ecg_bioz_sensor_data_t struct hpi_ppg_sensor_data_t { - int32_t ppg_red_samples[PPG_POINTS_PER_SAMPLE]; - int32_t ppg_ir_samples[PPG_POINTS_PER_SAMPLE]; - uint8_t ppg_num_samples; + int32_t ppg_red_sample; + int32_t ppg_ir_sample; uint8_t ppg_lead_off; uint8_t spo2; }; diff --git a/app/src/ui/screens/scr_ppg.c b/app/src/ui/screens/scr_ppg.c index 109dba1..339d613 100644 --- a/app/src/ui/screens/scr_ppg.c +++ b/app/src/ui/screens/scr_ppg.c @@ -83,7 +83,7 @@ static void hpi_ppg_disp_do_set_scale(int disp_window_size) } } -void hpi_ppg_disp_draw_plot_ppg(int32_t *data_ppg_red, int32_t *data_ppg_ir, int num_samples, bool ppg_lead_off) +void hpi_ppg_disp_draw_plot_ppg(int32_t *data_ppg_red, int32_t *data_ppg_ir, bool ppg_lead_off) { if (chart_ppg_update == true) // && ppg_lead_off == false) { diff --git a/drivers/sensor/afe4400/afe4400.c b/drivers/sensor/afe4400/afe4400.c index b702cf5..7055421 100644 --- a/drivers/sensor/afe4400/afe4400.c +++ b/drivers/sensor/afe4400/afe4400.c @@ -63,13 +63,13 @@ static int afe4400_sample_fetch(const struct device *dev, enum sensor_channel ch uint32_t led1val = _afe4400_read_reg(dev, LED1VAL); led1val = (uint32_t)(led1val << 10); int32_t led1val_signed = (int32_t)led1val; - drv_data->raw_samples_ir = (int32_t)led1val_signed >> 10; + drv_data->raw_sample_ir = (int32_t)led1val_signed >> 10; _afe4400_reg_write(dev, CONTROL0, 0x000001); uint32_t led2val = _afe4400_read_reg(dev, LED2VAL); led2val = (uint32_t)(led2val << 10); int32_t led2val_signed = (int32_t)led2val; - drv_data->raw_samples_red = (int32_t)led2val_signed >> 10; + drv_data->raw_sample_red = (int32_t)led2val_signed >> 10; return 0; } @@ -81,11 +81,11 @@ static int afe4400_channel_get(const struct device *dev, enum sensor_channel cha switch (chan) { case SENSOR_CHAN_RED: - val->val1 = drv_data->raw_samples_red; + val->val1 = drv_data->raw_sample_red; val->val2 = 0; break; case SENSOR_CHAN_IR: - val->val1 = drv_data->raw_samples_ir; + val->val1 = drv_data->raw_sample_ir; val->val2 = 0; break; default: diff --git a/drivers/sensor/afe4400/afe4400.h b/drivers/sensor/afe4400/afe4400.h index 50a0961..11d7210 100644 --- a/drivers/sensor/afe4400/afe4400.h +++ b/drivers/sensor/afe4400/afe4400.h @@ -19,8 +19,8 @@ struct afe4400_config struct afe4400_data { - int32_t raw_samples_ir; - int32_t raw_samples_red; + int32_t raw_sample_ir; + int32_t raw_sample_red; }; struct afe4400_decoder_header @@ -31,8 +31,8 @@ struct afe4400_decoder_header struct afe4400_encoded_data { struct afe4400_decoder_header header; - int32_t raw_samples_ir[8]; - int32_t raw_samples_red[8]; + int32_t raw_sample_ir; + int32_t raw_sample_red; uint32_t num_samples; }; diff --git a/drivers/sensor/afe4400/afe4400_async.c b/drivers/sensor/afe4400/afe4400_async.c index fe46fae..fd99dd2 100644 --- a/drivers/sensor/afe4400/afe4400_async.c +++ b/drivers/sensor/afe4400/afe4400_async.c @@ -9,23 +9,23 @@ LOG_MODULE_REGISTER(SENSOR_AFE4400_ASYNC, CONFIG_SENSOR_LOG_LEVEL); #define AFE4400_READ_BLOCK_SIZE 1 -static int afe4400_async_sample_fetch(const struct device *dev, int32_t raw_ir_sample[8], int32_t raw_red_sample[8], uint32_t *num_samples) +static int afe4400_async_sample_fetch(const struct device *dev, int32_t raw_ir_sample, int32_t raw_red_sample) { // struct afe4400_data *drv_data = dev->data; - for (int i = 0; i < AFE4400_READ_BLOCK_SIZE; i++) - { + //for (int i = 0; i < AFE4400_READ_BLOCK_SIZE; i++) + //{ _afe4400_reg_write(dev, CONTROL0, 0x000001); uint32_t led1val = _afe4400_read_reg(dev, LED1VAL); led1val = (uint32_t)(led1val << 10); int32_t led1val_signed = (int32_t)led1val; - raw_ir_sample[i] = (int32_t)led1val_signed >> 18; + raw_ir_sample = (int32_t)led1val_signed >> 18; _afe4400_reg_write(dev, CONTROL0, 0x000001); uint32_t led2val = _afe4400_read_reg(dev, LED2VAL); led2val = (uint32_t)(led2val << 10); int32_t led2val_signed = (int32_t)led2val; - raw_red_sample[i] = (int32_t)led2val_signed >> 18; + raw_red_sample = (int32_t)led2val_signed >> 18; //if(AFE4400_READ_BLOCK_SIZE>1) //k_sleep(K_MSEC(7)); @@ -33,7 +33,7 @@ static int afe4400_async_sample_fetch(const struct device *dev, int32_t raw_ir_s // printk("IR: %d, RED: %d\n", raw_ir_sample[i], raw_red_sample[i]); } - *num_samples = AFE4400_READ_BLOCK_SIZE; + //*num_samples = AFE4400_READ_BLOCK_SIZE; return 0; } @@ -59,7 +59,7 @@ int afe4400_submit(const struct device *dev, struct rtio_iodev_sqe *iodev_sqe) m_edata = (struct afe4400_encoded_data *)buf; m_edata->header.timestamp = k_ticks_to_ns_floor64(k_uptime_ticks()); - ret = afe4400_async_sample_fetch(dev, m_edata->raw_samples_ir, m_edata->raw_samples_red, &m_edata->num_samples); + ret = afe4400_async_sample_fetch(dev, &m_edata->raw_sample_ir, &m_edata->raw_sample_red, &m_edata->num_samples); if (ret != 0) { From 5ebd2379cb7904361314fffe1cfa90bf088006b1 Mon Sep 17 00:00:00 2001 From: MishalJasmine Date: Fri, 8 Nov 2024 18:05:03 +0530 Subject: [PATCH 07/10] ppg errors corrected --- app/src/ble_module.c | 2 +- app/src/data_module.c | 24 ++++++---------------- app/src/sampling_module.c | 4 ++-- drivers/sensor/afe4400/afe4400_async.c | 28 +++++++++++++------------- 4 files changed, 23 insertions(+), 35 deletions(-) diff --git a/app/src/ble_module.c b/app/src/ble_module.c index 09a871a..e85ec2c 100644 --- a/app/src/ble_module.c +++ b/app/src/ble_module.c @@ -268,7 +268,7 @@ void ble_ppg_notify(int16_t ppg_data) { uint8_t out_data[128]; - out_data[0] = (uint8_t)ppg_data; + out_data[0] = (uint8_t)(ppg_data); out_data[1] = (uint8_t)(ppg_data >> 8); bt_gatt_notify(NULL, &hpi_ppg_resp_service.attrs[1], &out_data, 2); diff --git a/app/src/data_module.c b/app/src/data_module.c index c567f6b..7a9b69d 100644 --- a/app/src/data_module.c +++ b/app/src/data_module.c @@ -321,23 +321,17 @@ void flush_current_session_logs(bool write_to_file) hpi_log_session_header.file_no = 0; } -void record_session_add_ppg_point(int16_t *ppg_samples, uint8_t ppg_len) +void record_session_add_ppg_point(int16_t ppg_sample) { if (current_session_ppg_counter < LOG_BUFFER_LENGTH) { - for (int i = 0; i < ppg_len; i++) - { - log_buffer[current_session_ppg_counter++].log_ppg_sample = ppg_samples[i]; - } + log_buffer[current_session_ppg_counter++].log_ppg_sample = ppg_sample; } else { hpi_log_session_write_file(PPG_DATA); current_session_ppg_counter = 0; - for (int i = 0; i < ppg_len; i++) - { - log_buffer[current_session_ppg_counter++].log_ppg_sample = ppg_samples[i]; - } + log_buffer[current_session_ppg_counter++].log_ppg_sample = ppg_sample; } } @@ -377,24 +371,18 @@ void record_session_add_ecg_point(int32_t *ecg_samples, uint8_t ecg_len, int32_t } } -void buffer_ppg_data_for_serial(int16_t *ppg_data_in, int ppg_len) +void buffer_ppg_data_for_serial(int16_t ppg_data_in) { if (serial_ppg_counter < HPI_OV3_DATA_IR_LEN) { - for (int i = 0; i < ppg_len; i++) - { - ppg_serial_streaming[serial_ppg_counter++] = ppg_data_in[i]; - } + ppg_serial_streaming[serial_ppg_counter++] = ppg_data_in; } else { send_ppg_data_ov3_format(); serial_ppg_counter = 0; memset(ppg_serial_streaming, 0, sizeof(ppg_serial_streaming)); - for (int i = 0; i < ppg_len; i++) - { - ppg_serial_streaming[serial_ppg_counter++] = ppg_data_in[i]; - } + ppg_serial_streaming[serial_ppg_counter++] = ppg_data_in; } } diff --git a/app/src/sampling_module.c b/app/src/sampling_module.c index 46f9645..d563b9f 100644 --- a/app/src/sampling_module.c +++ b/app/src/sampling_module.c @@ -109,8 +109,8 @@ static void sensor_ppg_process_cb(int result, uint8_t *buf, uint32_t buf_len, vo struct hpi_ppg_sensor_data_t ppg_sensor_sample; - ppg_sensor_sample.ppg_red_samples = edata->raw_sample_red; - ppg_sensor_sample.ppg_ir_samples = edata->raw_sample_ir; + ppg_sensor_sample.ppg_red_sample = edata->raw_sample_red; + ppg_sensor_sample.ppg_ir_sample = edata->raw_sample_ir; k_msgq_put(&q_ppg_sample, &ppg_sensor_sample, K_MSEC(1)); } diff --git a/drivers/sensor/afe4400/afe4400_async.c b/drivers/sensor/afe4400/afe4400_async.c index fd99dd2..6d744ac 100644 --- a/drivers/sensor/afe4400/afe4400_async.c +++ b/drivers/sensor/afe4400/afe4400_async.c @@ -14,24 +14,24 @@ static int afe4400_async_sample_fetch(const struct device *dev, int32_t raw_ir_s // struct afe4400_data *drv_data = dev->data; //for (int i = 0; i < AFE4400_READ_BLOCK_SIZE; i++) - //{ - _afe4400_reg_write(dev, CONTROL0, 0x000001); - uint32_t led1val = _afe4400_read_reg(dev, LED1VAL); - led1val = (uint32_t)(led1val << 10); - int32_t led1val_signed = (int32_t)led1val; - raw_ir_sample = (int32_t)led1val_signed >> 18; - - _afe4400_reg_write(dev, CONTROL0, 0x000001); - uint32_t led2val = _afe4400_read_reg(dev, LED2VAL); - led2val = (uint32_t)(led2val << 10); - int32_t led2val_signed = (int32_t)led2val; - raw_red_sample = (int32_t)led2val_signed >> 18; +//{ + _afe4400_reg_write(dev, CONTROL0, 0x000001); + uint32_t led1val = _afe4400_read_reg(dev, LED1VAL); + led1val = (uint32_t)(led1val << 10); + int32_t led1val_signed = (int32_t)led1val; + raw_ir_sample = (int32_t)led1val_signed >> 18; + + _afe4400_reg_write(dev, CONTROL0, 0x000001); + uint32_t led2val = _afe4400_read_reg(dev, LED2VAL); + led2val = (uint32_t)(led2val << 10); + int32_t led2val_signed = (int32_t)led2val; + raw_red_sample = (int32_t)led2val_signed >> 18; //if(AFE4400_READ_BLOCK_SIZE>1) //k_sleep(K_MSEC(7)); // printk("IR: %d, RED: %d\n", raw_ir_sample[i], raw_red_sample[i]); - } + //} //*num_samples = AFE4400_READ_BLOCK_SIZE; @@ -59,7 +59,7 @@ int afe4400_submit(const struct device *dev, struct rtio_iodev_sqe *iodev_sqe) m_edata = (struct afe4400_encoded_data *)buf; m_edata->header.timestamp = k_ticks_to_ns_floor64(k_uptime_ticks()); - ret = afe4400_async_sample_fetch(dev, &m_edata->raw_sample_ir, &m_edata->raw_sample_red, &m_edata->num_samples); + ret = afe4400_async_sample_fetch(dev, &m_edata->raw_sample_ir, &m_edata->raw_sample_red); if (ret != 0) { From 3e2e25024412aaca79ef2a0e671a61c5e1507f45 Mon Sep 17 00:00:00 2001 From: Ashwin K Whitchurch Date: Fri, 8 Nov 2024 18:43:06 +0530 Subject: [PATCH 08/10] Fix AFE400 Sample number issue --- app/src/ble_module.c | 2 +- drivers/sensor/afe4400/afe4400.h | 7 ++++--- drivers/sensor/afe4400/afe4400_async.c | 6 +++--- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/app/src/ble_module.c b/app/src/ble_module.c index e85ec2c..06320f5 100644 --- a/app/src/ble_module.c +++ b/app/src/ble_module.c @@ -266,7 +266,7 @@ void ble_bioz_notify(int32_t *resp_data, uint8_t len) void ble_ppg_notify(int16_t ppg_data) { - uint8_t out_data[128]; + uint8_t out_data[32]; out_data[0] = (uint8_t)(ppg_data); out_data[1] = (uint8_t)(ppg_data >> 8); diff --git a/drivers/sensor/afe4400/afe4400.h b/drivers/sensor/afe4400/afe4400.h index 11d7210..e629d56 100644 --- a/drivers/sensor/afe4400/afe4400.h +++ b/drivers/sensor/afe4400/afe4400.h @@ -33,8 +33,6 @@ struct afe4400_encoded_data struct afe4400_decoder_header header; int32_t raw_sample_ir; int32_t raw_sample_red; - - uint32_t num_samples; }; // AFE4400 Register Map @@ -91,4 +89,7 @@ struct afe4400_encoded_data #define DIAG 0x30 int afe4400_submit(const struct device *dev, struct rtio_iodev_sqe *iodev_sqe); -int afe4400_get_decoder(const struct device *dev, const struct sensor_decoder_api **decoder); \ No newline at end of file +int afe4400_get_decoder(const struct device *dev, const struct sensor_decoder_api **decoder); + +uint32_t _afe4400_read_reg(const struct device *dev, uint8_t reg); +int _afe4400_reg_write(const struct device *dev, uint8_t reg, uint32_t val); diff --git a/drivers/sensor/afe4400/afe4400_async.c b/drivers/sensor/afe4400/afe4400_async.c index 6d744ac..5ed7d9c 100644 --- a/drivers/sensor/afe4400/afe4400_async.c +++ b/drivers/sensor/afe4400/afe4400_async.c @@ -9,7 +9,7 @@ LOG_MODULE_REGISTER(SENSOR_AFE4400_ASYNC, CONFIG_SENSOR_LOG_LEVEL); #define AFE4400_READ_BLOCK_SIZE 1 -static int afe4400_async_sample_fetch(const struct device *dev, int32_t raw_ir_sample, int32_t raw_red_sample) +static int afe4400_async_sample_fetch(const struct device *dev, int32_t *raw_ir_sample, int32_t *raw_red_sample) { // struct afe4400_data *drv_data = dev->data; @@ -19,13 +19,13 @@ static int afe4400_async_sample_fetch(const struct device *dev, int32_t raw_ir_s uint32_t led1val = _afe4400_read_reg(dev, LED1VAL); led1val = (uint32_t)(led1val << 10); int32_t led1val_signed = (int32_t)led1val; - raw_ir_sample = (int32_t)led1val_signed >> 18; + *raw_ir_sample = (int32_t)led1val_signed >> 18; _afe4400_reg_write(dev, CONTROL0, 0x000001); uint32_t led2val = _afe4400_read_reg(dev, LED2VAL); led2val = (uint32_t)(led2val << 10); int32_t led2val_signed = (int32_t)led2val; - raw_red_sample = (int32_t)led2val_signed >> 18; + *raw_red_sample = (int32_t)led2val_signed >> 18; //if(AFE4400_READ_BLOCK_SIZE>1) //k_sleep(K_MSEC(7)); From b3166a419818783a29a48a65777c7c8edb7e4fd5 Mon Sep 17 00:00:00 2001 From: Ashwin K Whitchurch Date: Fri, 8 Nov 2024 22:37:54 +0530 Subject: [PATCH 09/10] Fix display mod num sample issue --- app/healthypi5_rp2040_display_ili9488.overlay | 2 +- app/prj.conf | 7 +++++ app/src/display/display_module.c | 4 +-- app/src/display/display_module.h | 2 +- app/src/ui/screens/scr_ppg.c | 27 ++++++++----------- 5 files changed, 22 insertions(+), 20 deletions(-) diff --git a/app/healthypi5_rp2040_display_ili9488.overlay b/app/healthypi5_rp2040_display_ili9488.overlay index 0cbe7fe..b5a23f2 100644 --- a/app/healthypi5_rp2040_display_ili9488.overlay +++ b/app/healthypi5_rp2040_display_ili9488.overlay @@ -16,7 +16,7 @@ ili9488: ili9488@0 { compatible = "ilitek,ili9488"; reg = <0>; - mipi-max-frequency = <32000000>; + mipi-max-frequency = <48000000>; rotation = <90>; width = <480>; height = <320>; diff --git a/app/prj.conf b/app/prj.conf index 46cc7e5..cf4bef1 100644 --- a/app/prj.conf +++ b/app/prj.conf @@ -98,7 +98,14 @@ CONFIG_CMSIS_DSP_FILTERING=y #CONFIG_TENSORFLOW_LITE_MICRO_CMSIS_NN_KERNELS=y CONFIG_LOG=y +CONFIG_UART_CONSOLE=y CONFIG_ENTROPY_GENERATOR=y CONFIG_TEST_RANDOM_GENERATOR=y +CONFIG_LV_USE_LOG=y +CONFIG_LV_LOG_LEVEL_ERROR=y +CONFIG_DISPLAY_LOG_LEVEL_DBG=y +CONFIG_INPUT_LOG_LEVEL_DBG=y +CONFIG_SENSOR_LOG_LEVEL_DBG=y +CONFIG_LOG_DEFAULT_LEVEL=4 \ No newline at end of file diff --git a/app/src/display/display_module.c b/app/src/display/display_module.c index fcfada4..8f83007 100644 --- a/app/src/display/display_module.c +++ b/app/src/display/display_module.c @@ -600,11 +600,11 @@ void display_screens_thread(void) } lv_task_handler(); - k_sleep(K_MSEC(1)); + k_sleep(K_MSEC(2)); } } -#define DISPLAY_SCREENS_THREAD_STACKSIZE 7000 +#define DISPLAY_SCREENS_THREAD_STACKSIZE 8192 #define DISPLAY_SCREENS_THREAD_PRIORITY 5 K_THREAD_DEFINE(display_screens_thread_id, DISPLAY_SCREENS_THREAD_STACKSIZE, display_screens_thread, NULL, NULL, NULL, DISPLAY_SCREENS_THREAD_PRIORITY, 0, 0); diff --git a/app/src/display/display_module.h b/app/src/display/display_module.h index 4055c9e..03b8b9f 100644 --- a/app/src/display/display_module.h +++ b/app/src/display/display_module.h @@ -65,7 +65,7 @@ void hpi_resp_disp_draw_plot_resp(int32_t *data_resp, int num_samples, bool resp // PPG Screen functions void draw_scr_ppg(enum scroll_dir m_scroll_dir); -void hpi_ppg_disp_draw_plot_ppg(int32_t *data_ppg_red, int32_t *data_ppg_ir, bool ppg_lead_off); +void hpi_ppg_disp_draw_plot_ppg(int32_t data_ppg_red, int32_t data_ppg_ir, bool ppg_lead_off); void hpi_scr_home_update_pr(int pr); //void draw_scr_chart_resp(void); diff --git a/app/src/ui/screens/scr_ppg.c b/app/src/ui/screens/scr_ppg.c index 339d613..888b754 100644 --- a/app/src/ui/screens/scr_ppg.c +++ b/app/src/ui/screens/scr_ppg.c @@ -83,29 +83,24 @@ static void hpi_ppg_disp_do_set_scale(int disp_window_size) } } -void hpi_ppg_disp_draw_plot_ppg(int32_t *data_ppg_red, int32_t *data_ppg_ir, bool ppg_lead_off) +void hpi_ppg_disp_draw_plot_ppg(int32_t data_ppg_red, int32_t data_ppg_ir, bool ppg_lead_off) { if (chart_ppg_update == true) // && ppg_lead_off == false) { - for (int i = 0; i < num_samples; i++) + + if (data_ppg_red < y_min_ppg) { - int32_t data_ppg_i = ((data_ppg_red[i])); - - // printk("PPG: %d\n", data_ppg_i); + y_min_ppg = data_ppg_red; + } - if (data_ppg_i < y_min_ppg) - { - y_min_ppg = data_ppg_i; - } + if (data_ppg_red > y_max_ppg) + { + y_max_ppg = data_ppg_red; + } - if (data_ppg_i > y_max_ppg) - { - y_max_ppg = data_ppg_i; - } + lv_chart_set_next_value(chart_ppg, ser_ppg, data_ppg_red); + hpi_ppg_disp_add_samples(1); - lv_chart_set_next_value(chart_ppg, ser_ppg, data_ppg_i); - hpi_ppg_disp_add_samples(1); - } hpi_ppg_disp_do_set_scale(PPG_DISP_WINDOW_SIZE); } From a40f0ebdf33a3c987b3e9de0db6c2362db32b6c0 Mon Sep 17 00:00:00 2001 From: MishalJasmine Date: Sat, 9 Nov 2024 09:01:58 +0530 Subject: [PATCH 10/10] flushing the previous session disabled --- app/src/cmd_module.c | 2 +- app/src/data_module.c | 6 +++--- app/src/datalog_module.c | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/src/cmd_module.c b/app/src/cmd_module.c index bfba648..f40e9a5 100644 --- a/app/src/cmd_module.c +++ b/app/src/cmd_module.c @@ -177,7 +177,7 @@ void hpi_decode_data_packet(uint8_t *in_pkt_buf, uint8_t pkt_len) printk("Command to end logging\n"); // AKW: Replace with a function to stop logging settings_log_data_enabled = false; - flush_current_session_logs(true); + flush_current_session_logs(); break; case CMD_LOGGING_START: diff --git a/app/src/data_module.c b/app/src/data_module.c index 7a9b69d..42d823b 100644 --- a/app/src/data_module.c +++ b/app/src/data_module.c @@ -284,11 +284,11 @@ void send_data_text_1(int32_t in_sample) } // Start a new session log -void flush_current_session_logs(bool write_to_file) +void flush_current_session_logs() { // if data is pending in the log Buffer - if ((current_session_ecg_counter > 0) && (write_to_file)) + /*if ((current_session_ecg_counter > 0) && (write_to_file)) { hpi_log_session_write_file(ECG_DATA); } @@ -296,7 +296,7 @@ void flush_current_session_logs(bool write_to_file) if ((current_session_ppg_counter > 0) && (write_to_file)) { hpi_log_session_write_file(PPG_DATA); - } + }*/ // current_session_log_id = 0; for (int i = 0; i < LOG_BUFFER_LENGTH; i++) diff --git a/app/src/datalog_module.c b/app/src/datalog_module.c index 864075f..830e9c0 100644 --- a/app/src/datalog_module.c +++ b/app/src/datalog_module.c @@ -131,7 +131,7 @@ void set_current_session_id(uint8_t m_sec, uint8_t m_min, uint8_t m_hour, uint8_ if (sd_card_present) { - flush_current_session_logs(true); + flush_current_session_logs(); // update structure with new session start time hpi_log_session_header.session_start_time.year = year;