Skip to content

Commit 754de0c

Browse files
committed
etc switch debouncing
1 parent 5b4b59b commit 754de0c

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

ETC/src/etc_controller.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,12 @@ ETCController::ETCController()
2323
this->state.cockpit = false;
2424
}));
2525
this->cockpitSwitchInterrupt.fall(callback([this]() {
26-
this->checkStartConditions();
26+
this->cockpitSwitchTicker.attach(callback([this]() {
27+
if (!cockpitSwitchInterrupt.read()) {
28+
this->checkStartConditions();
29+
}
30+
this->cockpitSwitchTicker.detach();
31+
}), 100ms);
2732
this->state.cockpit = true;
2833
}));
2934
this->reverseSwitchInterrupt.rise(callback([this]() { this->switchForwardMotor(); }));
@@ -131,8 +136,10 @@ void ETCController::checkStartConditions() {
131136

132137

133138
void ETCController::runRTDS() {
134-
this->rtdsOutput.write(true);
135-
this->rtdsTicker.attach(callback([this] {this->stopRTDS();}), 1000ms);
139+
if (!this->rtdsOutput.read()) {
140+
this->rtdsOutput.write(true);
141+
this->rtdsTicker.attach(callback([this] {this->stopRTDS();}), 1000ms);
142+
}
136143
}
137144

138145

ETC/src/etc_controller.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ class ETCController {
7777
/** Timer for the RTDS activation. */
7878
Ticker rtdsTicker;
7979

80+
/** Ticker for debouncing cockpit switch */
81+
Ticker cockpitSwitchTicker;
82+
8083
/** State of the ETC. */
8184
ETCState state;
8285

@@ -153,6 +156,10 @@ class ETCController {
153156
*/
154157
void checkStartConditions();
155158

159+
/**
160+
* Wait and check again before allowing starting
161+
*/
162+
void debounceCockpitSwitch();
156163

157164
/**
158165
* Runs the RTDS buzzer for 3 seconds.

0 commit comments

Comments
 (0)