Index: firmware/App/Modes/ModeDrain.c =================================================================== diff -u -r26f63d0260a3c35277e3e6dbca3573c253775318 -r1b95ae077de1d01a314be8cc011662ab508fba10 --- firmware/App/Modes/ModeDrain.c (.../ModeDrain.c) (revision 26f63d0260a3c35277e3e6dbca3573c253775318) +++ firmware/App/Modes/ModeDrain.c (.../ModeDrain.c) (revision 1b95ae077de1d01a314be8cc011662ab508fba10) @@ -15,6 +15,7 @@ * ***************************************************************************/ +#include "ConcentratePumps.h" #include "ConductivitySensors.h" #include "DrainPump.h" #include "Heaters.h" @@ -49,16 +50,24 @@ #define DIALYSATE_DRAIN_TIME_OUT ( 2 * SEC_PER_MIN * MS_PER_SECOND ) ///< Dialysate drain time out. +/// Time period to wait for concentrate lines to rinse. +#define RINSE_CONCENTRATE_LINES_WAIT ( 25 * MS_PER_SECOND / TASK_GENERAL_INTERVAL ) +/// Reserver the concentrate speed to rinse out concentrate lines. +#define RINSE_SPEED ( ( CONCENTRATE_PUMP_MAX_SPEED - 3.0 ) * -1.0 ) + // ********** private data ********** static DG_DRAIN_STATE_T drainState; ///< Currently active drain state. static U32 drainEmptyTareTimerCtr; ///< Timer counter for delay between drain complete and load cell tare. static U32 dialysateDrainStartTime; ///< Dialysate drain start time. +static BOOL rinseConcentrateLines; ///< Flag indicates to rinse concentrate lines. +static U32 rinseConcentrateLinesTimerCtr; ///< Timer counter for rinsing concentrate lines. // ********** private function prototypes ********** static DG_DRAIN_STATE_T handleDrainStateStart( void ); static DG_DRAIN_STATE_T handleDrainStateDrain( void ); static DG_DRAIN_STATE_T handleDrainStateTare( void ); +static DG_DRAIN_STATE_T handleRinseState( void ); /*********************************************************************//** * @brief @@ -69,9 +78,11 @@ *************************************************************************/ void initDrainMode( void ) { - drainState = DG_DRAIN_STATE_START; - drainEmptyTareTimerCtr = 0; - dialysateDrainStartTime = 0; + drainState = DG_DRAIN_STATE_START; + drainEmptyTareTimerCtr = 0; + dialysateDrainStartTime = 0; + rinseConcentrateLines = FALSE; + rinseConcentrateLinesTimerCtr = 0; } /*********************************************************************//** @@ -141,6 +152,10 @@ drainState = handleDrainStateTare(); break; + case DG_DRAIN_STATE_RINSE: + drainState = handleRinseState(); + break; + default: SET_ALARM_WITH_2_U32_DATA( ALARM_ID_DG_SOFTWARE_FAULT, SW_FAULT_ID_DRAIN_MODE_INVALID_EXEC_STATE, drainState ) drainState = DG_DRAIN_STATE_START; @@ -152,6 +167,30 @@ /*********************************************************************//** * @brief + * The getCurrentDrainState function returns the current state of the drain mode. + * @details Inputs: drainState + * @details Outputs: none + * @return the current state of drain mode. + *************************************************************************/ +DG_DRAIN_STATE_T getCurrentDrainState( void ) +{ + return drainState; +} + +/*********************************************************************//** + * @brief + * The signalDrainModeRinseConcentrateLines function sets the flag for drain + * mode to rinse concentrate lines. + * @details Inputs: none + * @details Outputs: rinseConcentrateLines + * @return none + *************************************************************************/ +void signalDrainModeRinseConcentrateLines( BOOL rinse ) +{ + rinseConcentrateLines = rinse; +} + +/*********************************************************************//** * The handleDrainStateStart function handles the drain start state of * the drain mode state machine. * @details Inputs: none @@ -187,7 +226,7 @@ // if we have reached our target drain to volume (by weight) or cannot drain anymore, we are done draining - go back to generation idle mode if ( TRUE == hasTargetDrainVolumeBeenReached( inactiveReservoir, DRAIN_WEIGHT_UNCHANGE_TIMEOUT ) ) { - setDrainPumpTargetRPM( 0 ); + signalDrainPumpHardStop(); if ( DG_RESERVOIR_1 == inactiveReservoir ) { @@ -234,25 +273,52 @@ { drainEmptyTareTimerCtr = 0; tareLoadCellsAtEmpty( inactiveReservoir ); - requestNewOperationMode( DG_MODE_GENE ); setValveState( VRD1, VALVE_STATE_CLOSED ); setValveState( VRD2, VALVE_STATE_CLOSED ); + + if ( TRUE == rinseConcentrateLines ) + { + setConcentratePumpTargetSpeed( CONCENTRATEPUMPS_CP1_ACID, RINSE_SPEED ); + setConcentratePumpTargetSpeed( CONCENTRATEPUMPS_CP2_BICARB, RINSE_SPEED ); + requestConcentratePumpOn( CONCENTRATEPUMPS_CP1_ACID ); + requestConcentratePumpOn( CONCENTRATEPUMPS_CP2_BICARB ); + } + rinseConcentrateLinesTimerCtr = 0; + result = DG_DRAIN_STATE_RINSE; } return result; } /*********************************************************************//** * @brief - * The getCurrentDrainState function returns the current state of the drain mode. - * @details Inputs: drainState - * @details Outputs: none - * @return the current state of drain mode. + * The handleRinseState function handles the tare state of the drain mode + * state machine. + * @details Inputs: drainEmptyTareTimerCtr + * @details Outputs: drainEmptyTareTimerCtr + * @return the next state *************************************************************************/ -DG_DRAIN_STATE_T getCurrentDrainState( void ) +static DG_DRAIN_STATE_T handleRinseState( void ) { - return drainState; + DG_DRAIN_STATE_T result = DG_DRAIN_STATE_RINSE; + + if ( TRUE == rinseConcentrateLines ) + { + if ( ++rinseConcentrateLinesTimerCtr > RINSE_CONCENTRATE_LINES_WAIT ) + { + rinseConcentrateLinesTimerCtr = 0; + requestConcentratePumpOff( CONCENTRATEPUMPS_CP1_ACID ); + requestConcentratePumpOff( CONCENTRATEPUMPS_CP2_BICARB ); + requestNewOperationMode( DG_MODE_GENE ); + } + } + else + { + requestNewOperationMode( DG_MODE_GENE ); + } + + return result; } /**@}*/