From 867fd3d746833a225b8564c7331329d3a9be98b4 Mon Sep 17 00:00:00 2001 From: kifir Date: Wed, 15 May 2024 18:45:59 +0300 Subject: [PATCH] Refactoring: extract readGppwmChannel function extract into gppwm_channel_reader.h/cpp files --- .../actuators/gppwm/gppwm_channel.cpp | 79 +---------------- .../actuators/gppwm/gppwm_channel.h | 2 - .../actuators/gppwm_channel_reader.cpp | 84 +++++++++++++++++++ .../actuators/gppwm_channel_reader.h | 7 ++ firmware/controllers/controllers.mk | 1 + firmware/controllers/math/engine_math.cpp | 2 +- 6 files changed, 94 insertions(+), 81 deletions(-) create mode 100644 firmware/controllers/actuators/gppwm_channel_reader.cpp create mode 100644 firmware/controllers/actuators/gppwm_channel_reader.h diff --git a/firmware/controllers/actuators/gppwm/gppwm_channel.cpp b/firmware/controllers/actuators/gppwm/gppwm_channel.cpp index 5ae4c760b0..683aba1a2f 100644 --- a/firmware/controllers/actuators/gppwm/gppwm_channel.cpp +++ b/firmware/controllers/actuators/gppwm/gppwm_channel.cpp @@ -4,84 +4,7 @@ #include "gppwm_channel.h" #include "table_helper.h" -#include - -expected readGppwmChannel(gppwm_channel_e channel) { - switch (channel) { - case GPPWM_Zero: - return 0; - case GPPWM_Rpm: - return Sensor::get(SensorType::Rpm); - case GPPWM_Tps: - return Sensor::get(SensorType::Tps1); - case GPPWM_Map: - return Sensor::get(SensorType::Map); - case GPPWM_Clt: - return Sensor::get(SensorType::Clt); - case GPPWM_Iat: - return Sensor::get(SensorType::Iat); - case GPPWM_LuaGauge1: - return Sensor::get(SensorType::LuaGauge1); - case GPPWM_LuaGauge2: - return Sensor::get(SensorType::LuaGauge2); - case GPPWM_FuelLoad: - return getFuelingLoad(); - case GPPWM_IgnLoad: - return getIgnitionLoad(); - case GPPWM_AuxTemp1: - return Sensor::get(SensorType::AuxTemp1); - case GPPWM_AuxTemp2: - return Sensor::get(SensorType::AuxTemp2); - case GPPWM_AccelPedal: - return Sensor::get(SensorType::AcceleratorPedal); - case GPPWM_Vbatt: - return Sensor::get(SensorType::BatteryVoltage); -#if EFI_SHAFT_POSITION_INPUT - case GPPWM_VVT_1I: - return engine->triggerCentral.getVVTPosition(/*bankIndex*/0, /*camIndex*/0); - case GPPWM_VVT_1E: - return engine->triggerCentral.getVVTPosition(/*bankIndex*/0, /*camIndex*/1); - case GPPWM_VVT_2I: - return engine->triggerCentral.getVVTPosition(/*bankIndex*/1, /*camIndex*/0); - case GPPWM_VVT_2E: - return engine->triggerCentral.getVVTPosition(/*bankIndex*/1, /*camIndex*/1); -#else - case GPPWM_VVT_1I: - case GPPWM_VVT_1E: - case GPPWM_VVT_2I: - case GPPWM_VVT_2E: - return 0; -#endif // EFI_SHAFT_POSITION_INPUT - case GPPWM_EthanolPercent: - return Sensor::get(SensorType::FuelEthanolPercent); - case GPPWM_AuxLinear1: - 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]; - case GPPWM_DetectedGear: -#if EFI_VEHICLE_SPEED - return Sensor::get(SensorType::DetectedGear); -#else - return 0; -#endif // EFI_VEHICLE_SPEED - case GPPWM_BaroPressure: - return Sensor::get(SensorType::BarometricPressure); - case GPPWM_Egt1: - return Sensor::get(SensorType::EGT1); - case GPPWM_Egt2: - return Sensor::get(SensorType::EGT2); - } - - return unexpected; -} +#include "gppwm_channel_reader.h" float GppwmChannel::setOutput(float result) { // Not init yet, nothing to do. diff --git a/firmware/controllers/actuators/gppwm/gppwm_channel.h b/firmware/controllers/actuators/gppwm/gppwm_channel.h index 7933b6087b..a6278a9aea 100644 --- a/firmware/controllers/actuators/gppwm/gppwm_channel.h +++ b/firmware/controllers/actuators/gppwm/gppwm_channel.h @@ -35,5 +35,3 @@ private: OutputPin* m_output = nullptr; const ValueProvider3D* m_table = nullptr; }; - -expected readGppwmChannel(gppwm_channel_e channel); diff --git a/firmware/controllers/actuators/gppwm_channel_reader.cpp b/firmware/controllers/actuators/gppwm_channel_reader.cpp new file mode 100644 index 0000000000..f80bbba2a5 --- /dev/null +++ b/firmware/controllers/actuators/gppwm_channel_reader.cpp @@ -0,0 +1,84 @@ +// +// Created by kifir on 5/15/24. +// + +#include "pch.h" + +#include "gppwm_channel_reader.h" + +expected readGppwmChannel(gppwm_channel_e channel) { + switch (channel) { + case GPPWM_Zero: + return 0; + case GPPWM_Rpm: + return Sensor::get(SensorType::Rpm); + case GPPWM_Tps: + return Sensor::get(SensorType::Tps1); + case GPPWM_Map: + return Sensor::get(SensorType::Map); + case GPPWM_Clt: + return Sensor::get(SensorType::Clt); + case GPPWM_Iat: + return Sensor::get(SensorType::Iat); + case GPPWM_LuaGauge1: + return Sensor::get(SensorType::LuaGauge1); + case GPPWM_LuaGauge2: + return Sensor::get(SensorType::LuaGauge2); + case GPPWM_FuelLoad: + return getFuelingLoad(); + case GPPWM_IgnLoad: + return getIgnitionLoad(); + case GPPWM_AuxTemp1: + return Sensor::get(SensorType::AuxTemp1); + case GPPWM_AuxTemp2: + return Sensor::get(SensorType::AuxTemp2); + case GPPWM_AccelPedal: + return Sensor::get(SensorType::AcceleratorPedal); + case GPPWM_Vbatt: + return Sensor::get(SensorType::BatteryVoltage); +#if EFI_SHAFT_POSITION_INPUT + case GPPWM_VVT_1I: + return engine->triggerCentral.getVVTPosition(/*bankIndex*/0, /*camIndex*/0); + case GPPWM_VVT_1E: + return engine->triggerCentral.getVVTPosition(/*bankIndex*/0, /*camIndex*/1); + case GPPWM_VVT_2I: + return engine->triggerCentral.getVVTPosition(/*bankIndex*/1, /*camIndex*/0); + case GPPWM_VVT_2E: + return engine->triggerCentral.getVVTPosition(/*bankIndex*/1, /*camIndex*/1); +#else + case GPPWM_VVT_1I: + case GPPWM_VVT_1E: + case GPPWM_VVT_2I: + case GPPWM_VVT_2E: + return 0; +#endif // EFI_SHAFT_POSITION_INPUT + case GPPWM_EthanolPercent: + return Sensor::get(SensorType::FuelEthanolPercent); + case GPPWM_AuxLinear1: + 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]; + case GPPWM_DetectedGear: +#if EFI_VEHICLE_SPEED + return Sensor::get(SensorType::DetectedGear); +#else + return 0; +#endif // EFI_VEHICLE_SPEED + case GPPWM_BaroPressure: + return Sensor::get(SensorType::BarometricPressure); + case GPPWM_Egt1: + return Sensor::get(SensorType::EGT1); + case GPPWM_Egt2: + return Sensor::get(SensorType::EGT2); + } + + return unexpected; +} diff --git a/firmware/controllers/actuators/gppwm_channel_reader.h b/firmware/controllers/actuators/gppwm_channel_reader.h new file mode 100644 index 0000000000..cf859eb2ce --- /dev/null +++ b/firmware/controllers/actuators/gppwm_channel_reader.h @@ -0,0 +1,7 @@ +// +// Created by kifir on 5/15/24. +// + +#pragma once + +expected readGppwmChannel(gppwm_channel_e channel); diff --git a/firmware/controllers/controllers.mk b/firmware/controllers/controllers.mk index f11e803826..90a55364de 100644 --- a/firmware/controllers/controllers.mk +++ b/firmware/controllers/controllers.mk @@ -23,6 +23,7 @@ CONTROLLERS_SRC_CPP = \ $(CONTROLLERS_DIR)/actuators/main_relay.cpp \ $(CONTROLLERS_DIR)/actuators/pwm_tester.cpp \ $(CONTROLLERS_DIR)/actuators/vvt.cpp \ + $(CONTROLLERS_DIR)/actuators/gppwm_channel_reader.cpp \ $(CONTROLLERS_DIR)/actuators/gppwm/gppwm_channel.cpp \ $(CONTROLLERS_DIR)/actuators/gppwm/gppwm.cpp \ $(CONTROLLERS_DIR)/gauges/tachometer.cpp \ diff --git a/firmware/controllers/math/engine_math.cpp b/firmware/controllers/math/engine_math.cpp index 6ee666a54c..2425207ae1 100644 --- a/firmware/controllers/math/engine_math.cpp +++ b/firmware/controllers/math/engine_math.cpp @@ -24,7 +24,7 @@ #include "event_registry.h" #include "fuel_math.h" #include "advance_map.h" -#include "gppwm_channel.h" +#include "gppwm_channel_reader.h" #if EFI_UNIT_TEST extern bool verboseMode;