parent
5e52aa0ed0
commit
3c8cd08c61
|
@ -281,6 +281,9 @@ Engine::Engine()
|
|||
#if EFI_ANTILAG_SYSTEM
|
||||
, ALSsoftSparkLimiter(false)
|
||||
#endif /* EFI_ANTILAG_SYSTEM */
|
||||
, clutchUpSwitchedState(&engineState.clutchUpState)
|
||||
, brakePedalSwitchedState(&engineState.brakePedalState)
|
||||
, acButtonSwitchedState(&module<AcController>().unmock().acButtonState)
|
||||
|
||||
#endif // EFI_LAUNCH_CONTROL
|
||||
{
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue