Index: firmware/App/Modes/ModeDrain.c =================================================================== diff -u -ra1452dc7f16d37db53930c3d73992098709d7915 -r24dd186948c13ae8e1ff88c14cc4f478e739ee0b --- firmware/App/Modes/ModeDrain.c (.../ModeDrain.c) (revision a1452dc7f16d37db53930c3d73992098709d7915) +++ firmware/App/Modes/ModeDrain.c (.../ModeDrain.c) (revision 24dd186948c13ae8e1ff88c14cc4f478e739ee0b) @@ -15,6 +15,7 @@ * ***************************************************************************/ +#include "ConcentratePumps.h" #include "ConductivitySensors.h" #include "DrainPump.h" #include "Heaters.h" @@ -46,15 +47,23 @@ #define DELAY_RES_DRAIN_VALVE_MS 1000 ///< Delay reservoir drain valve open by 1 second. #define DELAY_DRAIN_PUMP_MS 2000 ///< Delay drain pump on by 2 seconds. +/// 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 * -1 ) + // ********** 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 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 handleDrainState( void ); static DG_DRAIN_STATE_T handleTareState( void ); +static DG_DRAIN_STATE_T handleRinseState( void ); /*********************************************************************//** * @brief @@ -67,6 +76,8 @@ { drainState = DG_DRAIN_STATE_START; drainEmptyTareTimerCtr = 0; + rinseConcentrateLines = FALSE; + rinseConcentrateLinesTimerCtr = 0; } /*********************************************************************//** @@ -135,6 +146,10 @@ drainState = handleTareState(); 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; @@ -146,6 +161,31 @@ /*********************************************************************//** * @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; +} + +/*********************************************************************//** + * @brief * The handleDrainState function handles the drain state of the drain mode * state machine. * @details Inputs: none @@ -201,25 +241,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; } /**@}*/ Index: firmware/App/Modes/ModeDrain.h =================================================================== diff -u -r54f45c387430e440ab4607451fc84dea61f273f1 -r24dd186948c13ae8e1ff88c14cc4f478e739ee0b --- firmware/App/Modes/ModeDrain.h (.../ModeDrain.h) (revision 54f45c387430e440ab4607451fc84dea61f273f1) +++ firmware/App/Modes/ModeDrain.h (.../ModeDrain.h) (revision 24dd186948c13ae8e1ff88c14cc4f478e739ee0b) @@ -38,6 +38,7 @@ U32 execDrainMode( void ); // execute the drain mode state machine DG_DRAIN_STATE_T getCurrentDrainState( void ); // get the current state of the drain mode. +void signalDrainModeRinseConcentrateLines( BOOL rinse ); // Signal drain mode to rinse concentrate lines. /**@}*/ Index: firmware/App/Services/Reservoirs.c =================================================================== diff -u -rcbcd41ec1ac2d5ae6446ec206ed6991a5306c249 -r24dd186948c13ae8e1ff88c14cc4f478e739ee0b --- firmware/App/Services/Reservoirs.c (.../Reservoirs.c) (revision cbcd41ec1ac2d5ae6446ec206ed6991a5306c249) +++ firmware/App/Services/Reservoirs.c (.../Reservoirs.c) (revision 24dd186948c13ae8e1ff88c14cc4f478e739ee0b) @@ -18,6 +18,7 @@ #include // for memcpy() #include "LoadCell.h" +#include "ModeDrain.h" #include "ModeGenIdle.h" #include "OperationModes.h" #include "Reservoirs.h" @@ -327,6 +328,7 @@ { drainVolumeTargetMl.data = drainCmd.targetVolume; tareLoadCellRequest = drainCmd.tareLoadCell; + signalDrainModeRinseConcentrateLines( drainCmd.rinseConcentrateLines ); requestNewOperationMode( DG_MODE_DRAI ); cmdResponse.rejected = FALSE; } Index: firmware/App/Services/Reservoirs.h =================================================================== diff -u -re6f3a632890f96a5aa282922d11df148bdd06587 -r24dd186948c13ae8e1ff88c14cc4f478e739ee0b --- firmware/App/Services/Reservoirs.h (.../Reservoirs.h) (revision e6f3a632890f96a5aa282922d11df148bdd06587) +++ firmware/App/Services/Reservoirs.h (.../Reservoirs.h) (revision 24dd186948c13ae8e1ff88c14cc4f478e739ee0b) @@ -46,8 +46,9 @@ /// Drain command data structure. typedef struct { - U32 targetVolume; ///< Target volume to drain to (in mL) - BOOL tareLoadCell; ///< Flag to tare load call + U32 targetVolume; ///< Target volume to drain to (in mL) + BOOL tareLoadCell; ///< Flag to tare load cell or not + BOOL rinseConcentrateLines; ///< Flag indicates to rinse concentrate lines or not } DRAIN_CMD_T; /// DG command response data record.