From 7bfa18295a5e87883d3f56e6056f76cb03f74fa9 Mon Sep 17 00:00:00 2001 From: rusefillc Date: Fri, 6 Nov 2020 23:48:35 -0500 Subject: [PATCH] Proteus TCU gear shift configuration #1927 --- firmware/controllers/buttonshift.cpp | 8 ++++++ firmware/controllers/buttonshift.h | 1 + firmware/controllers/engine_controller.cpp | 1 + firmware/controllers/sensors/allsensors.cpp | 2 +- firmware/controllers/start_stop.cpp | 2 +- firmware/hw_layer/debounce.cpp | 32 ++++++++++++++++++++- firmware/hw_layer/debounce.h | 5 ++++ 7 files changed, 48 insertions(+), 3 deletions(-) diff --git a/firmware/controllers/buttonshift.cpp b/firmware/controllers/buttonshift.cpp index 4260bfb660..83f5f9761c 100644 --- a/firmware/controllers/buttonshift.cpp +++ b/firmware/controllers/buttonshift.cpp @@ -12,6 +12,14 @@ EXTERN_ENGINE; ButtonShiftController buttonShiftController; + +ButtonShiftController::ButtonShiftController() : + debounceUp("up"), + debounceDown("down") + { + +} + void ButtonShiftController::init (DECLARE_ENGINE_PARAMETER_SIGNATURE) { // 500 millisecond is maybe a little long? debounceUp.init(500, CONFIG(tcuUpshiftButtonPin), CONFIG(tcuUpshiftButtonPinMode)); diff --git a/firmware/controllers/buttonshift.h b/firmware/controllers/buttonshift.h index 9305c0feb9..5b82587b46 100644 --- a/firmware/controllers/buttonshift.h +++ b/firmware/controllers/buttonshift.h @@ -13,6 +13,7 @@ class ButtonShiftController: public GearControllerBase { public: + ButtonShiftController(); DECLARE_ENGINE_PTR; void update(); void init(DECLARE_ENGINE_PARAMETER_SIGNATURE); diff --git a/firmware/controllers/engine_controller.cpp b/firmware/controllers/engine_controller.cpp index f26cfb271a..80dad7e33f 100644 --- a/firmware/controllers/engine_controller.cpp +++ b/firmware/controllers/engine_controller.cpp @@ -588,6 +588,7 @@ void commonInitEngineController(Logging *sharedLogger DECLARE_ENGINE_PARAMETER_S initButtonShift(PASS_ENGINE_PARAMETER_SIGNATURE); + initButtonDebounce(sharedLogger); initStartStopButton(PASS_ENGINE_PARAMETER_SIGNATURE); #if EFI_ELECTRONIC_THROTTLE_BODY diff --git a/firmware/controllers/sensors/allsensors.cpp b/firmware/controllers/sensors/allsensors.cpp index 829be2d818..44a9e411c0 100644 --- a/firmware/controllers/sensors/allsensors.cpp +++ b/firmware/controllers/sensors/allsensors.cpp @@ -12,7 +12,7 @@ EXTERN_ENGINE; -ButtonDebounce acDebounce; +ButtonDebounce acDebounce("ac"); void initSensors(Logging *sharedLogger DECLARE_ENGINE_PARAMETER_SUFFIX) { initMapDecoder(sharedLogger PASS_ENGINE_PARAMETER_SUFFIX); diff --git a/firmware/controllers/start_stop.cpp b/firmware/controllers/start_stop.cpp index 95cef2307b..9b29d2d08a 100644 --- a/firmware/controllers/start_stop.cpp +++ b/firmware/controllers/start_stop.cpp @@ -3,7 +3,7 @@ EXTERN_ENGINE; -ButtonDebounce startStopButtonDebounce; +ButtonDebounce startStopButtonDebounce("start"); void initStartStopButton(DECLARE_ENGINE_PARAMETER_SIGNATURE) { /* startCrankingDuration is efitimesec_t, so we need to multiply it by 1000 to get milliseconds*/ diff --git a/firmware/hw_layer/debounce.cpp b/firmware/hw_layer/debounce.cpp index def299bb65..daa4da40c9 100644 --- a/firmware/hw_layer/debounce.cpp +++ b/firmware/hw_layer/debounce.cpp @@ -11,6 +11,11 @@ #include "hardware.h" 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 @@ -92,7 +97,12 @@ bool ButtonDebounce::readPinState() { // 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, // but when a method is implemented to actually get the pin's state, - // for example to implement long button presses, it will be needed. + ButtonDebounce *listItem = s_firstDebounce; + while (listItem != nullptr) { + listItem->stopConfiguration(); + listItem = listItem->nextDebounce; + } + // for example to implement long button presses, it will be needed. storedValue = false; #if EFI_PROD_CODE || EFI_UNIT_TEST storedValue = efiReadPin(active_pin); @@ -108,3 +118,23 @@ bool ButtonDebounce::readPinState() { } 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 */ +} diff --git a/firmware/hw_layer/debounce.h b/firmware/hw_layer/debounce.h index b766014016..466d09857f 100644 --- a/firmware/hw_layer/debounce.h +++ b/firmware/hw_layer/debounce.h @@ -15,6 +15,7 @@ class ButtonDebounce { public: + ButtonDebounce(const char *name); void init(efitimems_t threshold, brain_pin_e &pin, pin_input_mode_e &mode); void stopConfiguration(); void startConfiguration(); @@ -22,7 +23,9 @@ public: bool readPinState(); static void stopConfigurationList(); static void startConfigurationList(); + static void debug(); private: + const char *name; efitick_t m_threshold; efitick_t timeLast; brain_pin_e *m_pin; @@ -35,3 +38,5 @@ private: static ButtonDebounce* s_firstDebounce; bool needsInit = false; }; + +void initButtonDebounce(Logging *sharedLogger);