start/stop works now

This commit is contained in:
rusefi 2020-04-01 20:25:44 -04:00
parent 26f1ff996b
commit 63246269c7
3 changed files with 64 additions and 55 deletions

View File

@ -252,60 +252,6 @@ static void resetAccel(void) {
}
}
void onStartStopButtonToggle(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
engine->startStopStateToggleCounter++;
if (engine->rpmCalculator.isStopped(PASS_ENGINE_PARAMETER_SIGNATURE)) {
engine->startStopStateLastPushTime = getTimeNowNt();
bool wasStarterEngaged = enginePins.starterControl.getAndSet(1);
if (!wasStarterEngaged) {
scheduleMsg(&logger, "Let's crank this engine for up to %dseconds!", CONFIG(startCrankingDuration));
}
} else if (engine->rpmCalculator.isRunning(PASS_ENGINE_PARAMETER_SIGNATURE)) {
scheduleMsg(&logger, "Let's stop this engine!");
scheduleStopEngine();
}
}
static void slowStartStopButtonCallback(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
if (CONFIG(startStopButtonPin) != GPIO_UNASSIGNED) {
#if EFI_PROD_CODE
bool startStopState = efiReadPin(CONFIG(startStopButtonPin));
if (startStopState && !engine->startStopState) {
// we are here on transition from 0 to 1
onStartStopButtonToggle(PASS_ENGINE_PARAMETER_SIGNATURE);
}
engine->startStopState = startStopState;
#endif /* EFI_PROD_CODE */
}
if (engine->startStopStateLastPushTime == 0) {
// nothing is going on with startStop button
return;
}
// todo: should this be simply FSIO?
if (engine->rpmCalculator.isRunning(PASS_ENGINE_PARAMETER_SIGNATURE)) {
// turn starter off once engine is running
bool wasStarterEngaged = enginePins.starterControl.getAndSet(0);
if (wasStarterEngaged) {
scheduleMsg(&logger, "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(&logger, "Cranking timeout %dseconds", CONFIG(startCrankingDuration));
}
engine->startStopStateLastPushTime = 0;
}
}
static void doPeriodicSlowCallback(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
#if EFI_ENGINE_CONTROL && EFI_SHAFT_POSITION_INPUT
efiAssertVoid(CUSTOM_ERR_6661, getCurrentRemainingStack() > 64, "lowStckOnEv");

View File

@ -18,7 +18,7 @@ void commonInitEngineController(Logging *sharedLogger DECLARE_ENGINE_PARAMETER_S
void initDataStructures(DECLARE_ENGINE_PARAMETER_SIGNATURE);
void touchTimeCounter();
void onStartStopButtonToggle(DECLARE_ENGINE_PARAMETER_SIGNATURE);
void slowStartStopButtonCallback(DECLARE_ENGINE_PARAMETER_SIGNATURE);
#if EFI_ENABLE_MOCK_ADC
void setMockVoltage(int hwChannel, float voltage DECLARE_ENGINE_PARAMETER_SUFFIX);

View File

@ -8,9 +8,12 @@
#include "engine_controller.h"
#include "perf_trace.h"
#include "counter64.h"
#include "settings.h"
EXTERN_ENGINE;
extern LoggingWithStorage sharedLogger;
#if ENABLE_PERF_TRACE
void irqEnterHook(void) {
@ -145,4 +148,64 @@ void touchTimeCounter() {
chSysRestoreStatusX(sts);
}
static void onStartStopButtonToggle(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
engine->startStopStateToggleCounter++;
if (engine->rpmCalculator.isStopped(PASS_ENGINE_PARAMETER_SIGNATURE)) {
engine->startStopStateLastPushTime = getTimeNowNt();
bool wasStarterEngaged = enginePins.starterControl.getAndSet(1);
if (!wasStarterEngaged) {
scheduleMsg(&sharedLogger, "Let's crank this engine for up to %dseconds!", CONFIG(startCrankingDuration));
}
} else if (engine->rpmCalculator.isRunning(PASS_ENGINE_PARAMETER_SIGNATURE)) {
scheduleMsg(&sharedLogger, "Let's stop this engine!");
scheduleStopEngine();
}
}
static bool isFirstStartStopCallback = true;
void slowStartStopButtonCallback(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
if (CONFIG(startStopButtonPin) != GPIO_UNASSIGNED) {
#if EFI_PROD_CODE
bool startStopState = efiReadPin(CONFIG(startStopButtonPin));
if (isFirstStartStopCallback) {
// 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
onStartStopButtonToggle(PASS_ENGINE_PARAMETER_SIGNATURE);
}
engine->startStopState = startStopState;
#endif /* EFI_PROD_CODE */
}
if (engine->startStopStateLastPushTime == 0) {
// nothing is going on with startStop button
return;
}
// todo: should this be simply FSIO?
if (engine->rpmCalculator.isRunning(PASS_ENGINE_PARAMETER_SIGNATURE)) {
// turn starter off once engine is running
bool wasStarterEngaged = enginePins.starterControl.getAndSet(0);
if (wasStarterEngaged) {
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;
}
}
#endif /* EFI_PROD_CODE */