Rename timeout_at to with_deadline
This commit is contained in:
parent
1e698af05b
commit
8b7d856195
@ -32,7 +32,7 @@ pub use delay::{block_for, Delay};
|
|||||||
pub use duration::Duration;
|
pub use duration::Duration;
|
||||||
pub use embassy_time_driver::TICK_HZ;
|
pub use embassy_time_driver::TICK_HZ;
|
||||||
pub use instant::Instant;
|
pub use instant::Instant;
|
||||||
pub use timer::{timeout_at, with_timeout, Ticker, TimeoutError, Timer};
|
pub use timer::{with_deadline, with_timeout, Ticker, TimeoutError, Timer};
|
||||||
|
|
||||||
const fn gcd(a: u64, b: u64) -> u64 {
|
const fn gcd(a: u64, b: u64) -> u64 {
|
||||||
if b == 0 {
|
if b == 0 {
|
||||||
|
|||||||
@ -30,7 +30,7 @@ pub async fn with_timeout<F: Future>(timeout: Duration, fut: F) -> Result<F::Out
|
|||||||
///
|
///
|
||||||
/// If the future completes before the deadline, its output is returned. Otherwise, on timeout,
|
/// If the future completes before the deadline, its output is returned. Otherwise, on timeout,
|
||||||
/// work on the future is stopped (`poll` is no longer called), the future is dropped and `Err(TimeoutError)` is returned.
|
/// work on the future is stopped (`poll` is no longer called), the future is dropped and `Err(TimeoutError)` is returned.
|
||||||
pub async fn timeout_at<F: Future>(at: Instant, fut: F) -> Result<F::Output, TimeoutError> {
|
pub async fn with_deadline<F: Future>(at: Instant, fut: F) -> Result<F::Output, TimeoutError> {
|
||||||
let timeout_fut = Timer::at(at);
|
let timeout_fut = Timer::at(at);
|
||||||
pin_mut!(fut);
|
pin_mut!(fut);
|
||||||
match select(fut, timeout_fut).await {
|
match select(fut, timeout_fut).await {
|
||||||
|
|||||||
@ -7,7 +7,7 @@
|
|||||||
use defmt::info;
|
use defmt::info;
|
||||||
use embassy_executor::Spawner;
|
use embassy_executor::Spawner;
|
||||||
use embassy_rp::gpio::{Input, Level, Pull};
|
use embassy_rp::gpio::{Input, Level, Pull};
|
||||||
use embassy_time::{timeout_at, Duration, Instant, Timer};
|
use embassy_time::{with_deadline, Duration, Instant, Timer};
|
||||||
use {defmt_rtt as _, panic_probe as _};
|
use {defmt_rtt as _, panic_probe as _};
|
||||||
|
|
||||||
pub struct Debouncer<'a> {
|
pub struct Debouncer<'a> {
|
||||||
@ -49,7 +49,7 @@ async fn main(_spawner: Spawner) {
|
|||||||
let start = Instant::now();
|
let start = Instant::now();
|
||||||
info!("Button Press");
|
info!("Button Press");
|
||||||
|
|
||||||
match timeout_at(start + Duration::from_secs(1), btn.debounce()).await {
|
match with_deadline(start + Duration::from_secs(1), btn.debounce()).await {
|
||||||
// Button Released < 1s
|
// Button Released < 1s
|
||||||
Ok(_) => {
|
Ok(_) => {
|
||||||
info!("Button pressed for: {}ms", start.elapsed().as_millis());
|
info!("Button pressed for: {}ms", start.elapsed().as_millis());
|
||||||
@ -61,7 +61,7 @@ async fn main(_spawner: Spawner) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
match timeout_at(start + Duration::from_secs(5), btn.debounce()).await {
|
match with_deadline(start + Duration::from_secs(5), btn.debounce()).await {
|
||||||
// Button released <5s
|
// Button released <5s
|
||||||
Ok(_) => {
|
Ok(_) => {
|
||||||
info!("Button pressed for: {}ms", start.elapsed().as_millis());
|
info!("Button pressed for: {}ms", start.elapsed().as_millis());
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user