Index: firmware/App/Modes/ModeDrain.c =================================================================== diff -u -r4c20f6a3d8c8ff33d2dff4ba27e0732c7614378b -ra1b8dbb69c4bd2f0cc22e62bede7015c9307d378 --- firmware/App/Modes/ModeDrain.c (.../ModeDrain.c) (revision 4c20f6a3d8c8ff33d2dff4ba27e0732c7614378b) +++ firmware/App/Modes/ModeDrain.c (.../ModeDrain.c) (revision a1b8dbb69c4bd2f0cc22e62bede7015c9307d378) @@ -1,24 +1,29 @@ /************************************************************************** - * - * Copyright (c) 2019-2020 Diality Inc. - All Rights Reserved. - * - * THIS CODE MAY NOT BE COPIED OR REPRODUCED IN ANY FORM, IN PART OR IN - * WHOLE, WITHOUT THE EXPLICIT PERMISSION OF THE COPYRIGHT OWNER. - * - * @file ModeDrain.c - * - * @date 20-Dec-2019 - * @author L. Baloa - * - * @brief Top-level state machine for the drain mode. - * - **************************************************************************/ +* +* Copyright (c) 2019-2020 Diality Inc. - All Rights Reserved. +* +* THIS CODE MAY NOT BE COPIED OR REPRODUCED IN ANY FORM, IN PART OR IN +* WHOLE, WITHOUT THE EXPLICIT PERMISSION OF THE COPYRIGHT OWNER. +* +* @file ModeDrain.c +* +* @author (last) Quang Nguyen +* @date (last) 24-Aug-2020 +* +* @author (original) Leonardo Baloa +* @date (original) 20-Dec-2019 +* +***************************************************************************/ +#include "ConductivitySensors.h" #include "DrainPump.h" -#include "LoadCell.h" #include "ModeDrain.h" #include "OperationModes.h" +#include "Pressures.h" #include "Reservoirs.h" +#include "ROPump.h" +#include "TaskGeneral.h" +#include "TemperatureSensors.h" #include "Valves.h" /** @@ -28,22 +33,25 @@ // ********** private definitions ********** -#define TARGET_DRAIN_PUMP_RPM 2800 ///< Target drain pump speed (in RPM). +#define TARGET_DRAIN_PUMP_RPM 1800 ///< Target drain pump speed (in RPM). +#define DRAIN_WEIGH_UNCHANGE_TIMEOUT ( 2 * MS_PER_SECOND ) ///< Time period of unchanged weight during draining before timeout. +#define TARGET_RO_PRESSURE_PSI 130 ///< Target pressure for RO pump. +#define TARGET_RO_FLOW_RATE_L 0.3 ///< Target flow rate for RO pump. + // ********** private data ********** -static DG_DRAIN_STATE_T drainState = DG_DRAIN_STATE_START; ///< Currently active drain state. +static DG_DRAIN_STATE_T drainState = DG_DRAIN_STATE_START; ///< Currently active drain state. // ********** private function prototypes ********** static DG_DRAIN_STATE_T handleDrainState( void ); /*********************************************************************//** * @brief - * The initOpParamsMode function initializes the Drain Mode module. - * @details - * Inputs : none - * Outputs : Operating Parameters Mode module initialized. + * The initDrainMode function initializes the drain mode module. + * @details Inputs: none + * @details Outputs: drainState * @return none *************************************************************************/ void initDrainMode( void ) @@ -53,11 +61,9 @@ /*********************************************************************//** * @brief - * The transitionToDrainMode function prepares for transition to drain \n - * mode. - * @details - * Inputs : none - * Outputs : + * The transitionToDrainMode function prepares for transition to drain mode. + * @details Inputs: none + * @details Outputs: Drain mode initialized * @return none *************************************************************************/ void transitionToDrainMode( void ) @@ -67,19 +73,25 @@ // set initial actuator states setValveState( VDR, VALVE_STATE_DRAIN_C_TO_NO ); - setDrainPumpTargetSpeed( TARGET_DRAIN_PUMP_RPM ); + setDrainPumpTargetRPM( TARGET_DRAIN_PUMP_RPM ); + setROPumpTargetFlowRate( TARGET_RO_FLOW_RATE_L, TARGET_RO_PRESSURE_PSI ); } /*********************************************************************//** * @brief - * The execDrainMode function executes the Drain Mode state machine. - * @details - * Inputs : none - * Outputs : + * The execDrainMode function executes the drain mode state machine. + * @details Inputs: drainState + * @details Outputs: Check water quality, drain mode state machine executed * @return current state. *************************************************************************/ U32 execDrainMode( void ) { + // check inlet water conductivity, temperature, pressure, and RO rejection ratio + checkInletWaterConductivity(); + checkInletWaterTemperature(); + checkInletPressure(); + checkRORejectionRatio(); + // execute current drain state switch ( drainState ) { @@ -92,7 +104,7 @@ break; default: - SET_ALARM_WITH_2_U32_DATA( ALARM_ID_SOFTWARE_FAULT, 0, drainState ) // TODO - add s/w fault enum to 1st data param + 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; break; } @@ -102,32 +114,20 @@ /*********************************************************************//** * @brief - * The handleDrainState function handles the drain state of the Drain Mode \n - * state machine. - * @details - * Inputs : none - * Outputs : + * The handleDrainState function handles the drain state of the drain mode state machine. + * @details Inputs: none + * @details Outputs: Drain out from reservoir * @return the next state *************************************************************************/ static DG_DRAIN_STATE_T handleDrainState( void ) { DG_DRAIN_STATE_T result = DG_DRAIN_STATE_DRAIN; - LOAD_CELL_ID_T drainWeightLoadCell = LOAD_CELL_A1; + DG_RESERVOIR_ID_T inactiveReservoir = getInactiveReservoir(); - // determine which load cell to use for drain volume - we want weight of inactive reservoir -#ifndef BETA_V1_BUILD - if ( RESERVOIR_1 == getActiveReservoir() ) -#else - if ( RESERVOIR_2 == getActiveReservoir() ) -#endif + // if we have reached our target drain to volume (by weight) or cannot drain anymore, we are done draining - go back to re-circ mode + if ( hasTargetDrainVolumeBeenReached( inactiveReservoir, DRAIN_WEIGH_UNCHANGE_TIMEOUT ) ) { - drainWeightLoadCell = LOAD_CELL_B1; - } - - // if we've reached our target drain to volume (by weight), we're done draining - go back to re-circ mode - if ( getReservoirDrainVolumeTargetMl() >= getLoadCellFilteredWeight( drainWeightLoadCell ) ) - { - setDrainPumpTargetSpeed( 0 ); + setDrainPumpTargetRPM( 0 ); requestNewOperationMode( DG_MODE_CIRC ); } @@ -136,11 +136,9 @@ /*********************************************************************//** * @brief - * The getCurrentDrainState function returns the current state of the \n - * drain mode. - * @details - * Inputs : drainState - * Outputs : none + * 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 )