Struct esp32_simple::gps::Sensor
source · pub struct Sensor<'a, T: Trigger> { /* private fields */ }Expand description
Represents a GPS sensor.
§Type Parameters
'a- Lifetime of the sensor.T- The trigger type implementing theTriggertrait.
Implementations§
source§impl<'a, T: Trigger> Sensor<'a, T>
impl<'a, T: Trigger> Sensor<'a, T>
sourcepub fn new(
notifier: Notifier<T>,
trigger: &'static T,
state: Arc<Mutex<State>>,
uart: UartRxDriver<'a>,
data: Arc<Mutex<Option<Reading>>>,
) -> Self
pub fn new( notifier: Notifier<T>, trigger: &'static T, state: Arc<Mutex<State>>, uart: UartRxDriver<'a>, data: Arc<Mutex<Option<Reading>>>, ) -> Self
Creates a new GPS Sensor.
§Arguments
notifier- A notifier to send GPS data available events.trigger- The trigger to emit when a new reading is available.state- Shared on/off state controlling whether the sensor reads data.uart- UART receive driver connected to the GPS module.data- Shared storage for the latest GPS reading.
§Returns
A new Sensor instance ready to poll.
Trait Implementations§
source§impl<T: Trigger> Poller for Sensor<'_, T>
impl<T: Trigger> Poller for Sensor<'_, T>
source§fn poll(&mut self) -> Result<!>
fn poll(&mut self) -> Result<!>
Continuously reads NMEA sentences from the UART and publishes GPS readings.
Skips reading when the shared state is off. When a valid RMC sentence is parsed, stores the reading in the shared data mutex and sends a notification.
§Errors
Returns an error if UART reading, mutex locking, or notification fails.