Index: firmware/App/Modes/ModeGenIdle.c =================================================================== diff -u -rd03ddbc63925f2e5a5a5ceeba3487992e65a8ecf -r773bd9e1eebab013afa0b303231be73e8016c84c --- firmware/App/Modes/ModeGenIdle.c (.../ModeGenIdle.c) (revision d03ddbc63925f2e5a5a5ceeba3487992e65a8ecf) +++ firmware/App/Modes/ModeGenIdle.c (.../ModeGenIdle.c) (revision 773bd9e1eebab013afa0b303231be73e8016c84c) @@ -44,17 +44,19 @@ #define TARGET_RO_PRESSURE_PSI 130 ///< Target pressure for RO pump. #define TARGET_RO_FLOW_RATE_L 0.3 ///< Target flow rate for RO pump. +#define BAD_FLUSH_FILL_TARGET_VOLUME_ML 1000 ///< Target fill volume in the bad flush fill state. /// The time of HD lost comm before DG transition back to standby. #define HD_LOST_COMM_TIMEOUT_MS (5 * SEC_PER_MIN * MS_PER_SECOND ) // ********** private data ********** -static DG_GEN_IDLE_MODE_STATE_T genIdleState; ///< Currently active generation idle state. -static DG_GEN_IDLE_MODE_BAD_FILL_STATE_T badFillState; ///< Current active bad fill state. -static U32 hdLostCommStartTime_ms = 0; ///< Lost communication with HD start time in ms. -static U32 targetFillVolumeML; ///< Save the target fill volume before calling startFillCmd() -static BOOL handleBadFillFlag; ///< Internal signal flag to handle bad fill +static DG_GEN_IDLE_MODE_STATE_T genIdleState; ///< Currently active generation idle state. +static DG_GEN_IDLE_MODE_BAD_FILL_STATE_T badFillState = DG_HANDLE_BAD_FILL_STATE_START; ///< Initialize bad fill sub-state. +static U32 hdLostCommStartTime_ms = 0; ///< Lost communication with HD start time in ms. +static U32 targetFillVolumeML; ///< Save the target fill volume before calling startFillCmd(). +static BOOL handleBadFillFlag; ///< Internal signal flag to handle bad fill. +static BOOL badAvgConductivityDetected; ///< Bad average conductivity detected. // ********** private function prototypes ********** @@ -82,6 +84,7 @@ hdLostCommStartTime_ms = 0; targetFillVolumeML = 0; handleBadFillFlag = FALSE; + badAvgConductivityDetected = FALSE; } /*********************************************************************//** @@ -157,6 +160,18 @@ /*********************************************************************//** * @brief + * The setBadAvgConductivityDetectedFlag function sets a flag to indicate + * that bad average conductivity is detected. + * @details Inputs: none + * @details Outputs: none + * @param flag to TRUE if bad avg conductivity otherwise FALSE + *************************************************************************/ +void setBadAvgConductivityDetectedFlag( BOOL badAvgConducitivyflag ) +{ + badAvgConductivityDetected = badAvgConducitivyflag; +} +/*********************************************************************//** + * @brief * The execGenIdleMode function executes the generation idle mode state machine. * @details Inputs: genIdleState * @details Outputs: Check water quality, generation idle mode state machine executed @@ -187,7 +202,6 @@ switch ( genIdleState ) { case DG_GEN_IDLE_MODE_STATE_START: - badFillState = DG_HANDLE_BAD_FILL_STATE_START; genIdleState = handleIdleStartState(); break; @@ -220,14 +234,14 @@ { DG_GEN_IDLE_MODE_STATE_T result = DG_GEN_IDLE_MODE_STATE_START; - if ( TRUE == isAvgConductivityOutOfRange() ) + if ( TRUE == badAvgConductivityDetected ) { handleBadFillFlag = TRUE; } if ( TRUE == handleBadFillFlag ) { - result = DG_GEN_IDLE_MODE_STATE_HANDLE_BAD_FILL ; + result = DG_GEN_IDLE_MODE_STATE_HANDLE_BAD_FILL; } else { @@ -279,7 +293,7 @@ badFillState = handleFlushFillState(); break; - case DG_HANDLE_BAD_FILL_STATE_SECOND_DRAIN: // idle 1.2 + case DG_HANDLE_BAD_FILL_STATE_SECOND_DRAIN: // idle 1.2. badFillState = handleSecondDrainState(); break; @@ -310,7 +324,7 @@ *************************************************************************/ static DG_GEN_IDLE_MODE_BAD_FILL_STATE_T handleFirstDrainState( void ) { - DG_GEN_IDLE_MODE_BAD_FILL_STATE_T result = DG_HANDLE_BAD_FILL_STATE_FLUSH_FILL; // after first drain is completed, go to next sub-state + DG_GEN_IDLE_MODE_BAD_FILL_STATE_T result = DG_HANDLE_BAD_FILL_STATE_FLUSH_FILL; // after first drain is completed, go to next bad fill sub-state requestNewOperationMode( DG_MODE_DRAI ); // go to drain mode to empty bad dialysate because this is a bad fill @@ -328,14 +342,13 @@ static DG_GEN_IDLE_MODE_BAD_FILL_STATE_T handleFlushFillState( void ) { DG_GEN_IDLE_MODE_BAD_FILL_STATE_T result = DG_HANDLE_BAD_FILL_STATE_FLUSH_FILL; - U32 fillToVolumeML = 1000; if ( FALSE == isAlarmActive( ALARM_ID_FILL_CONDUCTIVITY_OUT_OF_RANGE ) ) // alarm is no longer active - cleared by user { targetFillVolumeML = getTargetFillVolumeML(); // save the HD target fill volume before command 1000 mL fill volume - startFillCmd( fillToVolumeML, getTargetFillFlowRateLPM() ); + startFillCmd( BAD_FLUSH_FILL_TARGET_VOLUME_ML, getTargetFillFlowRateLPM() ); - if ( TRUE == isAvgConductivityOutOfRange() ) + if ( TRUE == badAvgConductivityDetected ) { result = DG_HANDLE_BAD_FILL_STATE_FIRST_DRAIN; // (idle 1.0) } @@ -397,7 +410,7 @@ // clear wait for dialysate alarm condition to allow resume clearAlarmCondition( ALARM_ID_CREATING_DIALYSATE_PLEASE_WAIT ); // resume option will appear handleBadFillFlag = FALSE; // set flag to FALSE here so next call to idle exec will move to normal flush water state - requestNewOperationMode( DG_MODE_GENE ); // go to generation idle mode + genIdleState = DG_GEN_IDLE_MODE_STATE_START; return result; }