Index: firmware/App/Controllers/BloodLeak.c =================================================================== diff -u -r0528a70e1de371ac0659a732d8b71d140751381b -rfcfcd7619185b71aa2163c3e22e4b7bff730041c --- firmware/App/Controllers/BloodLeak.c (.../BloodLeak.c) (revision 0528a70e1de371ac0659a732d8b71d140751381b) +++ firmware/App/Controllers/BloodLeak.c (.../BloodLeak.c) (revision fcfcd7619185b71aa2163c3e22e4b7bff730041c) @@ -98,8 +98,7 @@ #define BLD_NOMINAL_INTENSITY 930 ///< Blood leak nominal intensity. #define BLD_MAX_INTENSITY_OUT_OF_RANGE 0.35F ///< Blood leak maximum allowed intensity. #define BLD_MIN_INTENSITY_OUT_OF_RANGE 0.40F ///< Blood leak minimum allowed intensity. -#define BLD_SHIFT_BITS_BY_4_FOR_AVERAGING 4U ///< Blood leak shift values by 4 to average them. -#define BLD_ZERO_INTERVAL_MS ( 30 * SEC_PER_MIN * MS_PER_SECOND ) ///< Blood leak zeroing interval in milliseconds. +#define BLD_ZERO_MIN_INTERVAL_MS ( 30 * SEC_PER_MIN * MS_PER_SECOND ) ///< Blood leak zeroing minimum interval in milliseconds. #define BLD_ZERO_MVG_AVG_NUM_OF_SAMPLES 16 ///< Blood leak number of moving average samples. #define BLD_ZERO_IN_RANGE_DRIFT_TIMEOUT_MS ( 2 * MS_PER_SECOND ) ///< Blood leak zero value drift in range timeout in milliseconds. @@ -159,11 +158,10 @@ { U32 lastZeroingStartTimeMS; ///< Blood leak last zero sequence start time in milliseconds. U32 driftInRangeStartTimeMS; ///< Blood leak drift is in range start time in milliseconds. - BOOL hasDriftTimerBeenSet; ///< Blood leak flag to indicate drift time has been set or not. U32 rawIntensity[ BLD_ZERO_MVG_AVG_NUM_OF_SAMPLES ]; ///< Blood leak raw intensity array. U32 intensityRunningSum; ///< Blood leak intensity running sum for moving average. U32 rawIntensityNextIndex; ///< Blood leak raw intensity next index for moving average. - U32 intensityMovingAverage; ///< Blood leak intensity moving average. + F32 intensityMovingAverage; ///< Blood leak intensity moving average. } BLOOD_LEAK_ZEROING_STATUS_T; // ********** private data ********** @@ -688,8 +686,9 @@ { // Done with zero sequence, transition to other states zeroBloodLeakReset(); - bloodLeakSelfTestStatus = SELF_TEST_STATUS_PASSED; - state = BLOOD_LEAK_NORMAL_STATE; + bloodLeakZeroingStatus.lastZeroingStartTimeMS = getMSTimerCount(); + bloodLeakSelfTestStatus = SELF_TEST_STATUS_PASSED; + state = BLOOD_LEAK_NORMAL_STATE; } // If not successful, retry if we've not run out else @@ -1684,7 +1683,7 @@ bloodLeakZeroingStatus.rawIntensity[ index ] = newIntensity; bloodLeakZeroingStatus.intensityRunningSum = bloodLeakZeroingStatus.intensityRunningSum - indexValue + newIntensity; - bloodLeakZeroingStatus.intensityMovingAverage = bloodLeakZeroingStatus.intensityRunningSum >> BLD_SHIFT_BITS_BY_4_FOR_AVERAGING; + bloodLeakZeroingStatus.intensityMovingAverage = bloodLeakZeroingStatus.intensityRunningSum / BLD_ZERO_MVG_AVG_NUM_OF_SAMPLES; bloodLeakZeroingStatus.rawIntensityNextIndex = INC_WRAP( index, 0, BLD_ZERO_MVG_AVG_NUM_OF_SAMPLES - 1 ); } } @@ -1699,38 +1698,24 @@ *************************************************************************/ static void checkBloodLeakDrift( void ) { - BOOL isDriftInRange = TRUE; + BOOL isZeroingNeeded = TRUE; U32 setPoint = bloodLeakEmbModeCmd[ SP_EMB_MODE_CMD ].commandResp; - F32 driftUpper = setPoint * BLD_MAX_INTENSITY_OUT_OF_RANGE; - F32 driftLower = setPoint * BLD_MIN_INTENSITY_OUT_OF_RANGE; + F32 driftUpper = BLD_NOMINAL_INTENSITY - ( setPoint * BLD_MAX_INTENSITY_OUT_OF_RANGE ); + F32 driftLower = BLD_NOMINAL_INTENSITY - ( setPoint * BLD_MIN_INTENSITY_OUT_OF_RANGE ); F32 intensityDrift = BLD_NOMINAL_INTENSITY - bloodLeakZeroingStatus.intensityMovingAverage; - BOOL isZeroingAllowed = didTimeout( bloodLeakZeroingStatus.lastZeroingStartTimeMS, BLD_ZERO_INTERVAL_MS ); + BOOL isZeroingAllowed = didTimeout( bloodLeakZeroingStatus.lastZeroingStartTimeMS, BLD_ZERO_MIN_INTERVAL_MS ); - isDriftInRange &= ( intensityDrift <= driftUpper ? TRUE : FALSE ); - isDriftInRange &= ( intensityDrift >= driftLower ? TRUE : FALSE ); + isZeroingNeeded &= ( intensityDrift <= driftUpper ? TRUE : FALSE ); + isZeroingNeeded &= ( intensityDrift >= driftLower ? TRUE : FALSE ); - if ( TRUE == isDriftInRange ) + if ( FALSE == isZeroingNeeded ) { - if ( FALSE == bloodLeakZeroingStatus.hasDriftTimerBeenSet ) - { - bloodLeakZeroingStatus.driftInRangeStartTimeMS = getMSTimerCount(); - bloodLeakZeroingStatus.hasDriftTimerBeenSet = TRUE; - } - } - else - { bloodLeakZeroingStatus.driftInRangeStartTimeMS = getMSTimerCount(); - bloodLeakZeroingStatus.hasDriftTimerBeenSet = FALSE; } if ( ( TRUE == isZeroingAllowed ) && ( TRUE == didTimeout( bloodLeakZeroingStatus.driftInRangeStartTimeMS, BLD_ZERO_IN_RANGE_DRIFT_TIMEOUT_MS ) ) ) { - BOOL status = zeroBloodLeak(); - - if ( TRUE == status ) - { - bloodLeakZeroingStatus.lastZeroingStartTimeMS = getMSTimerCount(); - } + zeroBloodLeak(); } }