use crate::cell::CellView; use crate::transducer::Publisher; use core::cell::Cell; #[cfg(feature = "embassy-sync")] use embassy_sync::blocking_mutex::raw::RawMutex; #[cfg(feature = "embassy-sync")] use embassy_sync::pubsub::PubSubChannel; use embassy_sync::pubsub::{Error, PubSubBehavior, Subscriber}; pub use physical::transducer::input::*; use physical::transducer::Stateful; #[cfg(feature = "embassy-sync")] pub struct RawPublishInput { pub channel: PubSubChannel, } impl RawPublishInput { #[inline(always)] pub fn new(channel: PubSubChannel) -> Self { Self { channel } } #[inline(always)] pub fn update(&self, value: T) { self.channel.publish_immediate(value); } } impl Publisher for RawPublishInput { type Value = T; type Mutex = MutexT; #[inline(always)] fn subscribe( &self, ) -> Result, Error> { self.channel.subscriber() } } #[cfg(feature = "embassy-sync")] pub struct RawStatePubInput< T: Copy, MutexT: RawMutex, const CAPACITY: usize, const NUM_SUBS: usize, > { pub state_cell: Cell, pub channel: PubSubChannel, } impl RawStatePubInput { #[inline(always)] pub fn new( state_cell: Cell, channel: PubSubChannel, ) -> Self { Self { state_cell, channel, } } #[inline] pub fn update(&self, value: T) { self.state_cell.set(value); self.channel.publish_immediate(value); } } impl Stateful for RawStatePubInput { type Value = T; #[inline(always)] fn state_cell(&self) -> CellView { (&self.state_cell).into() } #[inline(always)] fn state(&self) -> Self::Value { self.state_cell.get() } } impl Publisher for RawStatePubInput { type Value = T; type Mutex = MutexT; fn subscribe( &self, ) -> Result, Error> { self.channel.subscriber() } }