From a6a0e8ba773f7a484616188ae140592aa8149505 Mon Sep 17 00:00:00 2001 From: David Holdeman Date: Fri, 9 Oct 2020 22:34:45 -0500 Subject: [PATCH] Simple transmission 2 (#1870) * simple trans controller * don't need check * we can loop! * use efi::size * pin mode configuration * set pin mode * switch to RegisteredOutputPin * size * add to makefile * fixes * fixes * wat * output pin, and ts stuff * use SimpleTransmissionController * include * grrr * grrr * move to separate file * fix includes * try * semicolon stupid * try pointers * try * add to makefile * wat * try * try * try * try * try * try * try * try * try * try * try * try * try * try * undo * more idiomatic maybe * remove logger * try init func * try * try * try init fn * try * switch * try * try * ifndef * try * try * ifndef * use def dug * INJECT FIRST * try * try * duh --- firmware/controllers/algo/engine.h | 2 +- firmware/controllers/algo/rusefi_types.h | 2 +- firmware/controllers/buttonshift.cpp | 2 ++ firmware/controllers/buttonshift.h | 2 +- firmware/controllers/controllers.mk | 2 ++ firmware/controllers/gear_controller.cpp | 27 ++++++++++++++++++++++++ firmware/controllers/gear_controller.h | 23 ++++++++++++++++++++ firmware/controllers/simple_tcu.cpp | 18 ++++++++++------ firmware/controllers/simple_tcu.h | 8 ++++--- firmware/controllers/tcu.cpp | 20 ------------------ firmware/controllers/tcu.h | 13 +----------- firmware/integration/rusefi_config.txt | 2 +- firmware/tunerstudio/rusefi.input | 2 +- 13 files changed, 77 insertions(+), 46 deletions(-) create mode 100644 firmware/controllers/gear_controller.cpp create mode 100644 firmware/controllers/gear_controller.h diff --git a/firmware/controllers/algo/engine.h b/firmware/controllers/algo/engine.h index 791080bbda..d5d71aa651 100644 --- a/firmware/controllers/algo/engine.h +++ b/firmware/controllers/algo/engine.h @@ -17,7 +17,7 @@ #include "trigger_central.h" #include "local_version_holder.h" #include "buttonshift.h" -#include "tcu.h" +#include "gear_controller.h" #if EFI_SIGNAL_EXECUTOR_ONE_TIMER // PROD real firmware uses this implementation diff --git a/firmware/controllers/algo/rusefi_types.h b/firmware/controllers/algo/rusefi_types.h index f374a76897..baa1621737 100644 --- a/firmware/controllers/algo/rusefi_types.h +++ b/firmware/controllers/algo/rusefi_types.h @@ -100,7 +100,7 @@ typedef uint8_t iac_pid_mult_t[IAC_PID_MULT_SIZE][IAC_PID_MULT_SIZE]; typedef float baro_corr_table_t[BARO_CORR_SIZE][BARO_CORR_SIZE]; -typedef bool tcubinary_table_t[TCU_SOLENOID_COUNT][TCU_GEAR_COUNT]; +typedef bool tcubinary_table_t[TCU_GEAR_COUNT][TCU_SOLENOID_COUNT]; typedef float fsio_table_8x8_f32t[FSIO_TABLE_8][FSIO_TABLE_8]; typedef float tps_tps_table_t[TPS_TPS_ACCEL_TABLE][TPS_TPS_ACCEL_TABLE]; diff --git a/firmware/controllers/buttonshift.cpp b/firmware/controllers/buttonshift.cpp index e74c1a5bae..4260bfb660 100644 --- a/firmware/controllers/buttonshift.cpp +++ b/firmware/controllers/buttonshift.cpp @@ -16,6 +16,8 @@ void ButtonShiftController::init (DECLARE_ENGINE_PARAMETER_SIGNATURE) { // 500 millisecond is maybe a little long? debounceUp.init(500, CONFIG(tcuUpshiftButtonPin), CONFIG(tcuUpshiftButtonPinMode)); debounceDown.init(500, CONFIG(tcuDownshiftButtonPin), CONFIG(tcuDownshiftButtonPinMode)); + INJECT_ENGINE_REFERENCE(&transmissionController); + transmissionController.init(); } void ButtonShiftController::update() { diff --git a/firmware/controllers/buttonshift.h b/firmware/controllers/buttonshift.h index d68b91fe0b..9305c0feb9 100644 --- a/firmware/controllers/buttonshift.h +++ b/firmware/controllers/buttonshift.h @@ -7,7 +7,7 @@ */ #pragma once -#include "tcu.h" +#include "gear_controller.h" #include "globalaccess.h" #include "debounce.h" diff --git a/firmware/controllers/controllers.mk b/firmware/controllers/controllers.mk index 46b73a91ad..c8b7bfcb2b 100644 --- a/firmware/controllers/controllers.mk +++ b/firmware/controllers/controllers.mk @@ -50,7 +50,9 @@ CONTROLLERS_SRC_CPP = \ $(CONTROLLERS_DIR)/serial/serial_sensor.cpp \ $(CONTROLLERS_DIR)/buttonshift.cpp \ $(CONTROLLERS_DIR)/tcu.cpp \ + $(CONTROLLERS_DIR)/gear_controller.cpp \ $(CONTROLLERS_DIR)/start_stop.cpp \ + $(CONTROLLERS_DIR)/simple_tcu.cpp \ CONTROLLERS_INC=\ $(CONTROLLERS_DIR) \ diff --git a/firmware/controllers/gear_controller.cpp b/firmware/controllers/gear_controller.cpp new file mode 100644 index 0000000000..40aba538a0 --- /dev/null +++ b/firmware/controllers/gear_controller.cpp @@ -0,0 +1,27 @@ +#include "gear_controller.h" +#include "tunerstudio_outputs.h" + +void GearControllerBase::init() { + INJECT_ENGINE_REFERENCE(&transmissionController); + transmissionController.init(); +} + +void GearControllerBase::update() { + transmissionController.update(getDesiredGear()); + postState(); +} + +gear_e GearControllerBase::getDesiredGear() const { + return desiredGear; +} + +gear_e GearControllerBase::setDesiredGear(gear_e gear) { + desiredGear = gear; + return getDesiredGear(); +} + +void GearControllerBase::postState() { +#if EFI_TUNER_STUDIO + tsOutputChannels.tcuDesiredGear = getDesiredGear(); +#endif +} diff --git a/firmware/controllers/gear_controller.h b/firmware/controllers/gear_controller.h new file mode 100644 index 0000000000..2dab9a3b1f --- /dev/null +++ b/firmware/controllers/gear_controller.h @@ -0,0 +1,23 @@ +#pragma once + +#include "global.h" +#include "io_pins.h" +#include "persistent_configuration.h" +#include "engine_configuration_generated_structures.h" +#include "globalaccess.h" +#include "simple_tcu.h" + +class GearControllerBase { +public: + DECLARE_ENGINE_PTR; + + virtual void update(); + gear_e getDesiredGear() const; + virtual void init(); +private: + gear_e desiredGear = NEUTRAL; +protected: + gear_e setDesiredGear(gear_e); + void postState(); + SimpleTransmissionController transmissionController; +}; diff --git a/firmware/controllers/simple_tcu.cpp b/firmware/controllers/simple_tcu.cpp index 88a5380f11..8e0fa4b49d 100644 --- a/firmware/controllers/simple_tcu.cpp +++ b/firmware/controllers/simple_tcu.cpp @@ -1,16 +1,22 @@ #include "simple_tcu.h" +#include "efi_gpio.h" +#include "engine_configuration.h" -RegisteredOutputPin tcuSolenoids[efi::size(tcu_solenoid)]; +EXTERN_CONFIG; -void SimpleTransmissionController::SimpleTransmissionController() { - for (int i = 0; i < efi::size(tcu_solenoid); i++) { - tcuSolenoids[i].initPin("Transmission Solenoid", CONFIG(tcu_solenoid[i]), CONFIG{tcu_solenoid_mode[i]}); +OutputPin tcuSolenoids[TCU_SOLENOID_COUNT]; + +void SimpleTransmissionController::init() { + for (int i = 0; i < efi::size(CONFIG(tcu_solenoid)); i++) { + tcuSolenoids[i].initPin("Transmission Solenoid", CONFIG(tcu_solenoid)[i], &CONFIG(tcu_solenoid_mode)[i]); } } void SimpleTransmissionController::update(gear_e gear) { - for (int i = 0; i < efi::size(tcu_solenoid); i++) { - tcuSolenoids[i].setValue(CONFIG(tcuSolenoidTable)[i][static_cast(gear)]) + for (int i = 0; i < efi::size(CONFIG(tcu_solenoid)); i++) { +#ifndef EFI_UNIT_TEST + tcuSolenoids[i].setValue(config->tcuSolenoidTable[static_cast(gear) + 1][i]); +#endif } setCurrentGear(gear); postState(); diff --git a/firmware/controllers/simple_tcu.h b/firmware/controllers/simple_tcu.h index 8710c5bbd4..dcba48f164 100644 --- a/firmware/controllers/simple_tcu.h +++ b/firmware/controllers/simple_tcu.h @@ -2,8 +2,10 @@ #include "tcu.h" -class SimpleTransmissionController { +class SimpleTransmissionController: public TransmissionControllerBase { public: + DECLARE_ENGINE_PTR; + void update(gear_e); - SimpleTransmissionController(); -} + void init(); +}; diff --git a/firmware/controllers/tcu.cpp b/firmware/controllers/tcu.cpp index 29011cdb41..0af00c45c5 100644 --- a/firmware/controllers/tcu.cpp +++ b/firmware/controllers/tcu.cpp @@ -28,23 +28,3 @@ void TransmissionControllerBase::postState() { tsOutputChannels.tcuCurrentGear = getCurrentGear(); #endif } - -void GearControllerBase::update() { - transmissionController.update(getDesiredGear()); - postState(); -} - -gear_e GearControllerBase::getDesiredGear() const { - return desiredGear; -} - -gear_e GearControllerBase::setDesiredGear(gear_e gear) { - desiredGear = gear; - return getDesiredGear(); -} - -void GearControllerBase::postState() { -#if EFI_TUNER_STUDIO - tsOutputChannels.tcuDesiredGear = getDesiredGear(); -#endif -} diff --git a/firmware/controllers/tcu.h b/firmware/controllers/tcu.h index e8c522146a..f060d5c956 100644 --- a/firmware/controllers/tcu.h +++ b/firmware/controllers/tcu.h @@ -16,6 +16,7 @@ class TransmissionControllerBase { public: void update(gear_e); + void init(); gear_e getCurrentGear() const; private: gear_e currentGear = NEUTRAL; @@ -23,15 +24,3 @@ protected: gear_e setCurrentGear(gear_e); void postState(); }; - -class GearControllerBase { -public: - virtual void update(); - gear_e getDesiredGear() const; -private: - gear_e desiredGear = NEUTRAL; -protected: - gear_e setDesiredGear(gear_e); - void postState(); - TransmissionControllerBase transmissionController; -}; diff --git a/firmware/integration/rusefi_config.txt b/firmware/integration/rusefi_config.txt index 99dc7259af..474d47311b 100644 --- a/firmware/integration/rusefi_config.txt +++ b/firmware/integration/rusefi_config.txt @@ -205,7 +205,7 @@ custom fuel_table_t 4*@@FUEL_RPM_COUNT@@x@@FUEL_LOAD_COUNT@@ array, F32, @OF custom ve_table_t 4*@@FUEL_RPM_COUNT@@x@@FUEL_LOAD_COUNT@@ array, F32, @OFFSET@, [@@FUEL_RPM_COUNT@@x@@FUEL_LOAD_COUNT@@],"%", 1, 0, 0, 999.0, 2 custom afr_table_t @@FUEL_RPM_COUNT@@x@@FUEL_LOAD_COUNT@@ array, U08, @OFFSET@, [@@FUEL_RPM_COUNT@@x@@FUEL_LOAD_COUNT@@],"deg", {1/@@PACK_MULT_AFR_CFG@@}, 0, 0, 25.0, 1 -custom tcubinary_table_t @@TCU_SOLENOID_COUNT@@x@@TCU_GEAR_COUNT@@ array, U08, @OFFSET@, [@@TCU_SOLENOID_COUNT@@x@@TCU_GEAR_COUNT@@],"onoff", 1, 0, 0, 1, 0 +custom tcubinary_table_t @@TCU_GEAR_COUNT@@x@@TCU_SOLENOID_COUNT@@ array, U08, @OFFSET@, [@@TCU_GEAR_COUNT@@x@@TCU_SOLENOID_COUNT@@],"onoff", 1, 0, 0, 1, 0 custom fsio_table_8x8_u8t @@FSIO_TABLE_8@@x@@FSIO_TABLE_8@@ array, U08, @OFFSET@, [@@FSIO_TABLE_8@@x@@FSIO_TABLE_8@@],"value", 1, 0, 0.0, 255.0, 0 custom fsio_table_8x8_f32t 4*@@FSIO_TABLE_8@@x@@FSIO_TABLE_8@@ array, F32, @OFFSET@, [@@FSIO_TABLE_8@@x@@FSIO_TABLE_8@@],"value", 1, 0, 0.0, 30000.0, 2 diff --git a/firmware/tunerstudio/rusefi.input b/firmware/tunerstudio/rusefi.input index 561c6a379f..bde0694300 100644 --- a/firmware/tunerstudio/rusefi.input +++ b/firmware/tunerstudio/rusefi.input @@ -2957,7 +2957,7 @@ cmd_set_engine_type_default = "@@TS_IO_TEST_COMMAND_char@@\x00\x31\x00\x00" field = "Solenoid 5 Pin Mode" tcu_solenoid_mode5, { tcuEnabled } field = "Solenoid 6 Pin Mode" tcu_solenoid_mode6, { tcuEnabled } - dialog = buttonShiftInputPanel + dialog = buttonShiftInputPanel, "Switch/Button Shift" field = "Upshift Pin" tcuUpshiftButtonPin, { tcuEnabled } field = "Upshift Pin Mode" tcuUpshiftButtonPinMode, { tcuEnabled } field = "Downshift Pin" tcuDownshiftButtonPin, { tcuEnabled }