Index: firmware/App/Modes/TreatmentStop.c =================================================================== diff -u -rc46815918e7cf33e8736f180094843758f1e21b2 -r4151ee46ace3cc66b6b7c0f276040889fe0d75e6 --- firmware/App/Modes/TreatmentStop.c (.../TreatmentStop.c) (revision c46815918e7cf33e8736f180094843758f1e21b2) +++ firmware/App/Modes/TreatmentStop.c (.../TreatmentStop.c) (revision 4151ee46ace3cc66b6b7c0f276040889fe0d75e6) @@ -17,7 +17,9 @@ #include "AirTrap.h" #include "BloodFlow.h" -#include "Buttons.h" +//#include "Buttons.h" +#include "DGInterface.h" +#include "DialInFlow.h" #include "DialOutFlow.h" #include "ModeTreatment.h" #include "OperationModes.h" @@ -31,10 +33,13 @@ // ********** private data ********** -TREATMENT_STOP_STATE_T currentTxStopState; ///< Current treatment stop state. +static TREATMENT_STOP_STATE_T currentTxStopState; ///< Current treatment stop state. // ********** private function prototypes ********** +static TREATMENT_STOP_STATE_T handleTreatmentStopRecircState( void ); +static TREATMENT_STOP_STATE_T handleTreatmentStopNoRecircState( void ); + /*********************************************************************//** * @brief * The initTreatmentStop function initializes the Treatment Stop sub-mode @@ -63,6 +68,9 @@ signalDialOutPumpHardStop(); // TODO - stop Heparin pump + // Start out assuming we re-circulate dialysate while stopped + setDialInPumpTargetFlowRate( DIALYSATE_FLOW_RATE_FOR_RECIRC, MOTOR_DIR_FORWARD, PUMP_CONTROL_MODE_CLOSED_LOOP ); + // Set valves to safe state setValvePosition( VDI, VALVE_POSITION_C_CLOSE ); setValvePosition( VDO, VALVE_POSITION_C_CLOSE ); @@ -112,9 +120,70 @@ *************************************************************************/ void execTreatmentStop( void ) { - // TODO - implement + switch ( currentTxStopState ) + { + case TREATMENT_STOP_RECIRC_STATE: + currentTxStopState = handleTreatmentStopRecircState(); + break; + + case TREATMENT_STOP_NO_RECIRC_STATE: + currentTxStopState = handleTreatmentStopNoRecircState(); + break; + + default: + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_HD_SOFTWARE_FAULT, SW_FAULT_ID_TREATMENT_STOP_INVALID_STATE, currentTxStopState ); + break; + } } +/*********************************************************************//** + * @brief + * The handleTreatmentStopRecircState function handles the re-circ dialysate + * state operations. + * @details Inputs: active alarms + * @details Outputs: dialysate re-circulation stopped if active alarm blocks + * @return next treatment stop state + *************************************************************************/ +static TREATMENT_STOP_STATE_T handleTreatmentStopRecircState( void ) +{ + TREATMENT_STOP_STATE_T result = TREATMENT_STOP_RECIRC_STATE; + + // if any active alarm(s) blocks dialysate re-circulation, stop it + if ( TRUE == isDialysateRecircBlocked() ) + { + signalDialInPumpHardStop(); + cmdStopDGTrimmerHeater(); + result = TREATMENT_STOP_NO_RECIRC_STATE; + } + + return result; +} + +/*********************************************************************//** + * @brief + * The handleTreatmentStopNoRecircState function handles the no re-circ dialysate + * state operations. + * @details Inputs: none + * @details Outputs: none + * @return next treatment stop state + *************************************************************************/ +static TREATMENT_STOP_STATE_T handleTreatmentStopNoRecircState( void ) +{ + TREATMENT_STOP_STATE_T result = TREATMENT_STOP_NO_RECIRC_STATE; + + // nothing to do in this state - alarm user response will take us to appropriate next sub-mode + + return result; +} + +/*********************************************************************//** + * @brief + * The getCurrentTreatmentStopState function returns the current state of the + * treatment stop sub-mode. + * @details Inputs: currentTxStopState + * @details Outputs: none + * @return currentTxStopState + *************************************************************************/ TREATMENT_STOP_STATE_T getCurrentTreatmentStopState( void ) { return currentTxStopState;