From 70662ec4ba1d0ba9edd9d6b7a781c19dec938616 Mon Sep 17 00:00:00 2001 From: Frostie314159 Date: Tue, 29 Aug 2023 08:29:38 +0200 Subject: [PATCH 1/3] embassy-time: Introduced reset function for Ticker --- embassy-time/src/timer.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/embassy-time/src/timer.rs b/embassy-time/src/timer.rs index ad5026e6..8996aefb 100644 --- a/embassy-time/src/timer.rs +++ b/embassy-time/src/timer.rs @@ -133,7 +133,14 @@ impl Ticker { Self { expires_at, duration } } - /// Waits for the next tick + /// Resets the ticker back to its original state. + /// + /// This causes the ticker to go back to zero, even if the current tick isn't over yet. + pub fn reset(&mut self) { + self.expires_at = Instant::now() + self.duration; + } + + /// Waits for the next tick. pub fn next(&mut self) -> impl Future + '_ { poll_fn(|cx| { if self.expires_at <= Instant::now() { From de01fe352b954c58f8c403d30da496d880b7e353 Mon Sep 17 00:00:00 2001 From: Frostie314159 Date: Tue, 29 Aug 2023 08:35:29 +0200 Subject: [PATCH 2/3] Removed unnecessary newline. --- embassy-time/src/timer.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/embassy-time/src/timer.rs b/embassy-time/src/timer.rs index 8996aefb..88134bc6 100644 --- a/embassy-time/src/timer.rs +++ b/embassy-time/src/timer.rs @@ -133,8 +133,7 @@ impl Ticker { Self { expires_at, duration } } - /// Resets the ticker back to its original state. - /// + /// Resets the ticker back to its original state. /// This causes the ticker to go back to zero, even if the current tick isn't over yet. pub fn reset(&mut self) { self.expires_at = Instant::now() + self.duration; From 527bdc57b9c4d5a77f725111570c5add9e646a6b Mon Sep 17 00:00:00 2001 From: Frostie314159 Date: Mon, 11 Sep 2023 08:04:06 +0200 Subject: [PATCH 3/3] Fixed formating. --- embassy-time/src/timer.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/embassy-time/src/timer.rs b/embassy-time/src/timer.rs index 88134bc6..07ddf473 100644 --- a/embassy-time/src/timer.rs +++ b/embassy-time/src/timer.rs @@ -133,7 +133,7 @@ impl Ticker { Self { expires_at, duration } } - /// Resets the ticker back to its original state. + /// Resets the ticker back to its original state. /// This causes the ticker to go back to zero, even if the current tick isn't over yet. pub fn reset(&mut self) { self.expires_at = Instant::now() + self.duration;