Proteus TCU gear shift configuration #1927

This commit is contained in:
rusefillc 2020-11-06 23:48:35 -05:00
parent 1eb5d7f927
commit 7bfa18295a
7 changed files with 48 additions and 3 deletions

View File

@ -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));

View File

@ -13,6 +13,7 @@
class ButtonShiftController: public GearControllerBase {
public:
ButtonShiftController();
DECLARE_ENGINE_PTR;
void update();
void init(DECLARE_ENGINE_PARAMETER_SIGNATURE);

View File

@ -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

View File

@ -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);

View File

@ -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*/

View File

@ -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 */
}

View File

@ -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);