rusEFI
The most advanced open source ECU
start_stop.cpp
Go to the documentation of this file.
1 #include "pch.h"
2 
3 /**
4  * See test_start_stop.cpp
5  */
6 
7 #include "start_stop.h"
8 #include "ignition_controller.h"
9 
10 #if EFI_SHAFT_POSITION_INPUT
12  /* startCrankingDuration is efitimesec_t, so we need to multiply it by 1000 to get milliseconds*/
17 }
18 
19 static void onStartStopButtonToggle() {
21 
23  bool wasStarterEngaged = enginePins.starterControl.getAndSet(1);
24  if (!wasStarterEngaged) {
26  efiPrintf("Let's crank this engine for up to %d seconds via %s!",
29  }
30  } else if (engine->rpmCalculator.isRunning()) {
32  }
33 }
34 
35 static void disengageStarterIfNeeded() {
37  // turn starter off once engine is now running!
38  bool wasStarterEngaged = enginePins.starterControl.getAndSet(0);
39  if (wasStarterEngaged) {
40  efiPrintf("Engine runs we can disengage the starter");
41  }
42  } else {
44  bool wasStarterEngaged = enginePins.starterControl.getAndSet(0);
45  if (wasStarterEngaged) {
46  efiPrintf("Cranking timeout %d seconds", engineConfiguration->startCrankingDuration);
47  }
48  }
49  }
50 }
51 
52 PUBLIC_API_WEAK bool isCrankingSuppressed() {
53  return false;
54 }
55 
57  if (!isIgnVoltage()) {
58  // nothing to crank if we are powered only via USB
60  return;
61  } else if (engine->startStopState.isFirstTime) {
62  // initialize when first time with proper power
65  }
66 
68  // where are odd cases of start button combined with ECU power source button we do not want to crank right on start
69  return;
70  }
71 
74  return;
75  }
76 
77  if (isCrankingSuppressed()) {
78  return;
79  }
80  }
81 
83 
85  // we are here on transition from 0 to 1
87  }
88  // todo: we shall extract start_stop.txt from engine_state.txt
91 
92  bool isStarterEngaged = enginePins.starterControl.getLogicValue();
93 
94  if (isStarterEngaged) {
96  }
97 }
98 #endif // EFI_SHAFT_POSITION_INPUT
bool readPinEvent()
void init(efitimems_t threshold, brain_pin_e &pin, pin_input_mode_e &mode, bool inverted=false)
Definition: debounce.cpp:23
bool getPhysicalState()
EngineState engineState
Definition: engine.h:317
SwitchedState brakePedalSwitchedState
Definition: engine.h:191
RpmCalculator rpmCalculator
Definition: engine.h:280
StartStopState startStopState
Definition: engine.h:95
RegisteredOutputPin starterControl
Definition: efi_gpio.h:82
bool getLogicValue() const
Definition: efi_gpio.cpp:651
bool getAndSet(int logicValue)
Definition: efi_gpio.cpp:559
bool isStopped() const override
bool isRunning() const
EnginePins enginePins
Definition: efi_gpio.cpp:24
Engine * engine
bool isIgnVoltage()
engine_configuration_s * engineConfiguration
const char * hwPortname(brain_pin_e brainPin)
startStopState("startStopState", SensorCategory.SENSOR_INPUTS, FieldType.INT8, 1169, 1.0, -1.0, -1.0, "")
void doScheduleStopEngine()
static void onStartStopButtonToggle()
Definition: start_stop.cpp:19
PUBLIC_API_WEAK bool isCrankingSuppressed()
Definition: start_stop.cpp:52
static void disengageStarterIfNeeded()
Definition: start_stop.cpp:35
void slowStartStopButtonCallback()
Definition: start_stop.cpp:56
void initStartStopButton()
Definition: start_stop.cpp:11
Timer timeSinceIgnitionPower
Definition: start_stop.h:7
bool isFirstTime
Definition: start_stop.h:10
ButtonDebounce startStopButtonDebounce
Definition: start_stop.h:6
Timer startStopStateLastPush
Definition: start_stop.h:8
uint32_t startStopStateToggleCounter