Proteus TCU gear shift configuration #1927
This commit is contained in:
parent
1eb5d7f927
commit
7bfa18295a
|
@ -12,6 +12,14 @@ EXTERN_ENGINE;
|
||||||
|
|
||||||
ButtonShiftController buttonShiftController;
|
ButtonShiftController buttonShiftController;
|
||||||
|
|
||||||
|
|
||||||
|
ButtonShiftController::ButtonShiftController() :
|
||||||
|
debounceUp("up"),
|
||||||
|
debounceDown("down")
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
void ButtonShiftController::init (DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
void ButtonShiftController::init (DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
||||||
// 500 millisecond is maybe a little long?
|
// 500 millisecond is maybe a little long?
|
||||||
debounceUp.init(500, CONFIG(tcuUpshiftButtonPin), CONFIG(tcuUpshiftButtonPinMode));
|
debounceUp.init(500, CONFIG(tcuUpshiftButtonPin), CONFIG(tcuUpshiftButtonPinMode));
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
|
|
||||||
class ButtonShiftController: public GearControllerBase {
|
class ButtonShiftController: public GearControllerBase {
|
||||||
public:
|
public:
|
||||||
|
ButtonShiftController();
|
||||||
DECLARE_ENGINE_PTR;
|
DECLARE_ENGINE_PTR;
|
||||||
void update();
|
void update();
|
||||||
void init(DECLARE_ENGINE_PARAMETER_SIGNATURE);
|
void init(DECLARE_ENGINE_PARAMETER_SIGNATURE);
|
||||||
|
|
|
@ -588,6 +588,7 @@ void commonInitEngineController(Logging *sharedLogger DECLARE_ENGINE_PARAMETER_S
|
||||||
|
|
||||||
initButtonShift(PASS_ENGINE_PARAMETER_SIGNATURE);
|
initButtonShift(PASS_ENGINE_PARAMETER_SIGNATURE);
|
||||||
|
|
||||||
|
initButtonDebounce(sharedLogger);
|
||||||
initStartStopButton(PASS_ENGINE_PARAMETER_SIGNATURE);
|
initStartStopButton(PASS_ENGINE_PARAMETER_SIGNATURE);
|
||||||
|
|
||||||
#if EFI_ELECTRONIC_THROTTLE_BODY
|
#if EFI_ELECTRONIC_THROTTLE_BODY
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
|
|
||||||
EXTERN_ENGINE;
|
EXTERN_ENGINE;
|
||||||
|
|
||||||
ButtonDebounce acDebounce;
|
ButtonDebounce acDebounce("ac");
|
||||||
|
|
||||||
void initSensors(Logging *sharedLogger DECLARE_ENGINE_PARAMETER_SUFFIX) {
|
void initSensors(Logging *sharedLogger DECLARE_ENGINE_PARAMETER_SUFFIX) {
|
||||||
initMapDecoder(sharedLogger PASS_ENGINE_PARAMETER_SUFFIX);
|
initMapDecoder(sharedLogger PASS_ENGINE_PARAMETER_SUFFIX);
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
EXTERN_ENGINE;
|
EXTERN_ENGINE;
|
||||||
|
|
||||||
ButtonDebounce startStopButtonDebounce;
|
ButtonDebounce startStopButtonDebounce("start");
|
||||||
|
|
||||||
void initStartStopButton(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
void initStartStopButton(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
||||||
/* startCrankingDuration is efitimesec_t, so we need to multiply it by 1000 to get milliseconds*/
|
/* startCrankingDuration is efitimesec_t, so we need to multiply it by 1000 to get milliseconds*/
|
||||||
|
|
|
@ -11,6 +11,11 @@
|
||||||
#include "hardware.h"
|
#include "hardware.h"
|
||||||
|
|
||||||
ButtonDebounce* ButtonDebounce::s_firstDebounce = nullptr;
|
ButtonDebounce* ButtonDebounce::s_firstDebounce = nullptr;
|
||||||
|
static Logging *logger;
|
||||||
|
|
||||||
|
ButtonDebounce::ButtonDebounce(const char *name) {
|
||||||
|
this->name = name;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
We need to have a separate init function because we do not have the pin or mode in the context in which the class is originally created
|
We need to have a separate init function because we do not have the pin or mode in the context in which the class is originally created
|
||||||
|
@ -92,6 +97,11 @@ bool ButtonDebounce::readPinState() {
|
||||||
// storedValue is a class variable, so it needs to be reset.
|
// storedValue is a class variable, so it needs to be reset.
|
||||||
// We don't actually need it to be a class variable in this method,
|
// We don't actually need it to be a class variable in this method,
|
||||||
// but when a method is implemented to actually get the pin's state,
|
// but when a method is implemented to actually get the pin's state,
|
||||||
|
ButtonDebounce *listItem = s_firstDebounce;
|
||||||
|
while (listItem != nullptr) {
|
||||||
|
listItem->stopConfiguration();
|
||||||
|
listItem = listItem->nextDebounce;
|
||||||
|
}
|
||||||
// for example to implement long button presses, it will be needed.
|
// for example to implement long button presses, it will be needed.
|
||||||
storedValue = false;
|
storedValue = false;
|
||||||
#if EFI_PROD_CODE || EFI_UNIT_TEST
|
#if EFI_PROD_CODE || EFI_UNIT_TEST
|
||||||
|
@ -108,3 +118,23 @@ bool ButtonDebounce::readPinState() {
|
||||||
}
|
}
|
||||||
return storedValue;
|
return storedValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ButtonDebounce::debug() {
|
||||||
|
ButtonDebounce *listItem = s_firstDebounce;
|
||||||
|
while (listItem != nullptr) {
|
||||||
|
#if EFI_PROD_CODE || EFI_UNIT_TEST
|
||||||
|
scheduleMsg(logger, "%s timeLast %d", listItem->name, listItem->timeLast);
|
||||||
|
scheduleMsg(logger, "pin %d", efiReadPin(listItem->active_pin));
|
||||||
|
#endif
|
||||||
|
|
||||||
|
listItem = listItem->nextDebounce;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void initButtonDebounce(Logging *sharedLogger) {
|
||||||
|
logger = sharedLogger;
|
||||||
|
|
||||||
|
#if !EFI_UNIT_TEST
|
||||||
|
addConsoleAction("debounce", ButtonDebounce::debug);
|
||||||
|
#endif /* EFI_UNIT_TEST */
|
||||||
|
}
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
|
|
||||||
class ButtonDebounce {
|
class ButtonDebounce {
|
||||||
public:
|
public:
|
||||||
|
ButtonDebounce(const char *name);
|
||||||
void init(efitimems_t threshold, brain_pin_e &pin, pin_input_mode_e &mode);
|
void init(efitimems_t threshold, brain_pin_e &pin, pin_input_mode_e &mode);
|
||||||
void stopConfiguration();
|
void stopConfiguration();
|
||||||
void startConfiguration();
|
void startConfiguration();
|
||||||
|
@ -22,7 +23,9 @@ public:
|
||||||
bool readPinState();
|
bool readPinState();
|
||||||
static void stopConfigurationList();
|
static void stopConfigurationList();
|
||||||
static void startConfigurationList();
|
static void startConfigurationList();
|
||||||
|
static void debug();
|
||||||
private:
|
private:
|
||||||
|
const char *name;
|
||||||
efitick_t m_threshold;
|
efitick_t m_threshold;
|
||||||
efitick_t timeLast;
|
efitick_t timeLast;
|
||||||
brain_pin_e *m_pin;
|
brain_pin_e *m_pin;
|
||||||
|
@ -35,3 +38,5 @@ private:
|
||||||
static ButtonDebounce* s_firstDebounce;
|
static ButtonDebounce* s_firstDebounce;
|
||||||
bool needsInit = false;
|
bool needsInit = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
void initButtonDebounce(Logging *sharedLogger);
|
||||||
|
|
Loading…
Reference in New Issue