Index: firmware/App/Modes/ModePostTreat.c =================================================================== diff -u -r00f98c3a603917bb25450e7686bc75a34c357e97 -ra57af2726f27208a2de96e9331678caf022d927d --- firmware/App/Modes/ModePostTreat.c (.../ModePostTreat.c) (revision 00f98c3a603917bb25450e7686bc75a34c357e97) +++ firmware/App/Modes/ModePostTreat.c (.../ModePostTreat.c) (revision a57af2726f27208a2de96e9331678caf022d927d) @@ -47,7 +47,8 @@ static BOOL patientDisconnectionConfirmed; ///< Flag indicates user confirms patient disconnection. static BOOL patientDisconnectHandled; ///< Flag indicates patient disconnect actions have been handled static BOOL disposableRemovalConfirmed; ///< Flag indicates user confirms disposable removal. -static DISINFECT_SELECTION_T selectedDisinfectionSelection; ///< Selected disinfection option from UI.static BOOL disinfectionSelectionReceived; +static BOOL ddStandbyCommandSent; ///< Flag indicates DD Standby command has been sent. +static DISINFECT_SELECTION_T selectedDisinfectionSelection; ///< Selected disinfection option from UI. static BOOL disinfectionSelectionReceived; static volatile U32 postTreatmentStateBroadcastTimer; ///< Timer counter for pending power off request. @@ -72,6 +73,7 @@ patientDisconnectionConfirmed = FALSE; patientDisconnectHandled = FALSE; disposableRemovalConfirmed = FALSE; + ddStandbyCommandSent = FALSE; disinfectionSelectionReceived = FALSE; selectedDisinfectionSelection = DISINFECT_SEL_SKIP; postTreatmentStateBroadcastTimer = 0; @@ -244,15 +246,19 @@ retractSyringePump(); } doorClosedRequired( FALSE ); - // NOTE: patientDisconnectionConfirmed is NOT reset because - // Patient Disconnect State needs it to move to next state + + // Patient has been disconnected. DD no longer needs to remain + // in Generate Dialysate mode. + cmdSendDDCommand( DD_CMD_GOTO_POST_GENERATE ); + patientDisconnectHandled = TRUE; } if ( TRUE == patientDisconnectionConfirmed ) { patientDisconnectionConfirmed = FALSE; patientDisconnectHandled = FALSE; - state = TD_POST_TREATMENT_AUTO_EJECT_STATE; + + state = TD_POST_TREATMENT_AUTO_EJECT_STATE; } return state; @@ -285,19 +291,43 @@ /*********************************************************************//** * @brief * The handleDisposableRemovalState function executes the Post-Treatment - * mode Disposable Removal state machine. - * @details \b Inputs: disposableRemovalConfirmed - * @details \b Outputs: processed disposable removal confirmation - * @return next post-treatment mode state + * Disposable Removal state. + * @details \b Inputs: disposableRemovalConfirmed and DD operation mode. + * @details \b Outputs: Requests DD transition from Post-Generate to + * Standby and advances to Disinfection after DD reaches Standby. + * @return Next Post-Treatment mode state. *************************************************************************/ static TD_POST_TREATMENT_STATE_T handleDisposableRemovalState( void ) { TD_POST_TREATMENT_STATE_T state = TD_POST_TREATMENT_DISPOSABLE_REMOVAL_STATE; + DD_CMD_RESPONSE_T ddCmdResp; if ( TRUE == disposableRemovalConfirmed ) { - disposableRemovalConfirmed = FALSE; - state = TD_POST_TREATMENT_DISINFECTION_STATE; + // Wait until DD has completed the transition to Post-Generate + // before requesting DD Standby. + if ( FALSE == ddStandbyCommandSent ) + { + if ( DD_MODE_POSG == getDDOpMode() ) + { + cmdSendDDCommand( DD_CMD_GOTO_STANDBY ); + ddStandbyCommandSent = TRUE; + } + } + else if ( TRUE == getDDCommandResponse( DD_CMD_GOTO_STANDBY, + &ddCmdResp ) ) + { + // Command was accepted. Wait for the DD operation-mode + // broadcast confirming DD has actually reached Standby. + if ( ( FALSE == ddCmdResp.rejected ) && + ( DD_MODE_STAN == getDDOpMode() ) ) + { + disposableRemovalConfirmed = FALSE; + ddStandbyCommandSent = FALSE; + + state = TD_POST_TREATMENT_DISINFECTION_STATE; + } + } } return state; @@ -346,9 +376,6 @@ // Save selected disinfection option in Standby. signalStandbyDisinfectionSelection( command ); - // Request DD transition to Standby. - cmdStopGenerateDialysate(); - // Transition TD to Standby. requestNewOperationMode( MODE_STAN ); }