Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed OB1203_example_driver
Diff: main.cpp
- Revision:
- 1:fb6b2b4d5d8a
- Parent:
- 0:e9ae48b7f6f6
- Child:
- 2:ee175f471ecb
--- a/main.cpp Wed Apr 25 05:29:19 2018 +0000 +++ b/main.cpp Thu May 03 02:20:59 2018 +0000 @@ -5,6 +5,7 @@ #define intb_pin D3 + I2C i2c(I2C_SDA,I2C_SCL); InterruptIn intb(intb_pin); DigitalOut sda_pullup(D11,1); @@ -15,25 +16,38 @@ Serial pc(USBTX, USBRX,115200); Timer t; +int sample_delay = 10; //ms + + bool mode = 0; //0 for PS_LS, 1 for SPO2 bool intFlagged =0; + void defaultConfig() { - ob1203.ls_res = LS_RATE(2); //100ms + ob1203.ls_rate = LS_RATE(2); //100ms ob1203.ls_res = LS_RES(2); //18bit 100ms - ob1203.ls_gain = LS_GAIN(1); //gain 3 default - ob1203.ls_thres_hi = 0x0FFFFF; + ob1203.ls_gain = LS_GAIN(1); //gain 3 default (range) + ob1203.ls_thres_hi = 0x000FFFFF; ob1203.ls_thres_lo = 0; ob1203.ls_sai = LS_SAI_OFF; ob1203.ls_mode = RGB_MODE; ob1203.ls_en = LS_ON; ob1203.ps_sai_en = PS_SAI_OFF; - ob1203.ppg_ps_mode = PS_MODE; - ob1203.ps_pulses = PS_PULSES(8); + if(mode) + { + ob1203.pps_ps_mode = SPO2_MODE; + } + else + { + ob1203.ppg_ps_mode = PS_MODE; + } + ob1203.ps_pulses = PS_PULSES(2); +// pc.printf("ps_pulses = %02X\r\n",ob1203.ps_pulses); ob1203.ps_pwidth = PS_PWIDTH(1); ob1203.ps_rate = PS_RATE(5); +// pc.printf("ps_rate = %02X\r\n",ob1203.ps_rate); ob1203.ps_avg_en = PS_AVG_OFF; ob1203.ps_can_ana = PS_CAN_ANA_0; ob1203.ps_digital_can = 0; @@ -79,6 +93,25 @@ } } +void regDump(uint8_t Addr, uint8_t startByte, uint8_t endByte) +{ + /*print the values of up to 20 registers--buffer limit, e.g.*/ + char regData[20]; + int numBytes; + if (endByte>=startByte) { + numBytes = (endByte-startByte+1) < 20 ? (endByte-startByte+1) : 20; + } else { + numBytes=1; + } + + regData[0] = startByte; + i2c.write(Addr,regData,1,true); + i2c.read(Addr, regData, numBytes); + for(int n=0; n<numBytes; n++) { + pc.printf("%02X, %02X \r\n", startByte+n, regData[n]); + } +} + void intEvent(void) { @@ -94,29 +127,50 @@ char fifoBuffer[samples2Read]; uint32_t ppgData[samples2Read]; - + + pc.printf("register settings\r\n"); + regDump(OB1203_ADDR,0,19); + regDump(OB1203_ADDR,20,39); + regDump(OB1203_ADDR,40,59); + regDump(OB1203_ADDR,60,77); + + pc.printf("do initial config\r\n"); defaultConfig(); //rgb ps + + pc.printf("print new register config\r\n"); + regDump(OB1203_ADDR,0,19); + regDump(OB1203_ADDR,20,39); + regDump(OB1203_ADDR,40,59); + regDump(OB1203_ADDR,60,77); + intb.fall(&intEvent); while(1) - if(intFlagged) { - if( mode ) + if(mode) { - ob1203.getFifoSamples(samples2Read,fifoBuffer); - ob1203.parseFifoSamples(samples2Read,fifoBuffer,ppgData); - for (int n=0;n<samples2Read/2;n++) + if(intFlagged) { - pc.printf("%d %d/r/n",ppgData[2*n],ppgData[2*n+1]); + + ob1203.getFifoSamples(samples2Read,fifoBuffer); + ob1203.parseFifoSamples(samples2Read,fifoBuffer,ppgData); + for (int n=0;n<samples2Read/2;n++) + { + pc.printf("%d %d\r\n",ppgData[2*n],ppgData[2*n+1]); + } + intFlagged = 0; + } - intFlagged = 0; } else { - valid = ob1203.get_ps_ls_data(ps_ls_data); - pc.printf("%d %d %d %d %d %d/r/n",ps_ls_data[0],ps_ls_data[1],ps_ls_data[2],ps_ls_data[3],ps_ls_data[4],ps_ls_data[5]); + wait_ms(sample_delay); + if(ob1203.dataIsNew()) + { + valid = ob1203.get_ps_ls_data(ps_ls_data); + pc.printf("%d %d %d %d %d %d\r\n",ps_ls_data[0],ps_ls_data[1],ps_ls_data[2],ps_ls_data[3],ps_ls_data[4],ps_ls_data[5]); + } } - intFlagged =0; - } -} \ No newline at end of file + }//end while +}//end main \ No newline at end of file