Index: firmware/App/Controllers/ROPump.c =================================================================== diff -u -rff3e2e33857a7e2ea65969e87fb5b9e49937aafc -rba9341bc691b500d5ec3904fec1eb38279c5fbbd --- firmware/App/Controllers/ROPump.c (.../ROPump.c) (revision ff3e2e33857a7e2ea65969e87fb5b9e49937aafc) +++ firmware/App/Controllers/ROPump.c (.../ROPump.c) (revision ba9341bc691b500d5ec3904fec1eb38279c5fbbd) @@ -342,13 +342,27 @@ * @param roFlowRate which is target RO flow rate in mL/min * @return TRUE if new target flow rate is set successfully, FALSE if not *************************************************************************/ -BOOL setROPumpTargetFlowRateMLPM( U32 roFlowRate ) +BOOL setROPumpTargetFlowRateMLPM( U32 roFlowRate, BOOL firmwareCall ) { BOOL result = FALSE; // First of all, the flow rate must be in range if ( ( roFlowRate <= MAX_RO_FLOWRATE_MLPM ) && ( roFlowRate >= MIN_RO_FLOWRATE_MLPM ) ) { + if ( firmwareCall == TRUE ) // firmware call + { + if ( ( targetROPumpFlowRate.override == OVERRIDE_RESET ) && ( targetROPumpPressure.override == OVERRIDE_RESET ) && ( roPumpOpenLoopTargetDutyCycle.override == OVERRIDE_RESET ) ) + { + targetROPumpPressure.data = 0; + roPumpOpenLoopTargetDutyCycle.data = 0.0F; + } + else + { + result = TRUE; + return result; + } + + } targetROPumpFlowRate.data = roFlowRate; // Get the initial guess of the duty cycle roPumpDutyCyclePctSet = roPumpFlowToPWM( getTargetROPumpFlowRateMLPM() ); @@ -375,13 +389,26 @@ * @param roPressure which is target RO pressure * @return TRUE if new target flow rate is set successfully, FALSE if not *************************************************************************/ -BOOL setROPumpTargetPressure( F32 roPressure ) +BOOL setROPumpTargetPressure( F32 roPressure, BOOL firmwareCall ) { BOOL result = FALSE; // First of all, the pressure must be in range if ( ( roPressure <= MAX_RO_PRESSURE_PSI ) && ( roPressure >= MIN_RO_PRESSURE_PSI ) ) { + if ( firmwareCall == TRUE ) // firmware call + { + if ( ( targetROPumpFlowRate.override == OVERRIDE_RESET ) && ( targetROPumpPressure.override == OVERRIDE_RESET ) && ( roPumpOpenLoopTargetDutyCycle.override == OVERRIDE_RESET ) ) + { + targetROPumpFlowRate.data = 0; + roPumpOpenLoopTargetDutyCycle.data = 0.0F; + } + else + { + result = TRUE; + return result; + } + } targetROPumpPressure.data = roPressure; // Get the initial guess of the duty cycle roPumpDutyCyclePctSet = roPumpPresToPWM( getTargetROPumpPressure() ); @@ -409,19 +436,33 @@ * @param duty which is the duty cycle * @return none *************************************************************************/ -BOOL setROPumpTargetDutyCycle( F32 dutyCycle ) +BOOL setROPumpTargetDutyCycle( F32 dutyCycle, BOOL firmwareCall ) { BOOL result = FALSE; if ( ( dutyCycle >= MIN_FLUID_PUMP_DUTY_CYCLE_PCT ) && ( dutyCycle <= MAX_FLUID_PUMP_DUTY_CYCLE_PCT ) ) { + if ( firmwareCall == TRUE ) // firmware call + { + if ( ( targetROPumpFlowRate.override == OVERRIDE_RESET ) && ( targetROPumpPressure.override == OVERRIDE_RESET ) && ( roPumpOpenLoopTargetDutyCycle.override == OVERRIDE_RESET ) ) + { + targetROPumpFlowRate.data = 0; + targetROPumpPressure.data = 0.0F; + } + else + { + result = TRUE; + return result; + } + } + // Set the new duty cycle of the pump roPumpOpenLoopTargetDutyCycle.data = dutyCycle; result = TRUE; // stop RO Pump if duty cycle is set to zero - if ( dutyCycle == 0.0 ) + if ( dutyCycle == 0.0F ) { - if ( ( targetROPumpFlowRate.data == 0 ) && ( targetROPumpPressure.data == 0.0 ) ) + if ( ( targetROPumpFlowRate.data == 0 ) && ( targetROPumpPressure.data == 0.0F ) ) { signalROPumpHardStop(); } @@ -618,7 +659,6 @@ } } - /************************************************************************* * TEST SUPPORT FUNCTIONS *************************************************************************/ @@ -661,14 +701,14 @@ { // Restore previous flow, duty cycle and pressure values targetROPumpPressure.data = targetROPumpPressure.ovInitData; - targetROPumpPressure.ovInitData = 0.0; + targetROPumpPressure.ovInitData = 0.0F; targetROPumpPressure.ovData = targetROPumpPressure.ovInitData; targetROPumpPressure.override = OVERRIDE_RESET; if ( targetROPumpFlowRate.override == OVERRIDE_RESET && targetROPumpFlowRate.ovInitData != 0 ) { targetROPumpFlowRate.data = targetROPumpFlowRate.ovInitData; } - if ( roPumpOpenLoopTargetDutyCycle.override == OVERRIDE_RESET && roPumpOpenLoopTargetDutyCycle.ovInitData != 0 ) + if ( roPumpOpenLoopTargetDutyCycle.override == OVERRIDE_RESET && roPumpOpenLoopTargetDutyCycle.ovInitData != 0.0F ) { roPumpOpenLoopTargetDutyCycle.data = roPumpOpenLoopTargetDutyCycle.ovInitData; } @@ -678,40 +718,14 @@ { targetROPumpPressure.ovData = payload.state.f32; targetROPumpPressure.override = OVERRIDE_KEY; - if ( targetROPumpPressure.ovInitData == 0 ) + if ( targetROPumpPressure.ovInitData == 0.0F ) { targetROPumpPressure.ovInitData = targetROPumpPressure.data; } - if ( roPumpOpenLoopTargetDutyCycle.data > 0 ) - { - if ( roPumpOpenLoopTargetDutyCycle.override != OVERRIDE_RESET ) - { - roPumpOpenLoopTargetDutyCycle.ovData = 0; - roPumpOpenLoopTargetDutyCycle.override = OVERRIDE_RESET; - roPumpOpenLoopTargetDutyCycle.data = 0; - } - else if ( roPumpOpenLoopTargetDutyCycle.ovInitData == 0 ) - { - roPumpOpenLoopTargetDutyCycle.ovInitData = roPumpOpenLoopTargetDutyCycle.data; - roPumpOpenLoopTargetDutyCycle.data = 0; - } - } - if ( targetROPumpFlowRate.data > 0.0 ) - { - if ( targetROPumpFlowRate.override != OVERRIDE_RESET ) - { - targetROPumpFlowRate.ovData = 0.0; - targetROPumpFlowRate.override = OVERRIDE_RESET; - targetROPumpFlowRate.data = 0; - } - else if ( targetROPumpFlowRate.ovInitData == 0 ) - { - targetROPumpFlowRate.ovInitData = targetROPumpFlowRate.data; - targetROPumpFlowRate.data = 0.0; - } - } + handleFluidPumpF32Data( &roPumpOpenLoopTargetDutyCycle ); + handleFluidPumpU32Data( &targetROPumpFlowRate ); } - result = setROPumpTargetPressure(getTargetROPumpPressure()); + result = setROPumpTargetPressure(getTargetROPumpPressure(), FALSE); return result; } @@ -739,11 +753,11 @@ targetROPumpFlowRate.ovInitData = 0; targetROPumpFlowRate.ovData = targetROPumpFlowRate.ovInitData; targetROPumpFlowRate.override = OVERRIDE_RESET; - if ( roPumpOpenLoopTargetDutyCycle.override == OVERRIDE_RESET && roPumpOpenLoopTargetDutyCycle.ovInitData != 0 ) + if ( roPumpOpenLoopTargetDutyCycle.override == OVERRIDE_RESET && roPumpOpenLoopTargetDutyCycle.ovInitData != 0.0F ) { roPumpOpenLoopTargetDutyCycle.data = roPumpOpenLoopTargetDutyCycle.ovInitData; } - if ( targetROPumpPressure.override == OVERRIDE_RESET && targetROPumpPressure.ovInitData != 0 ) + if ( targetROPumpPressure.override == OVERRIDE_RESET && targetROPumpPressure.ovInitData != 0.0F ) { targetROPumpPressure.data = targetROPumpPressure.ovInitData; } @@ -757,36 +771,10 @@ { targetROPumpFlowRate.ovInitData = targetROPumpFlowRate.data; } - if ( roPumpOpenLoopTargetDutyCycle.data > 0 ) - { - if ( roPumpOpenLoopTargetDutyCycle.override != OVERRIDE_RESET ) - { - roPumpOpenLoopTargetDutyCycle.ovData = 0; - roPumpOpenLoopTargetDutyCycle.override = OVERRIDE_RESET; - roPumpOpenLoopTargetDutyCycle.data = 0; - } - else if ( roPumpOpenLoopTargetDutyCycle.ovInitData == 0 ) - { - roPumpOpenLoopTargetDutyCycle.ovInitData = roPumpOpenLoopTargetDutyCycle.data; - roPumpOpenLoopTargetDutyCycle.data = 0; - } - } - if ( targetROPumpPressure.data > 0.0 ) - { - if ( targetROPumpPressure.override != OVERRIDE_RESET ) - { - targetROPumpPressure.ovData = 0.0; - targetROPumpPressure.override = OVERRIDE_RESET; - targetROPumpPressure.data = 0; - } - else if ( targetROPumpPressure.ovInitData == 0 ) - { - targetROPumpPressure.ovInitData = targetROPumpPressure.data; - targetROPumpPressure.data = 0.0; - } - } + handleFluidPumpF32Data( &roPumpOpenLoopTargetDutyCycle ); + handleFluidPumpF32Data( &targetROPumpPressure ); } - result = setROPumpTargetFlowRateMLPM(getTargetROPumpFlowRateMLPM()); + result = setROPumpTargetFlowRateMLPM(getTargetROPumpFlowRateMLPM(), FALSE); return result; } @@ -811,7 +799,7 @@ { // Restore previous flow, duty cycle and pressure values roPumpOpenLoopTargetDutyCycle.data = roPumpOpenLoopTargetDutyCycle.ovInitData; - roPumpOpenLoopTargetDutyCycle.ovInitData = 0.0; + roPumpOpenLoopTargetDutyCycle.ovInitData = 0.0F; roPumpOpenLoopTargetDutyCycle.ovData = roPumpOpenLoopTargetDutyCycle.ovInitData; roPumpOpenLoopTargetDutyCycle.override = OVERRIDE_RESET; if ( targetROPumpFlowRate.override == OVERRIDE_RESET && targetROPumpFlowRate.ovInitData != 0 ) @@ -828,40 +816,14 @@ { roPumpOpenLoopTargetDutyCycle.ovData = payload.state.f32; roPumpOpenLoopTargetDutyCycle.override = OVERRIDE_KEY; - if ( roPumpOpenLoopTargetDutyCycle.ovInitData == 0 ) + if ( roPumpOpenLoopTargetDutyCycle.ovInitData == 0.0F ) { roPumpOpenLoopTargetDutyCycle.ovInitData = roPumpOpenLoopTargetDutyCycle.data; } - if ( targetROPumpFlowRate.data > 0 ) - { - if ( targetROPumpFlowRate.override != OVERRIDE_RESET ) - { - targetROPumpFlowRate.ovData = 0; - targetROPumpFlowRate.override = OVERRIDE_RESET; - targetROPumpFlowRate.data = 0; - } - else if ( targetROPumpFlowRate.ovInitData == 0 ) - { - targetROPumpFlowRate.ovInitData = targetROPumpFlowRate.data; - targetROPumpFlowRate.data = 0; - } - } - if ( targetROPumpPressure.data > 0.0 ) - { - if ( targetROPumpPressure.override != OVERRIDE_RESET ) - { - targetROPumpPressure.ovData = 0.0; - targetROPumpPressure.override = OVERRIDE_RESET; - targetROPumpPressure.data = 0; - } - else if ( targetROPumpPressure.ovInitData == 0 ) - { - targetROPumpPressure.ovInitData = targetROPumpPressure.data; - targetROPumpPressure.data = 0.0; - } - } + handleFluidPumpU32Data( &targetROPumpFlowRate ); + handleFluidPumpF32Data( &targetROPumpPressure ); } - result = setROPumpTargetDutyCycle(getTargetROPumpDutyCyclePCT()); + result = setROPumpTargetDutyCycle(getTargetROPumpDutyCyclePCT(), FALSE); return result; }