From 9238aa454ef82e738ec3c9b50a7d7343ec427303 Mon Sep 17 00:00:00 2001 From: Matthew Kennedy Date: Sun, 6 Dec 2020 06:32:38 -0600 Subject: [PATCH] fix button shift inheritance (#2027) * fix button shift inheritance * extra Co-authored-by: Matthew Kennedy --- firmware/controllers/buttonshift.cpp | 19 ++++++++----------- firmware/controllers/buttonshift.h | 6 +++--- firmware/controllers/gear_controller.cpp | 5 ++++- firmware/controllers/gear_controller.h | 4 +++- 4 files changed, 18 insertions(+), 16 deletions(-) diff --git a/firmware/controllers/buttonshift.cpp b/firmware/controllers/buttonshift.cpp index 5713cc8139..f1dc8414d8 100644 --- a/firmware/controllers/buttonshift.cpp +++ b/firmware/controllers/buttonshift.cpp @@ -20,12 +20,12 @@ ButtonShiftController::ButtonShiftController() : } -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::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)); + + GearControllerBase::init(PASS_ENGINE_PARAMETER_SIGNATURE); } void ButtonShiftController::update() { @@ -77,11 +77,8 @@ void ButtonShiftController::update() { break; } } - // We are responsible for telling the transmission controller - // what gear we want. - transmissionController.update(getDesiredGear()); - // Post state to TS - postState(); + + GearControllerBase::update(); } diff --git a/firmware/controllers/buttonshift.h b/firmware/controllers/buttonshift.h index 5b82587b46..e781cb5bf0 100644 --- a/firmware/controllers/buttonshift.h +++ b/firmware/controllers/buttonshift.h @@ -14,9 +14,9 @@ class ButtonShiftController: public GearControllerBase { public: ButtonShiftController(); - DECLARE_ENGINE_PTR; - void update(); - void init(DECLARE_ENGINE_PARAMETER_SIGNATURE); + + void update() override; + void init(DECLARE_ENGINE_PARAMETER_SIGNATURE) override; private: ButtonDebounce debounceUp; ButtonDebounce debounceDown; diff --git a/firmware/controllers/gear_controller.cpp b/firmware/controllers/gear_controller.cpp index 40aba538a0..0bd2f258c1 100644 --- a/firmware/controllers/gear_controller.cpp +++ b/firmware/controllers/gear_controller.cpp @@ -1,13 +1,16 @@ #include "gear_controller.h" #include "tunerstudio_outputs.h" -void GearControllerBase::init() { +void GearControllerBase::init(DECLARE_ENGINE_PARAMETER_SIGNATURE) { INJECT_ENGINE_REFERENCE(&transmissionController); 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(); } diff --git a/firmware/controllers/gear_controller.h b/firmware/controllers/gear_controller.h index 2dab9a3b1f..15c02fdf02 100644 --- a/firmware/controllers/gear_controller.h +++ b/firmware/controllers/gear_controller.h @@ -13,11 +13,13 @@ public: virtual void update(); gear_e getDesiredGear() const; - virtual void init(); + virtual void init(DECLARE_ENGINE_PARAMETER_SIGNATURE); private: gear_e desiredGear = NEUTRAL; protected: gear_e setDesiredGear(gear_e); + +private: void postState(); SimpleTransmissionController transmissionController; };