/************************************************************************** * * 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) 13-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 "Valves.h" #include "TemperatureSensors.h" /** * @addtogroup DGDrainMode * @{ */ // ********** private definitions ********** #define TARGET_DRAIN_PUMP_RPM 2800 ///< Target drain pump speed (in RPM). // ********** private data ********** 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. * @return none *************************************************************************/ void initDrainMode( void ) { drainState = DG_DRAIN_STATE_START; } /*********************************************************************//** * @brief * The transitionToDrainMode function prepares for transition to drain \n * mode. * @details * Inputs : none * Outputs : * @return none *************************************************************************/ void transitionToDrainMode( void ) { // re-initialize each time we transition to drain mode initDrainMode(); // set initial actuator states setValveState( VDR, VALVE_STATE_DRAIN_C_TO_NO ); setDrainPumpTargetSpeed( TARGET_DRAIN_PUMP_RPM ); } /*********************************************************************//** * @brief * The execDrainMode function executes the Drain Mode state machine. * @details * Inputs : none * Outputs : * @return current state. *************************************************************************/ U32 execDrainMode( void ) { // check inlet water conductivity, temperature, and pressure checkInletWaterConductivity( drainState ); checkInletWaterTemperature(); checkInletPressure(); // execute current drain state switch ( drainState ) { case DG_DRAIN_STATE_START: drainState = DG_DRAIN_STATE_DRAIN; break; case DG_DRAIN_STATE_DRAIN: drainState = handleDrainState(); break; default: SET_ALARM_WITH_2_U32_DATA( ALARM_ID_DG_SOFTWARE_FAULT, 0, drainState ) // TODO - add s/w fault enum to 1st data param drainState = DG_DRAIN_STATE_START; break; } return drainState; } /*********************************************************************//** * @brief * The handleDrainState function handles the drain state of the Drain Mode \n * state machine. * @details * Inputs : none * Outputs : * @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; // determine which load cell to use for drain volume - we want weight of inactive reservoir if ( RESERVOIR_1 == getActiveReservoir() ) { 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 ); requestNewOperationMode( DG_MODE_CIRC ); } return result; } /*********************************************************************//** * @brief * The getCurrentDrainState function returns the current state of the \n * drain mode. * @details * Inputs : drainState * Outputs : none * @return the current state of drain mode. *************************************************************************/ DG_DRAIN_STATE_T getCurrentDrainState( void ) { return drainState; } /**@}*/