Skip to content

Commit

Permalink
Update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
avsaase committed Dec 2, 2023
1 parent aa0b11c commit da834eb
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 11 deletions.
15 changes: 10 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

Async button handling crate for `no_std` environments. Built around `embedded-hal 1.0` traits and `embassy-time`.

- [x] Detect button presses without blocking execution of other tasks or unnecessary polling.
- [x] Debouncing
- [x] Detect single and multiple short presses
- [x] Detect long presses
- [ ] Detect sequences of short and long presses or multiple long presses. Open an issue if this would be useful to you, or submit a PR!

## Example

```rust,ignore
Expand All @@ -20,14 +26,13 @@ loop {
## Features

- `defmt`: derives `defmt::Format` on public types (except `Button`).
- `std`: uses `tokio` instead of `embassy-time`. Mainly useful for tests.

## License

Licensed under either of

- Apache License, Version 2.0
([LICENSE-APACHE](LICENSE-APACHE))
- MIT license
([LICENSE-MIT](LICENSE-MIT))

- Apache License, Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE) or <http://www.apache.org/licenses/LICENSE-2.0>)
- MIT license ([LICENSE-MIT](LICENSE-MIT) or <http://opensource.org/licenses/MIT>)

at your option.
10 changes: 5 additions & 5 deletions src/config.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use super::Duration;

/// Various [`Button`](super::Button) parameters.
/// [`Button`](super::Button) configuration.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct ButtonConfig {
Expand Down Expand Up @@ -47,20 +47,20 @@ impl Default for ButtonConfig {
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum Mode {
/// Active 0.
/// Button is connected to a pin with a pull-up resistor. Button pressed it logic 0.
#[default]
PullUp,
/// Active 1.
/// Button is connected to a pin with a pull-down resistor. Button pressed it logic 1.
PullDown,
}

impl Mode {
/// Is button activated by logic zero?
/// Is button connected to a pin with a pull-up resistor?
pub const fn is_pullup(&self) -> bool {
matches!(self, Mode::PullUp)
}

/// Is button activated by logic one?
/// Is button connected to a pin with a pull-down resistor?
pub const fn is_pulldown(&self) -> bool {
!self.is_pullup()
}
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ enum State {
}

/// Detected button events
#[derive(Debug, Clone, Copy, PartialEq)]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum ButtonEvent {
/// A sequence of 1 or more short presses.
Expand Down

0 comments on commit da834eb

Please sign in to comment.