Add interface for selecting GearController and TransmissionController classes (#4048)

* save changes

* save changes

* save changes

* fix mistakes

* try adding empty method

* copy simpleTransmissionController to GM 4L6X controller

* Import 4l6x header

* add to makefile

* fix whitespace

* try enum class

* change field name

* change field name in rusefi.input

* check for gear controller mode

* add mode fields to catch if mode was changed
This commit is contained in:
David Holdeman 2022-04-06 16:37:30 -05:00 committed by GitHub
parent ec2ade8c8d
commit f305db2575
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 157 additions and 36 deletions

View File

@ -675,7 +675,6 @@ typedef enum __attribute__ ((__packed__)) {
HPFP_CAM_EX2 = 4,
} hpfp_cam_e;
#if __cplusplus
#include <cstdint>
@ -695,4 +694,16 @@ enum class TsCalMode : uint8_t {
PedalMin = 12,
PedalMax = 13,
};
enum class GearControllerMode : uint8_t {
None = 0,
ButtonShift = 1,
};
enum class TransmissionControllerMode : uint8_t {
None = 0,
SimpleTransmissionController = 1,
Gm4l6x = 2,
};
#endif // __cplusplus

View File

@ -12,7 +12,6 @@
ButtonShiftController buttonShiftController;
ButtonShiftController::ButtonShiftController() :
debounceUp("gear_up"),
debounceDown("gear_down")
@ -81,8 +80,6 @@ void ButtonShiftController::update() {
GearControllerBase::update();
}
void initButtonShift() {
buttonShiftController.init();
engine->gearController = &buttonShiftController;
ButtonShiftController* getButtonShiftController() {
return &buttonShiftController;
}

View File

@ -15,11 +15,12 @@ class ButtonShiftController: public GearControllerBase {
public:
ButtonShiftController();
void update() override;
void init() override;
void update() override;
void init() override;
GearControllerMode mode = GearControllerMode::ButtonShift;
private:
ButtonDebounce debounceUp;
ButtonDebounce debounceDown;
ButtonDebounce debounceUp;
ButtonDebounce debounceDown;
};
void initButtonShift();
ButtonShiftController* getButtonShiftController();

View File

@ -63,6 +63,7 @@ CONTROLLERS_SRC_CPP = \
$(CONTROLLERS_DIR)/gear_controller.cpp \
$(CONTROLLERS_DIR)/start_stop.cpp \
$(CONTROLLERS_DIR)/simple_tcu.cpp \
$(CONTROLLERS_DIR)/tc_4l6x.cpp \
$(CONTROLLERS_DIR)/limp_manager.cpp \
CONTROLLERS_INC=\

View File

@ -224,7 +224,12 @@ static void doPeriodicSlowCallback() {
engine->periodicSlowCallback();
#endif /* if EFI_ENGINE_CONTROL && EFI_SHAFT_POSITION_INPUT */
if (engineConfiguration->tcuEnabled) {
if (engineConfiguration->tcuEnabled && engineConfiguration->gearControllerMode != GearControllerMode::None) {
if (engine->gearController == NULL) {
initGearController();
} else if (engine->gearController->mode != engineConfiguration->gearControllerMode) {
initGearController();
}
engine->gearController->update();
}
}
@ -513,7 +518,7 @@ void commonInitEngineController() {
startIdleThread();
#endif /* EFI_IDLE_CONTROL */
initButtonShift();
initGearController();
initButtonDebounce();
initStartStopButton();

View File

@ -3,15 +3,35 @@
#include "gear_controller.h"
void GearControllerBase::init() {
transmissionController.init();
initTransmissionController();
}
void GearControllerBase::initTransmissionController() {
switch (engineConfiguration->transmissionControllerMode) {
case TransmissionControllerMode::SimpleTransmissionController :
transmissionController = getSimpleTransmissionController();
break;
case TransmissionControllerMode::Gm4l6x :
transmissionController = getGm4l6xTransmissionController();
break;
default :
transmissionController = NULL;
return;
}
transmissionController->init();
}
void GearControllerBase::update() {
// We are responsible for telling the transmission controller
// what gear we want.
transmissionController.update(getDesiredGear());
// Post state to TS
postState();
if (transmissionController == NULL) {
initTransmissionController();
} else if (transmissionController->mode != engineConfiguration->transmissionControllerMode) {
initTransmissionController();
}
// We are responsible for telling the transmission controller
// what gear we want.
transmissionController->update(getDesiredGear());
// Post state to TS
postState();
}
gear_e GearControllerBase::getDesiredGear() const {
@ -28,3 +48,15 @@ void GearControllerBase::postState() {
engine->outputChannels.tcuDesiredGear = getDesiredGear();
#endif
}
void initGearController() {
switch (engineConfiguration->gearControllerMode) {
case GearControllerMode::ButtonShift :
engine->gearController = getButtonShiftController();
break;
default :
engine->gearController = NULL;
return;
}
engine->gearController->init();
}

View File

@ -6,18 +6,23 @@
#include "engine_configuration_generated_structures.h"
#include "globalaccess.h"
#include "simple_tcu.h"
#include "tc_4l6x.h"
class GearControllerBase {
public:
virtual void update();
gear_e getDesiredGear() const;
virtual void init();
virtual void update();
gear_e getDesiredGear() const;
virtual void init();
GearControllerMode mode = GearControllerMode::None;
private:
gear_e desiredGear = NEUTRAL;
gear_e desiredGear = NEUTRAL;
protected:
gear_e setDesiredGear(gear_e);
gear_e setDesiredGear(gear_e);
void initTransmissionController();
private:
void postState();
SimpleTransmissionController transmissionController;
void postState();
TransmissionControllerBase *transmissionController;
};
void initGearController();

View File

@ -2,6 +2,8 @@
#include "simple_tcu.h"
SimpleTransmissionController simpleTransmissionController;
void SimpleTransmissionController::init() {
for (size_t i = 0; i < efi::size(engineConfiguration->tcu_solenoid); i++) {
enginePins.tcuSolenoids[i].initPin("Transmission Solenoid", engineConfiguration->tcu_solenoid[i], &engineConfiguration->tcu_solenoid_mode[i]);
@ -27,3 +29,7 @@ void SimpleTransmissionController::update(gear_e gear) {
}
#endif
}
SimpleTransmissionController* getSimpleTransmissionController() {
return &simpleTransmissionController;
}

View File

@ -1,9 +1,14 @@
#pragma once
#define SIMPLE_TRANSMISSION_CONTROLLER
#include "tcu.h"
class SimpleTransmissionController: public TransmissionControllerBase {
public:
void update(gear_e);
void init();
void update(gear_e);
void init();
TransmissionControllerMode mode = TransmissionControllerMode::SimpleTransmissionController;
};
SimpleTransmissionController* getSimpleTransmissionController();

View File

@ -0,0 +1,35 @@
#include "pch.h"
#include "tc_4l6x.h"
Gm4l6xTransmissionController gm4l6xTransmissionController;
void Gm4l6xTransmissionController::init() {
for (size_t i = 0; i < efi::size(engineConfiguration->tcu_solenoid); i++) {
enginePins.tcuSolenoids[i].initPin("Transmission Solenoid", engineConfiguration->tcu_solenoid[i], &engineConfiguration->tcu_solenoid_mode[i]);
}
}
void Gm4l6xTransmissionController::update(gear_e gear) {
for (size_t i = 0; i < efi::size(engineConfiguration->tcu_solenoid); i++) {
#if ! EFI_UNIT_TEST
enginePins.tcuSolenoids[i].setValue(config->tcuSolenoidTable[static_cast<int>(gear) + 1][i]);
#endif
}
setCurrentGear(gear);
postState();
#if EFI_TUNER_STUDIO
if (engineConfiguration->debugMode == DBG_TCU) {
engine->outputChannels.debugIntField1 = config->tcuSolenoidTable[static_cast<int>(gear) + 1][0];
engine->outputChannels.debugIntField2 = config->tcuSolenoidTable[static_cast<int>(gear) + 1][1];
engine->outputChannels.debugIntField3 = config->tcuSolenoidTable[static_cast<int>(gear) + 1][2];
engine->outputChannels.debugIntField4 = config->tcuSolenoidTable[static_cast<int>(gear) + 1][3];
engine->outputChannels.debugIntField5 = config->tcuSolenoidTable[static_cast<int>(gear) + 1][4];
}
#endif
}
Gm4l6xTransmissionController* getGm4l6xTransmissionController() {
return &gm4l6xTransmissionController;
}

View File

@ -0,0 +1,12 @@
#pragma once
#include "tcu.h"
class Gm4l6xTransmissionController: public TransmissionControllerBase {
public:
void update(gear_e);
void init();
TransmissionControllerMode mode = TransmissionControllerMode::Gm4l6x;
};
Gm4l6xTransmissionController* getGm4l6xTransmissionController();

View File

@ -10,6 +10,9 @@
#include "tcu.h"
void TransmissionControllerBase::init() {
}
void TransmissionControllerBase::update(gear_e gear) {
setCurrentGear(gear);
postState();

View File

@ -15,12 +15,13 @@
class TransmissionControllerBase {
public:
void update(gear_e);
void init();
gear_e getCurrentGear() const;
void update(gear_e);
void init();
gear_e getCurrentGear() const;
TransmissionControllerMode mode = TransmissionControllerMode::None;
private:
gear_e currentGear = NEUTRAL;
gear_e currentGear = NEUTRAL;
protected:
gear_e setCurrentGear(gear_e);
void postState();
gear_e setCurrentGear(gear_e);
void postState();
};

View File

@ -1179,7 +1179,6 @@ int16_t tps2Max;Full throttle#2. tpsMax value as 10 bit ADC value. Not Voltage!\
brain_input_pin_e[2 iterate] auxSpeedSensorInputPin;
uint8_t totalGearsCount;;"", 1, 0, 1, @@GEARS_COUNT@@, 0
uint8_t unused16962;;"", 1, 0, 0, 1, 0
uint32_t uartConsoleSerialSpeed;Band rate for primary TTL;"BPs", 1, 0, 0, 1000000, 0
float tpsDecelEnleanmentThreshold;For decel we simply multiply delta of TPS and tFor decel we do not use table?!;"roc", 1, 0, 0, 200, 1
float tpsDecelEnleanmentMultiplier;Magic multiplier, we multiply delta of TPS and get fuel squirt duration;"coeff", 1, 0, 0, 200, 2
@ -1519,7 +1518,13 @@ uint8_t[TORQUE_CURVE_SIZE x TORQUE_CURVE_SIZE] autoscale torqueTable;;"Nm", 10,
uint16_t[TORQUE_CURVE_SIZE] torqueRpmBins;;"RPM", 1, 0, 0, 65000, 0
uint16_t[TORQUE_CURVE_SIZE] torqueLoadBins;;"Load", 1, 0, 0, 65000, 0
uint8_t[2] unused4750;;"",0,0,0,0,0
#define gear_controller_e_enum "None", "Button Shift"
custom GearControllerMode 1 bits, U08, @OFFSET@, [0:1], @@gear_controller_e_enum@@
GearControllerMode gearControllerMode
#define transmission_controller_e_enum "None", "Simple Transmission", "GM 4L6X"
custom TransmissionControllerMode 1 bits, U08, @OFFSET@, [0:1], @@transmission_controller_e_enum@@
TransmissionControllerMode transmissionControllerMode
linear_sensor_s auxLinear1
linear_sensor_s auxLinear2

View File

@ -3404,6 +3404,8 @@ cmd_set_engine_type_default = "@@TS_IO_TEST_COMMAND_char@@\x00\x31\x00\x00"
dialog = transmissionPanel
field = "TCU Enabled" tcuEnabled
field = "Gear Controller" gearControllerMode
field = "Transmission Controller" transmissionControllerMode
dialog = solenoidPanel, "Shift Solenoids"
field = "Solenoid 1 Pin" tcu_solenoid1, { tcuEnabled }