Index: firmware/App/Controllers/BloodLeak.c =================================================================== diff -u -r32309398e7ef59471bd624e34ab6b91cdaaf9d24 -r9ded16038a0d6dd844da697aaf03505ec3ed335a --- firmware/App/Controllers/BloodLeak.c (.../BloodLeak.c) (revision 32309398e7ef59471bd624e34ab6b91cdaaf9d24) +++ firmware/App/Controllers/BloodLeak.c (.../BloodLeak.c) (revision 9ded16038a0d6dd844da697aaf03505ec3ed335a) @@ -110,6 +110,7 @@ BLOOD_LEAK_CHECK_SET_POINT_STATE, ///< Check set point state. BLOOD_LEAK_INIT_STATE, ///< Init state. BLOOD_LEAK_CHECK_ZERO_AND_SELF_TEST_STATE, ///< Blood leak check for zero and self test commands state. + BLOOD_LEAK_VERIFY_INTENSITY_AFTER_ZEROING_STATE, ///< Blood leak verify intensity after zeroing state. BLOOD_LEAK_NORMAL_STATE, ///< Normal state. BLOOD_LEAK_RECOVER_BLOOD_DETECT_STATE, ///< Blood leak recover blood detect state. NUM_OF_BLOOD_LEAK_STATES ///< Number of blood leak detector states. @@ -210,6 +211,7 @@ static BLOOD_LEAK_STATE_T handleBloodLeakCheckSetPointState( void ); static BLOOD_LEAK_STATE_T handleBloodLeakInitState( void ); static BLOOD_LEAK_STATE_T handleBloodLeakCheckZeroAndSelfTestState( void ); +static BLOOD_LEAK_STATE_T handleBloodLeakVerifyIntensityAfterZeroingState( void ); static BLOOD_LEAK_STATE_T handleBloodLeakNormalState( void ); static BLOOD_LEAK_STATE_T handleBloodLeakRecoverBloodDetectState( void ); @@ -319,7 +321,7 @@ getNVRecord2Driver( GET_CAL_BLOOD_LEAK_SENSOR, (U08*)&bloodLeakCalRecord, length, 0, ALARM_ID_HD_BLOOD_LEAK_INVALID_CAL_RECORD ); } - processBloodLeakIntensityData(); // TODO is this the right place? + processBloodLeakIntensityData(); switch( bloodLeakState ) { @@ -339,6 +341,10 @@ bloodLeakState = handleBloodLeakCheckZeroAndSelfTestState(); break; + case BLOOD_LEAK_VERIFY_INTENSITY_AFTER_ZEROING_STATE: + bloodLeakState = handleBloodLeakVerifyIntensityAfterZeroingState(); + break; + case BLOOD_LEAK_NORMAL_STATE: bloodLeakState = handleBloodLeakNormalState(); break; @@ -462,21 +468,6 @@ return status; } -BLOOD_LEAK_INTENSITY_CHECK_T getBloodLeakIntensityStatusAfterZeroing( void ) -{ - BLOOD_LEAK_INTENSITY_CHECK_T status = BLOOD_LEAK_INTENSITY_WAIT_FOR_FRESH_DATA; - - if ( TRUE == bloodLeakEmbModeCmd[ I_EMB_MODE_CMD ].isCmdRespRdy ) - { - U32 intensity = bloodLeakEmbModeCmd[ I_EMB_MODE_CMD ].commandResp; - - status = ( abs( BLD_NOMINAL_INTENSITY - intensity ) <= BLD_MAX_INTENSITY_DRIFT_AFTER_ZEROING ? BLOOD_LEAK_INTENSITY_IN_RANGE : - BLOOD_LEAK_INTENSITY_OUT_OF_RANGE ); - } - - return status; -} - /*********************************************************************//** * @brief * The exitBloodLeakNormalState requests that the blood leak sensor to exit @@ -700,26 +691,59 @@ // Pass self-test if entire sequence was successful if ( FALSE == hasCmdSqncFailed ) { - // Done with zero sequence, transition to other states - zeroBloodLeakReset(); - bloodLeakZeroingStatus.lastZeroingStartTimeMS = getMSTimerCount(); - bloodLeakSelfTestStatus = SELF_TEST_STATUS_PASSED; - state = BLOOD_LEAK_NORMAL_STATE; + state = BLOOD_LEAK_VERIFY_INTENSITY_AFTER_ZEROING_STATE; } // If not successful, retry if we've not run out else { bloodLeakSelfTestStatus = SELF_TEST_STATUS_FAILED; state = BLOOD_LEAK_INIT_STATE; } - SEND_EVENT_WITH_2_U32_DATA( HD_EVENT_BLOOD_LEAK_SELF_TEST_RESULT, bloodLeakSelfTestStatus, state ); + SEND_EVENT_WITH_2_U32_DATA( HD_EVENT_BLOOD_LEAK_SELF_TEST_RESULT, bloodLeakSelfTestStatus, state ) } return state; } /*********************************************************************//** * @brief + * The handleBloodLeakVerifyIntensityAfterZeroingState function checks the + * blood leak sensor's intensity after zeroing the sensor. + * @details Inputs: bloodLeakEmbModeCmd + * @details Outputs: bloodLeakSelfTestStatus + * @return next state + *************************************************************************/ +static BLOOD_LEAK_STATE_T handleBloodLeakVerifyIntensityAfterZeroingState( void ) +{ + BLOOD_LEAK_STATE_T state = BLOOD_LEAK_VERIFY_INTENSITY_AFTER_ZEROING_STATE; + + if ( TRUE == bloodLeakEmbModeCmd[ I_EMB_MODE_CMD ].isCmdRespRdy ) + { + U32 intensity = bloodLeakEmbModeCmd[ I_EMB_MODE_CMD ].commandResp; + + state = BLOOD_LEAK_INIT_STATE; + bloodLeakSelfTestStatus = SELF_TEST_STATUS_FAILED; + + if ( abs( BLD_NOMINAL_INTENSITY - intensity ) <= BLD_MAX_INTENSITY_DRIFT_AFTER_ZEROING ) + { + // Done with zero sequence, transition to other states + zeroBloodLeakReset(); + bloodLeakZeroingStatus.lastZeroingStartTimeMS = getMSTimerCount(); + bloodLeakSelfTestStatus = SELF_TEST_STATUS_PASSED; + state = BLOOD_LEAK_NORMAL_STATE; + + if ( TRUE == isAlarmActive( ALARM_ID_HD_BLOOD_LEAK_RECOVERING_PLEASE_WAIT ) ) + { + state = BLOOD_LEAK_RECOVER_BLOOD_DETECT_STATE; + } + } + } + + return state; +} + +/*********************************************************************//** + * @brief * The handleBloodLeakNormalState function handles the Blood Leak module * in normal state. * @details Inputs: bloodLeakStatus, bloodLeakPersistenceCtr,