gppwm load axis can be another GPPWM channel (!!!!!) (#4587)

* gppwm load axis can be another GPPWM channel (!!!!!)

* explicit cast

* efiAssert not void

* kick
This commit is contained in:
Matthew Kennedy 2022-09-17 18:38:06 -07:00 committed by GitHub
parent 5a2f405a37
commit 57a22fd713
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 26 additions and 8 deletions

View File

@ -44,22 +44,32 @@ expected<float> readGppwmChannel(gppwm_channel_e channel) {
return Sensor::get(SensorType::AuxLinear1);
case GPPWM_AuxLinear2:
return Sensor::get(SensorType::AuxLinear2);
case GPPWM_GppwmOutput1:
return (float)engine->outputChannels.gppwmOutput[0];
case GPPWM_GppwmOutput2:
return (float)engine->outputChannels.gppwmOutput[1];
case GPPWM_GppwmOutput3:
return (float)engine->outputChannels.gppwmOutput[2];
case GPPWM_GppwmOutput4:
return (float)engine->outputChannels.gppwmOutput[3];
}
return unexpected;
}
void GppwmChannel::setOutput(float result) {
float GppwmChannel::setOutput(float result) {
// Not init yet, nothing to do.
if (!m_config) {
return;
return result;
}
if (m_usePwm) {
efiAssertVoid(OBD_PCM_Processor_Fault, m_usePwm, "m_usePwm null");
efiAssert(OBD_PCM_Processor_Fault, m_usePwm, "m_usePwm null", 0);
m_pwm->setSimplePwmDutyCycle(clampF(0, result / 100.0f, 1));
return result;
} else {
efiAssertVoid(OBD_PCM_Processor_Fault, m_output, "m_output null");
efiAssert(OBD_PCM_Processor_Fault, m_output, "m_output null", 0);
if (m_config->offBelowDuty > m_config->onAboveDuty) {
firmwareError(CUSTOM_ERR_6122, "You can't have off below %d greater than on above %d",
m_config->offBelowDuty,
@ -73,6 +83,9 @@ void GppwmChannel::setOutput(float result) {
}
m_output->setValue(m_state);
// Return the actual output value with hysteresis
return m_state ? 100 : 0;
}
}
@ -110,6 +123,5 @@ float GppwmChannel::update() {
}
float output = getOutput();
setOutput(output);
return output;
return setOutput(output);
}

View File

@ -14,7 +14,9 @@ public:
void init(bool usePwm, IPwm* pwm, OutputPin* outputPin, const ValueProvider3D* table, const gppwm_channel* config);
float update();
percent_t getOutput() const;
void setOutput(float result);
// Returns actual output duty, with hysteresis applied
float setOutput(float result);
private:
// Store the current state so we can apply hysteresis

View File

@ -547,6 +547,10 @@ typedef enum __attribute__ ((__packed__)) {
GPPWM_EthanolPercent = 15,
GPPWM_AuxLinear1 = 16,
GPPWM_AuxLinear2 = 17,
GPPWM_GppwmOutput1 = 18,
GPPWM_GppwmOutput2 = 19,
GPPWM_GppwmOutput3 = 20,
GPPWM_GppwmOutput4 = 21,
} gppwm_channel_e;
typedef enum __attribute__ ((__packed__)) {

View File

@ -347,7 +347,7 @@ struct spi_pins
end_struct
#define gppwm_channel_e_enum "Zero", "TPS", "MAP", "CLT", "IAT", "Fuel Load", "Ignition Load", "Aux Temp 1", "Aux Temp 2", "Accel Pedal", "Battery Voltage", "VVT 1 I", "VVT 1 E", "VVT 2 I", "VVT 2 E", "Ethanol (Flex) %", "Aux Linear 1", "Aux Linear 2"
#define gppwm_channel_e_enum "Zero", "TPS", "MAP", "CLT", "IAT", "Fuel Load", "Ignition Load", "Aux Temp 1", "Aux Temp 2", "Accel Pedal", "Battery Voltage", "VVT 1 I", "VVT 1 E", "VVT 2 I", "VVT 2 E", "Ethanol (Flex) %", "Aux Linear 1", "Aux Linear 2", "GPPWM Output 1", "GPPWM Output 2", "GPPWM Output 3", "GPPWM Output 4"
custom gppwm_channel_e 1 bits, U08, @OFFSET@, [0:4], @@gppwm_channel_e_enum@@
struct gppwm_channel