diff --git a/firmware/controllers/actuators/gppwm/gppwm_channel.cpp b/firmware/controllers/actuators/gppwm/gppwm_channel.cpp index 8db190c5fa..254f454414 100644 --- a/firmware/controllers/actuators/gppwm/gppwm_channel.cpp +++ b/firmware/controllers/actuators/gppwm/gppwm_channel.cpp @@ -44,22 +44,32 @@ expected 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); } diff --git a/firmware/controllers/actuators/gppwm/gppwm_channel.h b/firmware/controllers/actuators/gppwm/gppwm_channel.h index 3750e92738..de3da9eee2 100644 --- a/firmware/controllers/actuators/gppwm/gppwm_channel.h +++ b/firmware/controllers/actuators/gppwm/gppwm_channel.h @@ -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 diff --git a/firmware/controllers/algo/rusefi_enums.h b/firmware/controllers/algo/rusefi_enums.h index f05d317c75..24939ac47e 100644 --- a/firmware/controllers/algo/rusefi_enums.h +++ b/firmware/controllers/algo/rusefi_enums.h @@ -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__)) { diff --git a/firmware/integration/rusefi_config.txt b/firmware/integration/rusefi_config.txt index 10ba7d4e45..86126519e6 100644 --- a/firmware/integration/rusefi_config.txt +++ b/firmware/integration/rusefi_config.txt @@ -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