switch start/stop to ButtonDebounce (#1777)
This commit is contained in:
parent
8188ab7d90
commit
f5d9263ad1
|
@ -222,7 +222,6 @@ public:
|
||||||
|
|
||||||
|
|
||||||
bool startStopState = false;
|
bool startStopState = false;
|
||||||
efitick_t startStopStateLastPushTime = 0;
|
|
||||||
int startStopStateToggleCounter = 0;
|
int startStopStateToggleCounter = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -50,6 +50,7 @@ CONTROLLERS_SRC_CPP = \
|
||||||
$(CONTROLLERS_DIR)/serial/serial_sensor.cpp \
|
$(CONTROLLERS_DIR)/serial/serial_sensor.cpp \
|
||||||
$(CONTROLLERS_DIR)/buttonshift.cpp \
|
$(CONTROLLERS_DIR)/buttonshift.cpp \
|
||||||
$(CONTROLLERS_DIR)/tcu.cpp \
|
$(CONTROLLERS_DIR)/tcu.cpp \
|
||||||
|
$(CONTROLLERS_DIR)/start_stop.cpp \
|
||||||
|
|
||||||
CONTROLLERS_INC=\
|
CONTROLLERS_INC=\
|
||||||
$(CONTROLLERS_DIR) \
|
$(CONTROLLERS_DIR) \
|
||||||
|
|
|
@ -58,6 +58,7 @@
|
||||||
#include "gppwm.h"
|
#include "gppwm.h"
|
||||||
#include "date_stamp.h"
|
#include "date_stamp.h"
|
||||||
#include "buttonshift.h"
|
#include "buttonshift.h"
|
||||||
|
#include "start_stop.h"
|
||||||
|
|
||||||
#if EFI_SENSOR_CHART
|
#if EFI_SENSOR_CHART
|
||||||
#include "sensor_chart.h"
|
#include "sensor_chart.h"
|
||||||
|
@ -591,6 +592,8 @@ void commonInitEngineController(Logging *sharedLogger DECLARE_ENGINE_PARAMETER_S
|
||||||
|
|
||||||
initButtonShift(PASS_ENGINE_PARAMETER_SIGNATURE);
|
initButtonShift(PASS_ENGINE_PARAMETER_SIGNATURE);
|
||||||
|
|
||||||
|
initStartStopButton(PASS_ENGINE_PARAMETER_SIGNATURE);
|
||||||
|
|
||||||
#if EFI_ELECTRONIC_THROTTLE_BODY
|
#if EFI_ELECTRONIC_THROTTLE_BODY
|
||||||
initElectronicThrottle(PASS_ENGINE_PARAMETER_SIGNATURE);
|
initElectronicThrottle(PASS_ENGINE_PARAMETER_SIGNATURE);
|
||||||
#endif /* EFI_ELECTRONIC_THROTTLE_BODY */
|
#endif /* EFI_ELECTRONIC_THROTTLE_BODY */
|
||||||
|
|
|
@ -14,6 +14,7 @@ char * getPinNameByAdcChannel(const char *msg, adc_channel_e hwChannel, char *bu
|
||||||
void initPeriodicEvents(DECLARE_ENGINE_PARAMETER_SIGNATURE);
|
void initPeriodicEvents(DECLARE_ENGINE_PARAMETER_SIGNATURE);
|
||||||
void initEngineContoller(Logging *sharedLogger DECLARE_ENGINE_PARAMETER_SUFFIX);
|
void initEngineContoller(Logging *sharedLogger DECLARE_ENGINE_PARAMETER_SUFFIX);
|
||||||
void commonInitEngineController(Logging *sharedLogger DECLARE_ENGINE_PARAMETER_SUFFIX);
|
void commonInitEngineController(Logging *sharedLogger DECLARE_ENGINE_PARAMETER_SUFFIX);
|
||||||
|
void initStartStopButton(DECLARE_ENGINE_PARAMETER_SIGNATURE);
|
||||||
|
|
||||||
void initDataStructures(DECLARE_ENGINE_PARAMETER_SIGNATURE);
|
void initDataStructures(DECLARE_ENGINE_PARAMETER_SIGNATURE);
|
||||||
void touchTimeCounter();
|
void touchTimeCounter();
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
EXTERN_ENGINE;
|
EXTERN_ENGINE;
|
||||||
|
|
||||||
extern LoggingWithStorage sharedLogger;
|
extern LoggingWithStorage sharedLogger;
|
||||||
|
extern ButtonDebounce startStopButtonDebounce;
|
||||||
|
|
||||||
#if ENABLE_PERF_TRACE
|
#if ENABLE_PERF_TRACE
|
||||||
static uint8_t nextThreadId = 0;
|
static uint8_t nextThreadId = 0;
|
||||||
|
@ -154,9 +155,7 @@ void touchTimeCounter() {
|
||||||
static void onStartStopButtonToggle(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
static void onStartStopButtonToggle(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
||||||
engine->startStopStateToggleCounter++;
|
engine->startStopStateToggleCounter++;
|
||||||
|
|
||||||
if (engine->rpmCalculator.isStopped()) {
|
if (engine->rpmCalculator.isStopped(PASS_ENGINE_PARAMETER_SIGNATURE)) {
|
||||||
engine->startStopStateLastPushTime = getTimeNowNt();
|
|
||||||
|
|
||||||
bool wasStarterEngaged = enginePins.starterControl.getAndSet(1);
|
bool wasStarterEngaged = enginePins.starterControl.getAndSet(1);
|
||||||
if (!wasStarterEngaged) {
|
if (!wasStarterEngaged) {
|
||||||
scheduleMsg(&sharedLogger, "Let's crank this engine for up to %dseconds!", CONFIG(startCrankingDuration));
|
scheduleMsg(&sharedLogger, "Let's crank this engine for up to %dseconds!", CONFIG(startCrankingDuration));
|
||||||
|
@ -167,29 +166,16 @@ static void onStartStopButtonToggle(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool isFirstStartStopCallback = true;
|
|
||||||
|
|
||||||
void slowStartStopButtonCallback(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
void slowStartStopButtonCallback(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
||||||
if (CONFIG(startStopButtonPin) != GPIO_UNASSIGNED) {
|
|
||||||
#if EFI_PROD_CODE
|
#if EFI_PROD_CODE
|
||||||
bool startStopState = efiReadPin(CONFIG(startStopButtonPin));
|
bool startStopState = startStopButtonDebounce.readPinEvent();
|
||||||
|
|
||||||
if (isFirstStartStopCallback) {
|
if (startStopState && !engine->startStopState) {
|
||||||
// we just remember initial value on first callback and do not react to it
|
|
||||||
isFirstStartStopCallback = false;
|
|
||||||
} else if (startStopState && !engine->startStopState) {
|
|
||||||
// we are here on transition from 0 to 1
|
// we are here on transition from 0 to 1
|
||||||
onStartStopButtonToggle(PASS_ENGINE_PARAMETER_SIGNATURE);
|
onStartStopButtonToggle(PASS_ENGINE_PARAMETER_SIGNATURE);
|
||||||
}
|
}
|
||||||
engine->startStopState = startStopState;
|
engine->startStopState = startStopState;
|
||||||
#endif /* EFI_PROD_CODE */
|
#endif /* EFI_PROD_CODE */
|
||||||
}
|
|
||||||
|
|
||||||
if (engine->startStopStateLastPushTime == 0) {
|
|
||||||
// nothing is going on with startStop button
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// todo: should this be simply FSIO?
|
// todo: should this be simply FSIO?
|
||||||
if (engine->rpmCalculator.isRunning()) {
|
if (engine->rpmCalculator.isRunning()) {
|
||||||
|
@ -198,15 +184,6 @@ void slowStartStopButtonCallback(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
||||||
if (wasStarterEngaged) {
|
if (wasStarterEngaged) {
|
||||||
scheduleMsg(&sharedLogger, "Engine runs we can disengage the starter");
|
scheduleMsg(&sharedLogger, "Engine runs we can disengage the starter");
|
||||||
}
|
}
|
||||||
engine->startStopStateLastPushTime = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (getTimeNowNt() - engine->startStopStateLastPushTime > NT_PER_SECOND * CONFIG(startCrankingDuration)) {
|
|
||||||
bool wasStarterEngaged = enginePins.starterControl.getAndSet(0);
|
|
||||||
if (wasStarterEngaged) {
|
|
||||||
scheduleMsg(&sharedLogger, "Cranking timeout %dseconds", CONFIG(startCrankingDuration));
|
|
||||||
}
|
|
||||||
engine->startStopStateLastPushTime = 0;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,10 @@
|
||||||
|
#include "start_stop.h"
|
||||||
|
#include "engine.h"
|
||||||
|
|
||||||
|
EXTERN_ENGINE;
|
||||||
|
|
||||||
|
ButtonDebounce startStopButtonDebounce;
|
||||||
|
|
||||||
|
void initStartStopButton(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
||||||
|
startStopButtonDebounce.init(CONFIG(startCrankingDuration), &CONFIG(startStopButtonPin), &CONFIG(startStopButtonMode));
|
||||||
|
}
|
|
@ -0,0 +1,6 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "debounce.h"
|
||||||
|
#include "globalaccess.h"
|
||||||
|
|
||||||
|
void initStartStopButton(DECLARE_ENGINE_PARAMETER_SIGNATURE);
|
|
@ -339,10 +339,6 @@ void applyNewHardwareSettings(void) {
|
||||||
brain_pin_markUnused(activeConfiguration.clutchUpPin);
|
brain_pin_markUnused(activeConfiguration.clutchUpPin);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isPinOrModeChanged(startStopButtonPin, startStopButtonMode)) {
|
|
||||||
brain_pin_markUnused(activeConfiguration.startStopButtonPin);
|
|
||||||
}
|
|
||||||
|
|
||||||
enginePins.unregisterPins();
|
enginePins.unregisterPins();
|
||||||
|
|
||||||
#if EFI_SHAFT_POSITION_INPUT
|
#if EFI_SHAFT_POSITION_INPUT
|
||||||
|
@ -502,12 +498,6 @@ void initHardware(Logging *l) {
|
||||||
initSmartGpio(PASS_ENGINE_PARAMETER_SIGNATURE);
|
initSmartGpio(PASS_ENGINE_PARAMETER_SIGNATURE);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (CONFIG(startStopButtonPin) != GPIO_UNASSIGNED) {
|
|
||||||
efiSetPadMode("start/stop", CONFIG(startStopButtonPin),
|
|
||||||
getInputMode(CONFIG(startStopButtonMode)));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// output pins potentially depend on 'initSmartGpio'
|
// output pins potentially depend on 'initSmartGpio'
|
||||||
initOutputPins(PASS_ENGINE_PARAMETER_SIGNATURE);
|
initOutputPins(PASS_ENGINE_PARAMETER_SIGNATURE);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue