broadcast button toggle counter #5514

only:fancy boolen with counter
This commit is contained in:
rusefillc 2023-08-22 14:37:17 -04:00
parent 5e52aa0ed0
commit 3c8cd08c61
4 changed files with 36 additions and 9 deletions

View File

@ -281,6 +281,9 @@ Engine::Engine()
#if EFI_ANTILAG_SYSTEM #if EFI_ANTILAG_SYSTEM
, ALSsoftSparkLimiter(false) , ALSsoftSparkLimiter(false)
#endif /* EFI_ANTILAG_SYSTEM */ #endif /* EFI_ANTILAG_SYSTEM */
, clutchUpSwitchedState(&engineState.clutchUpState)
, brakePedalSwitchedState(&engineState.brakePedalState)
, acButtonSwitchedState(&module<AcController>().unmock().acButtonState)
#endif // EFI_LAUNCH_CONTROL #endif // EFI_LAUNCH_CONTROL
{ {

View File

@ -50,6 +50,7 @@
#include "throttle_model.h" #include "throttle_model.h"
#include "gc_generic.h" #include "gc_generic.h"
#include "lambda_monitor.h" #include "lambda_monitor.h"
#include "efi_output.h"
#ifndef EFI_UNIT_TEST #ifndef EFI_UNIT_TEST
#error EFI_UNIT_TEST must be defined! #error EFI_UNIT_TEST must be defined!
@ -337,6 +338,10 @@ public:
AirmassModelBase* mockAirmassModel = nullptr; AirmassModelBase* mockAirmassModel = nullptr;
#endif #endif
SwitchedState clutchUpSwitchedState;
SwitchedState brakePedalSwitchedState;
SwitchedState acButtonSwitchedState;
private: private:
void reset(); void reset();

View File

@ -3,11 +3,20 @@
* *
*/ */
#include "pch.h"
#include "efi_output.h" #include "efi_output.h"
void SwitchState::update(bool newState) {
bool SwitchedState::update(bool newState) {
if (newState != *state) { if (newState != *state) {
*state = newState; *state = newState ? 1 : 0;
counter++; counter++;
return true;
} }
return false;
} }
uint16_t SwitchedState::getCounter() {
return counter;
}

View File

@ -3,20 +3,30 @@
* *
*/ */
#pragma once
#include "io_pins.h" #include "io_pins.h"
#include "smart_gpio.h" #include "smart_gpio.h"
#pragma once
class SwitchState { // This class acts as a boolean, but has a switch counter inside
void init(bool *state, uint16_t *counter) { class SwitchedState {
public:
SwitchedState(int8_t *state) {
this->state = state; this->state = state;
this->counter = counter;
} }
bool *state; // returns true if the state has been changed
uint16_t *counter; bool update(bool newState);
void 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 // Used if you want a function to be virtual only for unit testing purposes