diff options
| author | Ulf Lilleengen <[email protected]> | 2022-08-09 12:17:30 +0200 |
|---|---|---|
| committer | Timo Kröger <[email protected]> | 2022-08-26 15:44:58 +0200 |
| commit | af845b7d44228665dffc4432ba509fd80e8400b2 (patch) | |
| tree | 896732fe7f97e9197973c6deceb4cecfb358ca66 /embassy-lora | |
| parent | 308ca4b8e3c4a4ef6c1711528dd7561b75c61aa8 (diff) | |
Add impl for offset radio interface
Diffstat (limited to 'embassy-lora')
| -rw-r--r-- | embassy-lora/src/lib.rs | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/embassy-lora/src/lib.rs b/embassy-lora/src/lib.rs index 1b2dd45c2..2483dcb2e 100644 --- a/embassy-lora/src/lib.rs +++ b/embassy-lora/src/lib.rs | |||
| @@ -11,13 +11,35 @@ pub mod stm32wl; | |||
| 11 | #[cfg(feature = "sx127x")] | 11 | #[cfg(feature = "sx127x")] |
| 12 | pub mod sx127x; | 12 | pub mod sx127x; |
| 13 | 13 | ||
| 14 | #[cfg(feature = "time")] | ||
| 15 | use embassy_time::{Duration, Instant, Timer}; | ||
| 16 | |||
| 14 | /// A convenience timer to use with the LoRaWAN crate | 17 | /// A convenience timer to use with the LoRaWAN crate |
| 15 | pub struct LoraTimer; | 18 | #[cfg(feature = "time")] |
| 19 | pub struct LoraTimer { | ||
| 20 | start: Instant, | ||
| 21 | } | ||
| 22 | |||
| 23 | #[cfg(feature = "time")] | ||
| 24 | impl LoraTimer { | ||
| 25 | pub fn new() -> Self { | ||
| 26 | Self { start: Instant::now() } | ||
| 27 | } | ||
| 28 | } | ||
| 16 | 29 | ||
| 17 | #[cfg(feature = "time")] | 30 | #[cfg(feature = "time")] |
| 18 | impl lorawan_device::async_device::radio::Timer for LoraTimer { | 31 | impl lorawan_device::async_device::radio::Timer for LoraTimer { |
| 32 | fn reset(&mut self) { | ||
| 33 | self.start = Instant::now(); | ||
| 34 | } | ||
| 35 | |||
| 36 | type AtFuture<'m> = impl core::future::Future<Output = ()> + 'm; | ||
| 37 | fn at<'m>(&'m mut self, millis: u64) -> Self::AtFuture<'m> { | ||
| 38 | Timer::at(self.start + Duration::from_millis(millis)) | ||
| 39 | } | ||
| 40 | |||
| 19 | type DelayFuture<'m> = impl core::future::Future<Output = ()> + 'm; | 41 | type DelayFuture<'m> = impl core::future::Future<Output = ()> + 'm; |
| 20 | fn delay_ms<'m>(&'m mut self, millis: u64) -> Self::DelayFuture<'m> { | 42 | fn delay_ms<'m>(&'m mut self, millis: u64) -> Self::DelayFuture<'m> { |
| 21 | embassy_time::Timer::after(embassy_time::Duration::from_millis(millis)) | 43 | Timer::after(Duration::from_millis(millis)) |
| 22 | } | 44 | } |
| 23 | } | 45 | } |
