Skip to main content

device_envoy_esp/button/
button_watch_generated.rs

1// @generated - manually created as documentation example. Do not auto-generate.
2//! Module containing [`ButtonWatchGenerated`], the sample struct type generated by the
3//! [`button_watch!`](crate::button_watch!) macro.
4//!
5//! This file shows what the macro expansion looks like for documentation purposes.
6
7#[cfg(all(not(doc), not(feature = "host"), target_os = "none"))]
8use crate::button_watch;
9
10#[cfg(all(not(doc), not(feature = "host"), target_os = "none"))]
11button_watch! {
12    pub ButtonWatchGenerated {
13        pin: GPIO13,
14    }
15}
16
17#[cfg(doc)]
18/// Sample struct type generated by the [`button_watch!`](crate::button_watch!) macro, showing all methods.
19///
20/// This page serves as the definitive reference for what a generated button watch type
21/// provides. For first-time readers, start with the examples in the [`button_watch!`](crate::button_watch!)
22/// macro documentation, then return here for a complete list of available methods.
23pub struct ButtonWatchGenerated;
24
25#[cfg(doc)]
26impl ButtonWatchGenerated {
27    /// Creates a new button monitor and spawns its background task.
28    ///
29    /// # Parameters
30    ///
31    /// - `button_pin`: GPIO pin for the button
32    /// - `pressed_to`: How the button is wired ([`PressedTo::Ground`](crate::button::PressedTo::Ground) or [`PressedTo::Voltage`](crate::button::PressedTo::Voltage))
33    /// - `spawner`: Task spawner for background operations
34    ///
35    /// # Errors
36    ///
37    /// Returns an error if the background task cannot be spawned.
38    ///
39    /// # Example
40    ///
41    /// See the [`button_watch!`](crate::button_watch!) macro for usage.
42    pub async fn new(
43        button_pin: impl Sized,
44        pressed_to: crate::button::PressedTo,
45        spawner: embassy_executor::Spawner,
46    ) -> crate::Result<&'static mut Self> {
47        static INSTANCE: static_cell::StaticCell<ButtonWatchGenerated> =
48            static_cell::StaticCell::new();
49        let instance = INSTANCE.init(ButtonWatchGenerated);
50        let _ = (button_pin, pressed_to, spawner);
51        Ok(instance)
52    }
53}
54
55#[cfg(doc)]
56impl crate::button::__ButtonMonitor for ButtonWatchGenerated {
57    fn is_pressed_raw(&self) -> bool {
58        false
59    }
60
61    async fn wait_until_pressed_state(&mut self, pressed: bool) {
62        let _ = pressed;
63    }
64}
65
66#[cfg(doc)]
67impl crate::button::Button for ButtonWatchGenerated {}