Skip to content

Commit 351ae5b

Browse files
author
Felipe Balbi
committed
Add minimal button tests
This commit adds a minimal set of tests for the button logic. Notice that this is, indeed, a breaking a change and coordination with dependent crates is required.
1 parent 62ddb55 commit 351ae5b

File tree

7 files changed

+560
-30
lines changed

7 files changed

+560
-30
lines changed

Cargo.lock

Lines changed: 237 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

power-button-service/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,7 @@ embassy-time.workspace = true
1313
embedded-hal-async.workspace = true
1414
embedded-hal.workspace = true
1515
log = { workspace = true, optional = true }
16+
17+
[dev-dependencies]
18+
embedded-hal-mock = { version = "0.11.1", features = ["eh1", "embedded-hal-async"] }
19+
tokio = { version = "1.45.0", features = ["rt", "macros"] }

power-button-service/src/button.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! Button Service Definitions
22
3-
use embassy_time::{with_timeout, Duration, Instant, TimeoutError, Timer};
3+
use embassy_time::{with_timeout, Delay, Duration, Instant, TimeoutError, Timer};
44
use embedded_hal::digital::InputPin;
55
use embedded_hal_async::digital::Wait;
66

@@ -48,7 +48,9 @@ impl<I: InputPin + Wait> Button<I> {
4848

4949
/// Checks button state.
5050
pub async fn get_button_state(&mut self) -> ButtonState {
51-
match self.config.debouncer.debounce(&mut self.gpio).await {
51+
let mut delay = Delay;
52+
53+
match self.config.debouncer.debounce(&mut self.gpio, &mut delay).await {
5254
true => ButtonState::ButtonPressed(Instant::now()),
5355
false => ButtonState::ButtonReleased(Instant::now()),
5456
}

0 commit comments

Comments
 (0)