make fan control live-data-friendly (#3626)

* make fan live-data-friendly

* script

* generated for happy simulator
This commit is contained in:
Matthew Kennedy 2021-11-27 21:40:12 -08:00 committed by GitHub
parent b7e8dbc137
commit b8660db35e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 214 additions and 17 deletions

View File

@ -4,34 +4,96 @@
#include "bench_test.h"
static void fanControl(bool acActive, OutputPin& pin, int8_t fanOnTemp, int8_t fanOffTemp, bool enableWithAc, bool disableWhenStopped) {
bool FanController::getState(bool acActive, bool lastState) {
auto [cltValid, clt] = Sensor::get(SensorType::Clt);
bool isCranking = engine->rpmCalculator.isCranking();
bool isRunning = engine->rpmCalculator.isRunning();
cranking = engine->rpmCalculator.isCranking();
notRunning = !engine->rpmCalculator.isRunning();
if (isCranking) {
disabledWhileEngineStopped = notRunning && disableWhenStopped();
brokenClt = !cltValid;
enabledForAc = enableWithAc() && acActive;
hot = clt > getFanOnTemp();
cold = clt < getFanOffTemp();
if (cranking) {
// Inhibit while cranking
pin.setValue(false);
} else if (disableWhenStopped && !isRunning) {
return false;
} else if (disabledWhileEngineStopped) {
// Inhibit while not running (if so configured)
pin.setValue(false);
} else if (!cltValid) {
return false;
} else if (brokenClt) {
// If CLT is broken, turn the fan on
pin.setValue(true);
} else if (enableWithAc && acActive) {
pin.setValue(true);
} else if (clt > fanOnTemp) {
return true;
} else if (enabledForAc) {
return true;
} else if (hot) {
// If hot, turn the fan on
pin.setValue(true);
} else if (clt < fanOffTemp) {
return true;
} else if (cold) {
// If cold, turn the fan off
pin.setValue(false);
return false;
} else {
// no condition met, maintain previous state
return lastState;
}
}
void FanController::update(bool acActive) {
auto& pin = getPin();
bool result = getState(acActive, pin.getLogicValue());
pin.setValue(result);
}
struct FanControl1 : public FanController {
OutputPin& getPin() {
return enginePins.fanRelay;
}
float getFanOnTemp() {
return engineConfiguration->fanOnTemperature;
}
float getFanOffTemp() {
return engineConfiguration->fanOffTemperature;
}
bool enableWithAc() {
return engineConfiguration->enableFan1WithAc;
}
bool disableWhenStopped() {
return engineConfiguration->disableFan1WhenStopped;
}
};
struct FanControl2 : public FanController {
OutputPin& getPin() {
return enginePins.fanRelay2;
}
float getFanOnTemp() {
return engineConfiguration->fan2OnTemperature;
}
float getFanOffTemp() {
return engineConfiguration->fan2OffTemperature;
}
bool enableWithAc() {
return engineConfiguration->enableFan2WithAc;
}
bool disableWhenStopped() {
return engineConfiguration->disableFan2WhenStopped;
}
};
static FanControl1 fan1;
static FanControl2 fan2;
void updateFans(bool acActive) {
#if EFI_PROD_CODE
if (isRunningBenchTest()) {
@ -39,6 +101,6 @@ void updateFans(bool acActive) {
}
#endif
fanControl(acActive, enginePins.fanRelay, engineConfiguration->fanOnTemperature, engineConfiguration->fanOffTemperature, engineConfiguration->enableFan1WithAc, engineConfiguration->disableFan1WhenStopped);
fanControl(acActive, enginePins.fanRelay2, engineConfiguration->fan2OnTemperature, engineConfiguration->fan2OffTemperature, engineConfiguration->enableFan2WithAc, engineConfiguration->disableFan2WhenStopped);
fan1.update(acActive);
fan2.update(acActive);
}

View File

@ -1,4 +1,19 @@
#pragma once
#include "fan_control_generated.h"
struct FanController : public fan_control_s {
void update(bool acActive);
private:
bool getState(bool acActive, bool lastState);
protected:
virtual OutputPin& getPin() = 0;
virtual float getFanOnTemp() = 0;
virtual float getFanOffTemp() = 0;
virtual bool enableWithAc() = 0;
virtual bool disableWhenStopped() = 0;
};
void updateFans(bool acActive);

View File

@ -0,0 +1,9 @@
struct_no_prefix fan_control_s
bit cranking
bit notRunning
bit disabledWhileEngineStopped
bit brokenClt
bit enabledForAc
bit hot
bit cold
end_struct

View File

@ -0,0 +1,108 @@
// this section was generated automatically by rusEFI tool ConfigDefinition.jar based on (unknown script) controllers/actuators/fan_control.txt Sat Nov 27 12:34:09 PST 2021
// by class com.rusefi.output.CHeaderConsumer
// begin
#pragma once
#include "rusefi_types.h"
// start of fan_control_s
struct fan_control_s {
/**
offset 0 bit 0 */
bool cranking : 1 {};
/**
offset 0 bit 1 */
bool notRunning : 1 {};
/**
offset 0 bit 2 */
bool disabledWhileEngineStopped : 1 {};
/**
offset 0 bit 3 */
bool brokenClt : 1 {};
/**
offset 0 bit 4 */
bool enabledForAc : 1 {};
/**
offset 0 bit 5 */
bool hot : 1 {};
/**
offset 0 bit 6 */
bool cold : 1 {};
/**
offset 0 bit 7 */
bool unusedBit_7_7 : 1 {};
/**
offset 0 bit 8 */
bool unusedBit_7_8 : 1 {};
/**
offset 0 bit 9 */
bool unusedBit_7_9 : 1 {};
/**
offset 0 bit 10 */
bool unusedBit_7_10 : 1 {};
/**
offset 0 bit 11 */
bool unusedBit_7_11 : 1 {};
/**
offset 0 bit 12 */
bool unusedBit_7_12 : 1 {};
/**
offset 0 bit 13 */
bool unusedBit_7_13 : 1 {};
/**
offset 0 bit 14 */
bool unusedBit_7_14 : 1 {};
/**
offset 0 bit 15 */
bool unusedBit_7_15 : 1 {};
/**
offset 0 bit 16 */
bool unusedBit_7_16 : 1 {};
/**
offset 0 bit 17 */
bool unusedBit_7_17 : 1 {};
/**
offset 0 bit 18 */
bool unusedBit_7_18 : 1 {};
/**
offset 0 bit 19 */
bool unusedBit_7_19 : 1 {};
/**
offset 0 bit 20 */
bool unusedBit_7_20 : 1 {};
/**
offset 0 bit 21 */
bool unusedBit_7_21 : 1 {};
/**
offset 0 bit 22 */
bool unusedBit_7_22 : 1 {};
/**
offset 0 bit 23 */
bool unusedBit_7_23 : 1 {};
/**
offset 0 bit 24 */
bool unusedBit_7_24 : 1 {};
/**
offset 0 bit 25 */
bool unusedBit_7_25 : 1 {};
/**
offset 0 bit 26 */
bool unusedBit_7_26 : 1 {};
/**
offset 0 bit 27 */
bool unusedBit_7_27 : 1 {};
/**
offset 0 bit 28 */
bool unusedBit_7_28 : 1 {};
/**
offset 0 bit 29 */
bool unusedBit_7_29 : 1 {};
/**
offset 0 bit 30 */
bool unusedBit_7_30 : 1 {};
/**
offset 0 bit 31 */
bool unusedBit_7_31 : 1 {};
/** total size 4*/
};
// end
// this section was generated automatically by rusEFI tool ConfigDefinition.jar based on (unknown script) controllers/actuators/fan_control.txt Sat Nov 27 12:34:09 PST 2021

View File

@ -8,6 +8,9 @@ bash gen_live_documentation_one_file.sh boost_control BoostControl.java controll
bash gen_live_documentation_one_file.sh ac_control AcControl.java controllers/actuators
[ $? -eq 0 ] || { echo "ERROR generating"; exit 1; }
bash gen_live_documentation_one_file.sh fan_control FanControl.java controllers/actuators
[ $? -eq 0 ] || { echo "ERROR generating"; exit 1; }
bash gen_live_documentation_one_file.sh fuel_pump FuelPump.java controllers/actuators
[ $? -eq 0 ] || { echo "ERROR generating"; exit 1; }