device-envoy-rp 0.1.0

Build Pico applications with LED panels, easy Wi-Fi, and composable device abstractions
Documentation
// @generated - manually created as documentation example. Do not auto-generate.
//! Module containing [`ButtonWatchGenerated`], the sample struct type generated by the
//! [`button_watch!`](crate::button_watch!) macro.
//!
//! This file shows what the macro expansion looks like for documentation purposes.

#[cfg(all(not(doc), not(feature = "host")))]
use crate::button_watch;

#[cfg(all(not(doc), not(feature = "host")))]
button_watch! {
    pub ButtonWatchGenerated {
        pin: PIN_13,
    }
}

#[cfg(doc)]
/// Sample struct type generated by the [`button_watch!`](crate::button_watch!) macro, showing all methods.
///
/// This page serves as the definitive reference for what a generated button watch type
/// provides. For first-time readers, start with the examples in the [`button_watch!`](crate::button_watch!) macro
/// documentation, then return here for a complete list of available methods.
pub struct ButtonWatchGenerated {
    button_watch: super::ButtonWatchRp,
}

#[cfg(doc)]
impl ButtonWatchGenerated {
    /// Creates a new button monitor and spawns its background task.
    ///
    /// # Parameters
    ///
    /// - `pin`: GPIO pin for the button
    /// - `pressed_to`: How the button is wired ([`PressedTo::Ground`](crate::button::PressedTo::Ground) or [`PressedTo::Voltage`](crate::button::PressedTo::Voltage))
    /// - `spawner`: Task spawner for background operations
    ///
    /// # Errors
    ///
    /// Returns an error if the background task cannot be spawned.
    ///
    /// # Example
    ///
    /// See the [`button_watch!`](crate::button_watch!) macro for usage.
    pub fn new(
        pin: impl Into<embassy_rp::Peri<'static, embassy_rp::peripherals::PIN_13>>,
        pressed_to: crate::button::PressedTo,
        spawner: embassy_executor::Spawner,
    ) -> crate::Result<&'static mut Self> {
        static INSTANCE: static_cell::StaticCell<ButtonWatchGenerated> =
            static_cell::StaticCell::new();
        let instance = INSTANCE.init(ButtonWatchGenerated {
            button_watch: super::ButtonWatchRp {
                signal: &embassy_sync::signal::Signal::new(),
                state_signal: &embassy_sync::signal::Signal::new(),
                is_pressed: &core::sync::atomic::AtomicBool::new(false),
            },
        });
        let _ = (pin, pressed_to, spawner);
        Ok(instance)
    }
}

#[cfg(doc)]
impl core::ops::Deref for ButtonWatchGenerated {
    type Target = super::ButtonWatchRp;

    fn deref(&self) -> &Self::Target {
        &self.button_watch
    }
}

#[cfg(doc)]
impl crate::button::__ButtonMonitor for ButtonWatchGenerated {
    fn is_pressed_raw(&self) -> bool {
        <super::ButtonWatchRp as crate::button::Button>::is_pressed(&self.button_watch)
    }

    async fn wait_until_pressed_state(&mut self, pressed: bool) {
        <super::ButtonWatchRp as crate::button::__ButtonMonitor>::wait_until_pressed_state(
            &mut self.button_watch,
            pressed,
        )
        .await
    }
}

#[cfg(doc)]
impl crate::button::Button for ButtonWatchGenerated {
    async fn wait_for_press_duration(&mut self) -> crate::button::PressDuration {
        <super::ButtonWatchRp as crate::button::Button>::wait_for_press_duration(
            &mut self.button_watch,
        )
        .await
    }
}