![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Mode1 Optical Validation
Diff: main.cpp
- Revision:
- 33:c8fbd904df3e
- Parent:
- 32:92adfbe18ab6
- Child:
- 34:53043966c276
--- a/main.cpp Mon Mar 14 23:53:46 2022 +0000 +++ b/main.cpp Tue Mar 15 21:01:25 2022 +0000 @@ -86,7 +86,11 @@ /*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*/ //#define RAW // define this if you want AFE+accel data, no algorithm #define ALGO_ONLY 1 // define this if you only want algo data, comment out if you want raw sensor+algo data -//#define EXTENDED_ALGO 1 // define this if you want the extended algo format + +// Comment out both of the below for Normal Algorithm Samples Format +//#define EXTENDED_ALGO 1 // define this if you want the extended algo samples report format +#define PACKED_NORMAL_ALGO 1 // define this if you want the packed normal algo samples report format + //#define AGC 1 // define this for AGC, otherwise the default is AEC #ifdef MAXREFDES103_CFG @@ -103,20 +107,22 @@ #define SENSOR_SZ (PPG_SZ+ACCEL_SZ) #if defined(MAXM86161_CFG) || defined(MAXM86146_CFG) // MAXM86161, MAXM86146, keep algo Fifo size as 52, 20 to keep compatible w/ the GUI -#define old_msbl 1 // 3x.12.0 or earlier; 32.9.x +#define old_algo_sz 1 // 3x.12.0 or earlier; 32.9.x #endif -#ifdef old_msbl +#ifdef old_algo_sz #ifdef EXTENDED_ALGO - #define ALGO_SZ 52 // 52 bytes is the extended algo size for 3x.12.0 + #define ALGO_SZ 52 // 52 bytes, extended algo size for 3x.12.0 + #elif defined(PACKED_NORMAL_ALGO) + #define ALGO_SZ 16 // 16 bytes, packed algo normal size for 33.31.31 #else - #define ALGO_SZ 20 // 20 bytes is the algo normal size for 3x.12.0 + #define ALGO_SZ 20 // 20 bytes, normal algo size for 3x.12.0 #endif #else #ifdef EXTENDED_ALGO - #define ALGO_SZ 56 // 56 bytes is the extended algo size for 3x.13.x+ + #define ALGO_SZ 56 // 56 bytes, extended algo size for 3x.13.x+ #else - #define ALGO_SZ 24 // 24 bytes is the algo normal size for 3x.13.x+ + #define ALGO_SZ 24 // 24 bytes, normal algo size for 3x.13.x+ #endif #endif @@ -135,6 +141,9 @@ DigitalOut gLED(LED2); DigitalOut bLED(LED3); +int32_t heading_printed; // has the heading been printed? + + //#define thread_sleep_for(x) wait_ms(x) // for older versions of mbed @@ -160,17 +169,18 @@ #define MAX_FIFO_CNT 20 #endif void read_sh_fifo(void) { - char cmd[8], i, j, samples; + char cmd[8], i, j, k, samples; char rsp[3000]; int32_t ppg[12]; int16_t accel[3]; + int32_t tst[20]; int32_t status, opmode, hr, hr_conf, ibi, ibi_conf; #ifdef EXTENDED_ALGO int32_t walk_stp, run_stp, energy, amr, iadj1_rqt, iadj1, iadj2_rqt, iadj2, iadj3_rqt, iadj3; int32_t intadj_rqt, intadj, smpladj_rqt, smpladj, rqt_smplave, afestatehr, hr_motion; #endif int32_t act, r, spo2, spo2_conf; - int32_t spo2_compl, spo2_lo, spo2_mo, spo2_lopi, spo2_unrel, spo2_state, ibi_offset, scd; + int32_t spo2_compl, spo2_lo, spo2_mo, spo2_lopi, spo2_unrel, spo2_state, ibi_offset, scd, inappro_ori; int32_t scnt = 0; int32_t ptr = 0; int32_t sptr = 0; @@ -191,7 +201,7 @@ sh_i2c.read(SH_ADDR, rsp, 2); // pc.printf("2.1 Status: %x %x\n\r", rsp[0], rsp[1]); #else - // testd 33.13.12 doesn't need 2.1 + // tested w/ 33.13.12 doen't need 2.1 #endif // 2.2 cmd[0] = 0x12; cmd[1] = 0x00; @@ -301,6 +311,13 @@ sptr += (TTL_SZ); #if 1 + if (heading_printed == 0) { + heading_printed = 1; + pc.printf("opmode,hr,hr_conf,ibi,ibi_conf,act,walk_stp,run_stp,energy,amr,"); + pc.printf("iadj1_rqt,iadj1,iadj2_rqt,iadj2,iadj3_rqt,iadj3,intadj_rqt,intadj,"); + pc.printf("smpladj_rqt,smpladj,rqt_smplave,afestatehr,hr_motion,scd,"); + pc.printf("spo2,spo2_compl,spo2_lo,spo2_mo,spo2_lopi,spo2_unrel,spo2_state,ibi_offset,\n\r"); + } pc.printf("%d,%d,%d,%d,", opmode, hr, hr_conf, ibi); pc.printf("%d,%d,", ibi_conf, act); pc.printf("%d,%d,%d,", walk_stp, run_stp, energy); @@ -313,11 +330,71 @@ pc.printf("%d,%d,%d,", spo2_lopi,spo2_unrel, spo2_state); pc.printf("%d,", ibi_offset); #else + if (heading_printed == 0) { + heading_printed = 1; + pc.printf("hr,hr_conf,spo2,spo2_conf,spo2_lo,spo2_unrel,scd,\n\r"); + } pc.printf("%d,%d,", hr, hr_conf); pc.printf("%d,%d,", spo2, spo2_conf); pc.printf("%d,%d,%d,", spo2_lo, spo2_mo, spo2_lopi); pc.printf("%d,%d,", spo2_unrel, scd); #endif +#elif defined(PACKED_NORMAL_ALGO) +// pc.printf("ptr %d ttlsiz %d ", ptr, TTL_SZ); + opmode = rsp[ptr]; + hr = (rsp[ptr+1] << 8) + rsp[ptr+2]; + hr_conf = rsp[ptr+3]; + ibi = (rsp[ptr+4] << 8) + rsp[ptr+5]; + + ibi_conf = rsp[ptr+6]; +// act = rsp[ptr+7]; + r = (rsp[ptr+7] << 8) + rsp[ptr+8]; + spo2_conf = rsp[ptr+9]; + + spo2 = (rsp[ptr+10] << 8) + rsp[ptr+11]; + spo2_compl = rsp[ptr+12]; + + spo2_lo = 0; spo2_mo = 0; spo2_lopi = 0; spo2_unrel = 0; + + if (rsp[ptr+13] & 0x01) + spo2_lo = 1; + if (rsp[ptr+13] & 0x02) + spo2_mo = 1; + if (rsp[ptr+13] & 0x04) + spo2_lopi = 1; + if (rsp[ptr+13] & 0x08) + spo2_unrel = 1; + spo2_state = (0x30 & rsp[ptr+13]) >> 4; + + scd = (0x03 & rsp[ptr+14]); + act = (0x1C & rsp[ptr+14]) >> 2; + inappro_ori = (0x20 & rsp[ptr+14]) >> 5; + + ibi_offset = rsp[ptr+15]; + + sptr += (TTL_SZ); +#if 1 + if (heading_printed == 0) { + heading_printed = 1; + pc.printf("opmode,hr,hr_conf,ibi,ibi_conf,act,r,spo2_conf,spo2,spo2_compl,spo2_lo,spo2_mo,spo2_lopi,spo2_unrel,spo2_state,scd,ibioffset,inappro_ori,\n\r"); + } + pc.printf("%d,%d,%d,%d,", opmode, hr, hr_conf, ibi); + pc.printf("%d,%d,%d,%d,", ibi_conf, act, r, spo2_conf); + pc.printf("%d,%d,%d,%d,", spo2, spo2_compl, spo2_lo, spo2_mo); + pc.printf("%d,%d,%d,%d,", spo2_lopi,spo2_unrel, spo2_state, scd); + pc.printf("%d,", ibi_offset); + pc.printf("%d,", inappro_ori); + +#else + if (heading_printed == 0) { + heading_printed = 1; + pc.printf("hr,hr_conf,spo2,spo2_conf,spo2_lo,spo2_unrel,scd,\n\r"); + } + pc.printf("%d,%d,", hr, hr_conf); + pc.printf("%d,%d,", spo2, spo2_conf); + pc.printf("%d,", spo2_lo); + pc.printf("%d,%d,", spo2_unrel, scd); +#endif #else // normal algo size // pc.printf("ptr %d ttlsiz %d ", ptr, TTL_SZ); opmode = rsp[ptr]; @@ -344,12 +421,20 @@ sptr += (TTL_SZ); #if 0 + if (heading_printed == 0) { + heading_printed = 1; + pc.printf("opmode,hr,hr_conf,ibi,ibi_conf,act,r,spo2_conf,spo2,spo2_compl,spo2_lo,spo2_mo,spo2_lopi,spo2_unrel,spo2_state,scd,ibioffset,\n\r"); + } pc.printf("%d,%d,%d,%d,", opmode, hr, hr_conf, ibi); pc.printf("%d,%d,%d,%d,", ibi_conf, act, r, spo2_conf); pc.printf("%d,%d,%d,%d,", spo2, spo2_compl, spo2_lo, spo2_mo); pc.printf("%d,%d,%d,%d,", spo2_lopi,spo2_unrel, spo2_state, scd); pc.printf("%d,", ibi_offset); #else + if (heading_printed == 0) { + heading_printed = 1; + pc.printf("hr,hr_conf,spo2,spo2_conf,spo2_lo,spo2_unrel,scd,\n\r"); + } pc.printf("%d,%d,", hr, hr_conf); pc.printf("%d,%d,", spo2, spo2_conf); pc.printf("%d,", spo2_lo); @@ -432,30 +517,37 @@ mfio = 1; mfio = 0; wait_us(300); pc.printf("Ver: %d %d %d %d\n\r", rsp[0], rsp[1], rsp[2], rsp[3]); -#if defined(MAXM86161_CFG) -// algo sz normal +#if defined(MAXM86161_CFG) || defined(MAXM86146_CFG) +// rd algo sz normal cmd[0] = 0x11; cmd[1] = 0x06; cmd[2] = 0x01; sh_i2c.write(SH_ADDR, cmd, 3); mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300); sh_i2c.read(SH_ADDR, rsp, 2); mfio = 1; mfio = 0; wait_us(300); - pc.printf("algo size: %d %d \n\r", rsp[0], rsp[1]); - -// algo sz extended + pc.printf("rd algo size: %d %d \n\r", rsp[0], rsp[1]); +// rd algo sz extended cmd[0] = 0x11; cmd[1] = 0x06; cmd[2] = 0x02; sh_i2c.write(SH_ADDR, cmd, 3); mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300); sh_i2c.read(SH_ADDR, rsp, 2); mfio = 1; mfio = 0; wait_us(300); - pc.printf("algo size: %d %d \n\r", rsp[0], rsp[1]); - -// algo sz scd + pc.printf("rd algo size: %d %d \n\r", rsp[0], rsp[1]); +// rd algo sz scd cmd[0] = 0x11; cmd[1] = 0x06; cmd[2] = 0x03; sh_i2c.write(SH_ADDR, cmd, 3); mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300); sh_i2c.read(SH_ADDR, rsp, 2); mfio = 1; mfio = 0; wait_us(300); - pc.printf("algo size: %d %d \n\r", rsp[0], rsp[1]); + pc.printf("rd algo size: %d %d \n\r", rsp[0], rsp[1]); +#if defined(MAXM86146_CFG) +// rd algo sz scd + cmd[0] = 0x11; cmd[1] = 0x06; cmd[2] = 0x04; + sh_i2c.write(SH_ADDR, cmd, 3); + mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300); + sh_i2c.read(SH_ADDR, rsp, 2); + mfio = 1; mfio = 0; wait_us(300); + pc.printf("rd algo size: %d %d \n\r", rsp[0], rsp[1]); +#endif #endif #if 0 @@ -630,6 +722,8 @@ // 1.30 Enable HR, SpO2 algo #ifdef EXTENDED_ALGO cmd[0] = 0x52; cmd[1] = 0x07; cmd[2] = 0x02; +#elif defined(PACKED_NORMAL_ALGO) + cmd[0] = 0x52; cmd[1] = 0x07; cmd[2] = 0x04; #else cmd[0] = 0x52; cmd[1] = 0x07; cmd[2] = 0x01; #endif @@ -845,6 +939,7 @@ init_sh_algo(); #endif mfio = 1; + heading_printed = 0; #if defined(MAXREFDES103_CFG) || defined(MAXM86161_CFG) || defined(MAXM86146_CFG) Timer tmr1; while (1) {