pub struct AsyncBeacon { /* private fields */ }Implementations§
Source§impl AsyncBeacon
impl AsyncBeacon
Sourcepub fn new(beacon: Beacon) -> Self
pub fn new(beacon: Beacon) -> Self
Examples found in repository?
examples/async_touch.rs (line 13)
6async fn main() -> Result<()> {
7 println!("Opening beacon device...");
8 let beacon = Beacon::open()?;
9
10 // Set LED to blue while waiting
11 beacon.set_light(LedColor::Blue, LedPattern::Pattern1)?;
12
13 let async_beacon = AsyncBeacon::new(beacon);
14
15 println!("Example 1: Simple wait for touch");
16 println!("Please press the touch sensor...");
17 async_beacon.wait_for_touch().await?;
18 println!("Touch detected!");
19
20 println!("\nExample 2: Wait with callback to show state");
21 println!("Press the touch sensor again...");
22 async_beacon.wait_for_touch_with_callback(|state| {
23 println!("Sensor state: {}", if state { "PRESSED" } else { "RELEASED" });
24 }).await?;
25
26 println!("\nExample 3: Poll sensor for 5 seconds");
27 let start = std::time::Instant::now();
28 async_beacon.poll_touch_sensor(|state| {
29 println!("Polling... state: {}", if state { "PRESSED" } else { "RELEASED" });
30
31 // Continue polling for 5 seconds
32 start.elapsed() < Duration::from_secs(5)
33 }, Duration::from_millis(100)).await?;
34
35 println!("\nAll examples completed!");
36 Ok(())
37}Sourcepub async fn wait_for_touch(&self) -> Result<()>
pub async fn wait_for_touch(&self) -> Result<()>
Examples found in repository?
examples/async_touch.rs (line 17)
6async fn main() -> Result<()> {
7 println!("Opening beacon device...");
8 let beacon = Beacon::open()?;
9
10 // Set LED to blue while waiting
11 beacon.set_light(LedColor::Blue, LedPattern::Pattern1)?;
12
13 let async_beacon = AsyncBeacon::new(beacon);
14
15 println!("Example 1: Simple wait for touch");
16 println!("Please press the touch sensor...");
17 async_beacon.wait_for_touch().await?;
18 println!("Touch detected!");
19
20 println!("\nExample 2: Wait with callback to show state");
21 println!("Press the touch sensor again...");
22 async_beacon.wait_for_touch_with_callback(|state| {
23 println!("Sensor state: {}", if state { "PRESSED" } else { "RELEASED" });
24 }).await?;
25
26 println!("\nExample 3: Poll sensor for 5 seconds");
27 let start = std::time::Instant::now();
28 async_beacon.poll_touch_sensor(|state| {
29 println!("Polling... state: {}", if state { "PRESSED" } else { "RELEASED" });
30
31 // Continue polling for 5 seconds
32 start.elapsed() < Duration::from_secs(5)
33 }, Duration::from_millis(100)).await?;
34
35 println!("\nAll examples completed!");
36 Ok(())
37}Sourcepub async fn wait_for_touch_with_callback<F>(&self, callback: F) -> Result<()>
pub async fn wait_for_touch_with_callback<F>(&self, callback: F) -> Result<()>
Examples found in repository?
examples/async_touch.rs (lines 22-24)
6async fn main() -> Result<()> {
7 println!("Opening beacon device...");
8 let beacon = Beacon::open()?;
9
10 // Set LED to blue while waiting
11 beacon.set_light(LedColor::Blue, LedPattern::Pattern1)?;
12
13 let async_beacon = AsyncBeacon::new(beacon);
14
15 println!("Example 1: Simple wait for touch");
16 println!("Please press the touch sensor...");
17 async_beacon.wait_for_touch().await?;
18 println!("Touch detected!");
19
20 println!("\nExample 2: Wait with callback to show state");
21 println!("Press the touch sensor again...");
22 async_beacon.wait_for_touch_with_callback(|state| {
23 println!("Sensor state: {}", if state { "PRESSED" } else { "RELEASED" });
24 }).await?;
25
26 println!("\nExample 3: Poll sensor for 5 seconds");
27 let start = std::time::Instant::now();
28 async_beacon.poll_touch_sensor(|state| {
29 println!("Polling... state: {}", if state { "PRESSED" } else { "RELEASED" });
30
31 // Continue polling for 5 seconds
32 start.elapsed() < Duration::from_secs(5)
33 }, Duration::from_millis(100)).await?;
34
35 println!("\nAll examples completed!");
36 Ok(())
37}Sourcepub async fn poll_touch_sensor<F>(
&self,
callback: F,
poll_interval: Duration,
) -> Result<()>
pub async fn poll_touch_sensor<F>( &self, callback: F, poll_interval: Duration, ) -> Result<()>
Examples found in repository?
examples/async_touch.rs (lines 28-33)
6async fn main() -> Result<()> {
7 println!("Opening beacon device...");
8 let beacon = Beacon::open()?;
9
10 // Set LED to blue while waiting
11 beacon.set_light(LedColor::Blue, LedPattern::Pattern1)?;
12
13 let async_beacon = AsyncBeacon::new(beacon);
14
15 println!("Example 1: Simple wait for touch");
16 println!("Please press the touch sensor...");
17 async_beacon.wait_for_touch().await?;
18 println!("Touch detected!");
19
20 println!("\nExample 2: Wait with callback to show state");
21 println!("Press the touch sensor again...");
22 async_beacon.wait_for_touch_with_callback(|state| {
23 println!("Sensor state: {}", if state { "PRESSED" } else { "RELEASED" });
24 }).await?;
25
26 println!("\nExample 3: Poll sensor for 5 seconds");
27 let start = std::time::Instant::now();
28 async_beacon.poll_touch_sensor(|state| {
29 println!("Polling... state: {}", if state { "PRESSED" } else { "RELEASED" });
30
31 // Continue polling for 5 seconds
32 start.elapsed() < Duration::from_secs(5)
33 }, Duration::from_millis(100)).await?;
34
35 println!("\nAll examples completed!");
36 Ok(())
37}Auto Trait Implementations§
impl Freeze for AsyncBeacon
impl RefUnwindSafe for AsyncBeacon
impl Send for AsyncBeacon
impl Sync for AsyncBeacon
impl Unpin for AsyncBeacon
impl UnwindSafe for AsyncBeacon
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more