Index: firmware/App/Modes/ModeStandby.c =================================================================== diff -u -rebbb1f85550a1f9b8f946655f7b2b63f76fbf67d -rd3819286869611f9c02add72a0f8e321598fdf42 --- firmware/App/Modes/ModeStandby.c (.../ModeStandby.c) (revision ebbb1f85550a1f9b8f946655f7b2b63f76fbf67d) +++ firmware/App/Modes/ModeStandby.c (.../ModeStandby.c) (revision d3819286869611f9c02add72a0f8e321598fdf42) @@ -19,8 +19,10 @@ #include "CPLD.h" #include "DrainPump.h" #include "Heaters.h" +#include "ModeFault.h" #include "ModeStandby.h" #include "OperationModes.h" +#include "Pressures.h" #include "Reservoirs.h" #include "ROPump.h" #include "SystemComm.h" @@ -49,10 +51,12 @@ static BOOL flushFilterRequest = FALSE; ///< Flag indicating HD has requested to flush filters static BOOL endSampleWaterRequest = FALSE; ///< Flag indicating HD has requested to end sample water -static BOOL pendingStartDGRequest = FALSE; ///< Flag indicating HD has requested DG start (go to re-circulate mode). +static BOOL pendingStartDGRequest = FALSE; ///< Flag indicating HD has requested DG start (go to generation idle mode). static U32 waterSampleStartTime = 0; ///< Time stamp for start of water sample state. static U32 filterFlushStartTime = 0; ///< Time stamp for start of filter flush state. static U32 filterFlushPublishTimerCounter = 0; ///< Filter flush data publish timer counter. +/// Filter flush time period in ms. +static OVERRIDE_U32_T filterFlushTimePeriod = { FILTER_FLUSH_TIME_MS, FILTER_FLUSH_TIME_MS, 0, 0 }; // ********** private function prototypes ********** @@ -94,27 +98,7 @@ // re-initialize standby mode each time we transition to standby mode initStandbyMode(); - // set initial actuator states - setValveState( VRF, VALVE_STATE_R2_C_TO_NO ); - setValveState( VRI, VALVE_STATE_R1_C_TO_NO ); - setValveState( VRD, VALVE_STATE_R2_C_TO_NO ); - setValveState( VRO, VALVE_STATE_R1_C_TO_NO ); - setValveState( VPO, VALVE_STATE_NOFILL_C_TO_NO ); - setValveState( VRC, VALVE_STATE_DRAIN_C_TO_NO ); - setValveState( VDR, VALVE_STATE_DRAIN_C_TO_NO ); - setValveState( VPI, VALVE_STATE_CLOSED ); - setValveState( VSP, VALVE_STATE_CLOSED ); - - signalROPumpHardStop(); - signalDrainPumpHardStop(); - stopPrimaryHeater(); - stopTrimmerHeater(); - requestConcentratePumpsOff( CONCENTRATEPUMPS_CP1_ACID ); - requestConcentratePumpsOff( CONCENTRATEPUMPS_CP2_BICARB ); - - // UV off - turnOffUVReactor( INLET_UV_REACTOR ); - turnOffUVReactor( OUTLET_UV_REACTOR ); + deenergizeActuators(); } /*********************************************************************//** @@ -181,13 +165,13 @@ flushFilterRequest = FALSE; filterFlushStartTime = getMSTimerCount(); setValveState( VPI, VALVE_STATE_OPEN ); - setValveState( VPD, VALVE_STATE_OPEN ); // TODO: VPD drain state is closed for V3 + setValveState( VPD, VALVE_STATE_OPEN_C_TO_NC ); state = DG_STANDBY_MODE_STATE_FLUSH_FILTER; } else if ( TRUE == pendingStartDGRequest ) { pendingStartDGRequest = FALSE; - requestNewOperationMode( DG_MODE_CIRC ); + requestNewOperationMode( DG_MODE_GENE ); } return state; @@ -204,30 +188,43 @@ static DG_STANDBY_MODE_STATE_T handleStandbyFlushFilterState( void ) { DG_STANDBY_MODE_STATE_T state = DG_STANDBY_MODE_STATE_FLUSH_FILTER; + U32 const filterFlushTimePeriod_ms = getU32OverrideValue( &filterFlushTimePeriod ); - if ( TRUE == didTimeout( filterFlushStartTime, FILTER_FLUSH_TIME_MS ) ) + checkInletPressure(); + + if ( TRUE == didTimeout( filterFlushStartTime, filterFlushTimePeriod_ms ) ) { + setValveState( VPI, VALVE_STATE_CLOSED ); state = DG_STANDBY_MODE_STATE_FLUSH_FILTER_IDLE; } if ( FILTER_FLUSH_DATA_PUBLISH_INTERVAL <= filterFlushPublishTimerCounter++ ) { - U32 const timeout = FILTER_FLUSH_TIME_MS / MS_PER_SECOND; + U32 const timeout = filterFlushTimePeriod_ms / MS_PER_SECOND; U32 const countdown = timeout - ( calcTimeSince( filterFlushStartTime ) / MS_PER_SECOND ); filterFlushPublishTimerCounter = 0; broadcastFilterFlushData( timeout, countdown ); } + if ( TRUE == endSampleWaterRequest ) + { + endSampleWaterRequest = FALSE; + setValveState( VPI, VALVE_STATE_CLOSED ); + setValveState( VPD, VALVE_STATE_CLOSED ); + state = DG_STANDBY_MODE_STATE_IDLE; + } + return state; } /*********************************************************************//** * @brief - * The handleStandbyFlushFilterIdleState function executes the flush filter state - * of the standby mode state machine. - * @details Inputs: filterFLushStartTime - * @details Outputs: Flushed the filters + * The handleStandbyFlushFilterIdleState function executes the flush filter + * idle state of the standby mode state machine. + * @details Inputs: filterFLushStartTime, startSampleWaterRequest, endSampleWaterRequest + * @details Outputs: Flushed the filters, startSampleWaterRequest, endSampleWaterRequest, + * waterSampleStartTime * @return the next state *************************************************************************/ static DG_STANDBY_MODE_STATE_T handleStandbyFlushFilterIdleState( void ) @@ -245,8 +242,9 @@ if ( TRUE == endSampleWaterRequest ) { + endSampleWaterRequest = FALSE; setValveState( VPI, VALVE_STATE_CLOSED ); - setValveState( VPD, VALVE_STATE_CLOSED ); + setValveState( VPD, VALVE_STATE_DRAIN_C_TO_NO ); state = DG_STANDBY_MODE_STATE_IDLE; } @@ -268,8 +266,10 @@ // After HD requests to stop or 10 seconds has elapsed, close and return to idle state if ( ( TRUE == stopSampleWaterRequest ) || ( TRUE == didTimeout( waterSampleStartTime, MAX_WATER_SAMPLE_TIME_MS ) ) ) { + stopSampleWaterRequest = FALSE; setValveState( VSP, VALVE_STATE_CLOSED ); - setValveState( VPD, VALVE_STATE_OPEN ); // TODO: VPD drain state is closed for V3 + + setValveState( VPD, VALVE_STATE_DRAIN_C_TO_NO ); state = DG_STANDBY_MODE_STATE_FLUSH_FILTER_IDLE; } @@ -321,7 +321,7 @@ break; case SAMPLE_WATER_CMD_END: - if ( ( DG_MODE_STAN == getCurrentOperationMode() ) && ( DG_STANDBY_MODE_STATE_FLUSH_FILTER_IDLE == standbyState ) ) + if ( DG_MODE_STAN == getCurrentOperationMode() ) { endSampleWaterRequest = TRUE; cmdResponse.rejected = FALSE; @@ -339,7 +339,7 @@ /*********************************************************************//** * @brief - * The requestDGStart function handles an HD request to start (go to re-circulate mode). + * The requestDGStart function handles an HD request to start (go to generation idle mode). * @details Inputs: standbyState * @details Outputs: pendingSampleWaterRequest * @return TRUE if request accepted, FALSE if not. @@ -359,6 +359,29 @@ /*********************************************************************//** * @brief + * The startDGFlush function starts DG flush mode. + * @details Inputs: standbyState + * @details Outputs: none + * @return: TRUE if the switch was successful, otherwise FALSE + *************************************************************************/ +BOOL startDGFlush( void ) +{ + BOOL result = FALSE; + + // If DG is in standby mode or in the solo mode and the standby mode is in Idle state, request DG flush + if ( ( DG_MODE_STAN == getCurrentOperationMode() && DG_STANDBY_MODE_STATE_IDLE == standbyState ) || + DG_MODE_SOLO == getCurrentOperationMode() ) + { + requestNewOperationMode( DG_MODE_FLUS ); + + result = TRUE; + } + + return result; +} + +/*********************************************************************//** + * @brief * The startDGHeatDisinfect function starts heat disinfect mode. * @details Inputs: standbyState * @details Outputs: none @@ -373,7 +396,28 @@ ( DG_MODE_SOLO == getCurrentOperationMode() ) ) { requestNewOperationMode( DG_MODE_HEAT ); + status = TRUE; + } + return status; +} + +/*********************************************************************//** + * @brief + * The startDGChemicalDisinfect function starts chemical disinfect mode. + * @details Inputs: standbyState + * @details Outputs: none + * @return: TRUE if the switch was successful + *************************************************************************/ +BOOL startDGChemicalDisinfect( void ) +{ + BOOL status = FALSE; + + // If DG is in standby mode and the standby mode is in Idle, request chemical disinfect + // Chemical disinfect cannot be run in solo mode because the user has to confirm that the acid is inserted or removed + //if ( ( DG_MODE_STAN == getCurrentOperationMode() ) && ( DG_STANDBY_MODE_STATE_IDLE == standbyState ) ) TODO un-comment this line. This is commented to be able to run chemical without HD for development + { + requestNewOperationMode( DG_MODE_CHEM ); status = TRUE; } @@ -392,4 +436,55 @@ return standbyState; } + +/************************************************************************* + * TEST SUPPORT FUNCTIONS + *************************************************************************/ + + +/*********************************************************************//** + * @brief + * The testSetFilterFlushTimePeriodOverride function overrides the filter + * flush time period. + * @details Inputs: none + * @details Outputs: filterFlushTimePeriod + * @param value override concentrate pump data publish interval with (in ms) + * @return TRUE if override successful, FALSE if not + *************************************************************************/ +BOOL testSetFilterFlushTimePeriodOverride( U32 value ) +{ + BOOL result = FALSE; + + if ( TRUE == isTestingActivated() ) + { + result = TRUE; + filterFlushTimePeriod.override = OVERRIDE_KEY; + filterFlushTimePeriod.ovData = value; + } + + return result; +} + +/*********************************************************************//** + * @brief + * The testResetFilterFlushTimePeriodOverride function resets the + * override of the filter flush time period. + * @details Inputs: none + * @details Outputs: filterFlushTimePeriod + * @return TRUE if override reset successful, FALSE if not + *************************************************************************/ +BOOL testResetFilterFlushTimePeriodOverride( void ) +{ + BOOL result = FALSE; + + if ( TRUE == isTestingActivated() ) + { + result = TRUE; + filterFlushTimePeriod.override = OVERRIDE_RESET; + filterFlushTimePeriod.ovData = filterFlushTimePeriod.ovInitData; + } + + return result; +} + /**@}*/