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:
- 19:6e584392d4a7
- Parent:
- 18:b7226b560838
- Child:
- 20:fcf071379cba
--- a/main.cpp Mon Oct 08 21:40:53 2018 +0000
+++ b/main.cpp Fri Oct 12 20:24:15 2018 +0000
@@ -1,7 +1,7 @@
#include "mbed.h"
#include "OB1203.h"
#include "math.h"
-//#include "SoftI2C.h"
+
//normal
@@ -34,9 +34,9 @@
bool meas_temp = 0;
bool printAvg = 0; //default 0 print raw data
bool redAGC = 1;
-bool IRAGC = 1;
+bool irAGC = 1;
bool trim_oscillator = 0;
-bool printCurrent = 1;
+bool printCurrent = 0;
//****************************
//internal settings
@@ -225,17 +225,8 @@
uint32_t PSprev = 0;
uint32_t PS_avg_buffer[ps_running_avg];
- uint32_t targetIRcounts = 196608; //0.75 of full scale
- uint32_t targetRcounts = 196608; //0.75 of full scale
-// uint32_t tol1 = 8192; //1 5 bit increment
- uint32_t tol1 = 4096; //1 5 bit increment
- uint32_t tol2 = 39321; //for 90% and 60% large limits
- uint32_t step = 8;
- uint32_t IR_in_range = 0;
- uint32_t R_in_range = 0;
bool update = 0;
- uint32_t in_range_persist = 4;
- uint16_t maxIRcurrent =0x2AF;
+
for (int n=0;n<ps_running_avg;n++)
{
@@ -402,75 +393,20 @@
}//HR case
if(n+1==samples2Read/2)
{
- if(IRAGC)
- {
- if( ppgData[2*n] > targetIRcounts + (IR_in_range>in_range_persist ? tol2: tol1) )
- {
- if(ppgData[2*n]>targetIRcounts + tol2)
- IR_in_range=0;
- if(ob1203.ir_current>step)
- {
-// pc.printf("IR %d, IRc %d--, IR_in_range %d\r\n",ppgData[2*n],ob1203.ir_current,IR_in_range);
- ob1203.ir_current -= step;
- update = 1;
-
- }
- }
- else if( ppgData[2*n] < targetIRcounts - (IR_in_range>in_range_persist ? tol2 : tol1) )
- {
- if(ppgData[2*n]<targetIRcounts - tol2)
- IR_in_range=0;
- if(ob1203.ir_current+step<maxIRcurrent) //no need to go to full current
- {
- ob1203.ir_current += step;
- update = 1;
-// pc.printf("IR %d, IRc %d++, IR_in range %d\r\n", ppgData[2*n],ob1203.ir_current,IR_in_range);
- }
- }
- else
- {
- if( (ppgData[2*n] > (targetRcounts-tol1) ) && (ppgData[2*n] < (targetRcounts+tol1)) )
- IR_in_range++;
- }
- }//end IR AGC case
-
+ if(irAGC)
+ {
+ ob1203.do_agc(ppgData[2*n],0);
+ }//end IR AGC case
if(spo2 && redAGC)
{
- if( ppgData[2*n+1] > targetRcounts + (R_in_range>in_range_persist ? tol2 : tol1) )
- {
- if(ppgData[2*n+1]>targetRcounts + tol2)
- R_in_range=0;
- if(ob1203.r_current>step)
- {
-// pc.printf("R %d, Rc %d--,R_in_range %d\r\n", ppgData[2*n+1],ob1203.r_current,R_in_range);
- ob1203.r_current -= step;
- update = 1;
- }
- }
- else if( ppgData[2*n+1] < targetRcounts - (R_in_range>in_range_persist ? tol2 : tol1) )
- {
- if(ppgData[2*n+1]<targetRcounts - tol2)
- R_in_range=0;
- if(ob1203.r_current+step<0x1FF)
- {
-
-// pc.printf("R %d, Rc %d++,R_in_range %d\r\n", ppgData[2*n+1],ob1203.r_current,R_in_range);
- ob1203.r_current += step;
- update = 1;
- }
- }
- else
- {
- if( (ppgData[2*n+1] > (targetRcounts-tol1) ) && (ppgData[2*n+1] < (targetRcounts+tol1)) )
- R_in_range++;
- }
- if(update)
- {
- ob1203.setPPGcurrent();
- ob1203.resetFIFO();
- update=0;
- }
- }//end R AGC case
+ ob1203.do_agc(ppgData[2*n+1],1);
+ }//enr R AGC case
+ if(ob1203.update)
+ {
+ ob1203.setPPGcurrent();
+ ob1203.resetFIFO();
+ ob1203.update=0;
+ }
}
}//end sample loop