diff --git a/firmware/controllers/algo/engine.cpp b/firmware/controllers/algo/engine.cpp index 470ccea48c..6a805b7f8d 100644 --- a/firmware/controllers/algo/engine.cpp +++ b/firmware/controllers/algo/engine.cpp @@ -281,6 +281,9 @@ Engine::Engine() #if EFI_ANTILAG_SYSTEM , ALSsoftSparkLimiter(false) #endif /* EFI_ANTILAG_SYSTEM */ + , clutchUpSwitchedState(&engineState.clutchUpState) + , brakePedalSwitchedState(&engineState.brakePedalState) + , acButtonSwitchedState(&module().unmock().acButtonState) #endif // EFI_LAUNCH_CONTROL { diff --git a/firmware/controllers/algo/engine.h b/firmware/controllers/algo/engine.h index 43ea29b6cf..0f39d879da 100644 --- a/firmware/controllers/algo/engine.h +++ b/firmware/controllers/algo/engine.h @@ -50,6 +50,7 @@ #include "throttle_model.h" #include "gc_generic.h" #include "lambda_monitor.h" +#include "efi_output.h" #ifndef EFI_UNIT_TEST #error EFI_UNIT_TEST must be defined! @@ -337,6 +338,10 @@ public: AirmassModelBase* mockAirmassModel = nullptr; #endif + SwitchedState clutchUpSwitchedState; + SwitchedState brakePedalSwitchedState; + SwitchedState acButtonSwitchedState; + private: void reset(); diff --git a/firmware/controllers/system/efi_output.cpp b/firmware/controllers/system/efi_output.cpp index b2dd60ff0e..b87dd453cf 100644 --- a/firmware/controllers/system/efi_output.cpp +++ b/firmware/controllers/system/efi_output.cpp @@ -3,11 +3,20 @@ * */ +#include "pch.h" #include "efi_output.h" -void SwitchState::update(bool newState) { + +bool SwitchedState::update(bool newState) { if (newState != *state) { - *state = newState; + *state = newState ? 1 : 0; counter++; + return true; } + return false; } + +uint16_t SwitchedState::getCounter() { + return counter; +} + diff --git a/firmware/controllers/system/efi_output.h b/firmware/controllers/system/efi_output.h index 7a1c8560e3..1789afafe8 100644 --- a/firmware/controllers/system/efi_output.h +++ b/firmware/controllers/system/efi_output.h @@ -3,20 +3,30 @@ * */ +#pragma once + #include "io_pins.h" #include "smart_gpio.h" -#pragma once -class SwitchState { - void init(bool *state, uint16_t *counter) { +// This class acts as a boolean, but has a switch counter inside +class SwitchedState { +public: + SwitchedState(int8_t *state) { this->state = state; - this->counter = counter; } - bool *state; - uint16_t *counter; - void update(bool newState); + // returns true if the state has been changed + bool update(bool newState); + uint16_t getCounter(); + + operator bool() const { + return (bool)*state; + } + +private: + int8_t *state; + uint16_t counter = 0; }; // Used if you want a function to be virtual only for unit testing purposes