Skip to content

Commit 85093d0

Browse files
committed
run: use kernel hardware debounce instead of broken software impl.
closes #70
1 parent 811117d commit 85093d0

1 file changed

Lines changed: 24 additions & 26 deletions

File tree

crates/shepherd-run/src/runner.rs

Lines changed: 24 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ impl Runner {
4040
let opts = Options::input([config.run.start_button])
4141
.edge(EdgeDetect::Falling)
4242
.bias(Bias::PullUp)
43+
.debounce(Duration::from_millis(250))
4344
.consumer(config.run.service_id.clone());
4445
let lines = chip.request_lines(opts).await?;
4546
Ok((chip, lines))
@@ -241,33 +242,30 @@ impl Runner {
241242
mut lines: Lines<Input>,
242243
sender: UnboundedSender<StateEvent>,
243244
) -> Result<()> {
244-
let mut last_event = Duration::ZERO;
245245
loop {
246-
let event = lines.read_event().await?;
247-
if event.time - last_event >= Duration::from_millis(1000) {
248-
info!("gpio start detected");
249-
last_event = event.time;
250-
251-
let arena_usb = PathBuf::from(&config.path.arena_usb);
252-
253-
// pull zone info from arena usb
254-
let zone = if arena_usb.join("zone1.txt").is_file() {
255-
Zone::from_id(1)
256-
} else if arena_usb.join("zone2.txt").is_file() {
257-
Zone::from_id(2)
258-
} else if arena_usb.join("zone3.txt").is_file() {
259-
Zone::from_id(3)
260-
} else {
261-
// default to zone 0 always
262-
Zone::from_id(0)
263-
};
264-
265-
sender.send(StateEvent::SetTarget(Mode::Comp, zone))?;
266-
sender.send(StateEvent::Transition(
267-
RunState::Running,
268-
Some(RunState::Ready),
269-
))?;
270-
}
246+
let _ = lines.read_event().await?;
247+
248+
info!("gpio start detected");
249+
250+
let arena_usb = PathBuf::from(&config.path.arena_usb);
251+
252+
// pull zone info from arena usb
253+
let zone = if arena_usb.join("zone1.txt").is_file() {
254+
Zone::from_id(1)
255+
} else if arena_usb.join("zone2.txt").is_file() {
256+
Zone::from_id(2)
257+
} else if arena_usb.join("zone3.txt").is_file() {
258+
Zone::from_id(3)
259+
} else {
260+
// default to zone 0 always
261+
Zone::from_id(0)
262+
};
263+
264+
sender.send(StateEvent::SetTarget(Mode::Comp, zone))?;
265+
sender.send(StateEvent::Transition(
266+
RunState::Running,
267+
Some(RunState::Ready),
268+
))?;
271269
}
272270
}
273271

0 commit comments

Comments
 (0)