AsyncBeacon

Struct AsyncBeacon 

Source
pub struct AsyncBeacon { /* private fields */ }

Implementations§

Source§

impl AsyncBeacon

Source

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}
Source

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}
Source

pub async fn wait_for_touch_with_callback<F>(&self, callback: F) -> Result<()>
where F: FnMut(bool),

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}
Source

pub async fn poll_touch_sensor<F>( &self, callback: F, poll_interval: Duration, ) -> Result<()>
where F: FnMut(bool) -> bool,

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§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.