Beacon

Struct Beacon 

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

Implementations§

Source§

impl Beacon

Source

pub fn open() -> Result<Self>

Examples found in repository?
examples/async_touch.rs (line 8)
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}
More examples
Hide additional examples
examples/sync_touch.rs (line 7)
5fn main() -> Result<()> {
6    println!("Opening beacon device...");
7    let beacon = Beacon::open()?;
8    
9    // Set LED to green while waiting
10    beacon.set_light(LedColor::Green, LedPattern::On)?;
11    
12    println!("Example 1: Simple synchronous wait for touch");
13    println!("Please press the touch sensor...");
14    beacon.wait_for_touch_sync()?;
15    println!("Touch detected!");
16    
17    // Set LED to yellow for next test
18    beacon.set_light(LedColor::Yellow, LedPattern::Pattern2)?;
19    
20    println!("\nExample 2: Wait with callback to show state");
21    println!("Press the touch sensor again...");
22    beacon.wait_for_touch_with_callback_sync(|state| {
23        println!("Sensor state: {}", if state { "PRESSED" } else { "RELEASED" });
24    })?;
25    
26    // Set LED to purple for polling
27    beacon.set_light(LedColor::Purple, LedPattern::Pattern3)?;
28    
29    println!("\nExample 3: Poll sensor for 5 seconds");
30    let start = std::time::Instant::now();
31    beacon.poll_touch_sensor_sync(|state| {
32        println!("Polling... state: {}", if state { "PRESSED" } else { "RELEASED" });
33        
34        // Continue polling for 5 seconds
35        start.elapsed() < Duration::from_secs(5)
36    }, Duration::from_millis(100))?;
37    
38    // Turn off LED
39    beacon.reset()?;
40    
41    println!("\nAll examples completed!");
42    Ok(())
43}
Source

pub fn scan() -> Result<Vec<(u8, u8, u16, u16)>>

Source

pub fn set_light(&self, color: LedColor, pattern: LedPattern) -> Result<()>

Examples found in repository?
examples/async_touch.rs (line 11)
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}
More examples
Hide additional examples
examples/sync_touch.rs (line 10)
5fn main() -> Result<()> {
6    println!("Opening beacon device...");
7    let beacon = Beacon::open()?;
8    
9    // Set LED to green while waiting
10    beacon.set_light(LedColor::Green, LedPattern::On)?;
11    
12    println!("Example 1: Simple synchronous wait for touch");
13    println!("Please press the touch sensor...");
14    beacon.wait_for_touch_sync()?;
15    println!("Touch detected!");
16    
17    // Set LED to yellow for next test
18    beacon.set_light(LedColor::Yellow, LedPattern::Pattern2)?;
19    
20    println!("\nExample 2: Wait with callback to show state");
21    println!("Press the touch sensor again...");
22    beacon.wait_for_touch_with_callback_sync(|state| {
23        println!("Sensor state: {}", if state { "PRESSED" } else { "RELEASED" });
24    })?;
25    
26    // Set LED to purple for polling
27    beacon.set_light(LedColor::Purple, LedPattern::Pattern3)?;
28    
29    println!("\nExample 3: Poll sensor for 5 seconds");
30    let start = std::time::Instant::now();
31    beacon.poll_touch_sensor_sync(|state| {
32        println!("Polling... state: {}", if state { "PRESSED" } else { "RELEASED" });
33        
34        // Continue polling for 5 seconds
35        start.elapsed() < Duration::from_secs(5)
36    }, Duration::from_millis(100))?;
37    
38    // Turn off LED
39    beacon.reset()?;
40    
41    println!("\nAll examples completed!");
42    Ok(())
43}
Source

pub fn set_buzzer( &self, pattern: BuzzerPattern, count: BuzzerCount, ) -> Result<()>

Source

pub fn set_volume(&self, volume: BuzzerVolume) -> Result<()>

Source

pub fn set_buzzer_ex( &self, pattern: BuzzerPattern, count: BuzzerCount, volume: BuzzerVolume, ) -> Result<()>

Source

pub fn set_setting(&self, setting: Setting) -> Result<()>

Source

pub fn get_touch_sensor_state(&self) -> Result<bool>

Source

pub fn reset(&self) -> Result<()>

Examples found in repository?
examples/sync_touch.rs (line 39)
5fn main() -> Result<()> {
6    println!("Opening beacon device...");
7    let beacon = Beacon::open()?;
8    
9    // Set LED to green while waiting
10    beacon.set_light(LedColor::Green, LedPattern::On)?;
11    
12    println!("Example 1: Simple synchronous wait for touch");
13    println!("Please press the touch sensor...");
14    beacon.wait_for_touch_sync()?;
15    println!("Touch detected!");
16    
17    // Set LED to yellow for next test
18    beacon.set_light(LedColor::Yellow, LedPattern::Pattern2)?;
19    
20    println!("\nExample 2: Wait with callback to show state");
21    println!("Press the touch sensor again...");
22    beacon.wait_for_touch_with_callback_sync(|state| {
23        println!("Sensor state: {}", if state { "PRESSED" } else { "RELEASED" });
24    })?;
25    
26    // Set LED to purple for polling
27    beacon.set_light(LedColor::Purple, LedPattern::Pattern3)?;
28    
29    println!("\nExample 3: Poll sensor for 5 seconds");
30    let start = std::time::Instant::now();
31    beacon.poll_touch_sensor_sync(|state| {
32        println!("Polling... state: {}", if state { "PRESSED" } else { "RELEASED" });
33        
34        // Continue polling for 5 seconds
35        start.elapsed() < Duration::from_secs(5)
36    }, Duration::from_millis(100))?;
37    
38    // Turn off LED
39    beacon.reset()?;
40    
41    println!("\nAll examples completed!");
42    Ok(())
43}
Source

pub fn wait_for_touch_sync(&self) -> Result<()>

Examples found in repository?
examples/sync_touch.rs (line 14)
5fn main() -> Result<()> {
6    println!("Opening beacon device...");
7    let beacon = Beacon::open()?;
8    
9    // Set LED to green while waiting
10    beacon.set_light(LedColor::Green, LedPattern::On)?;
11    
12    println!("Example 1: Simple synchronous wait for touch");
13    println!("Please press the touch sensor...");
14    beacon.wait_for_touch_sync()?;
15    println!("Touch detected!");
16    
17    // Set LED to yellow for next test
18    beacon.set_light(LedColor::Yellow, LedPattern::Pattern2)?;
19    
20    println!("\nExample 2: Wait with callback to show state");
21    println!("Press the touch sensor again...");
22    beacon.wait_for_touch_with_callback_sync(|state| {
23        println!("Sensor state: {}", if state { "PRESSED" } else { "RELEASED" });
24    })?;
25    
26    // Set LED to purple for polling
27    beacon.set_light(LedColor::Purple, LedPattern::Pattern3)?;
28    
29    println!("\nExample 3: Poll sensor for 5 seconds");
30    let start = std::time::Instant::now();
31    beacon.poll_touch_sensor_sync(|state| {
32        println!("Polling... state: {}", if state { "PRESSED" } else { "RELEASED" });
33        
34        // Continue polling for 5 seconds
35        start.elapsed() < Duration::from_secs(5)
36    }, Duration::from_millis(100))?;
37    
38    // Turn off LED
39    beacon.reset()?;
40    
41    println!("\nAll examples completed!");
42    Ok(())
43}
Source

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

Examples found in repository?
examples/sync_touch.rs (lines 22-24)
5fn main() -> Result<()> {
6    println!("Opening beacon device...");
7    let beacon = Beacon::open()?;
8    
9    // Set LED to green while waiting
10    beacon.set_light(LedColor::Green, LedPattern::On)?;
11    
12    println!("Example 1: Simple synchronous wait for touch");
13    println!("Please press the touch sensor...");
14    beacon.wait_for_touch_sync()?;
15    println!("Touch detected!");
16    
17    // Set LED to yellow for next test
18    beacon.set_light(LedColor::Yellow, LedPattern::Pattern2)?;
19    
20    println!("\nExample 2: Wait with callback to show state");
21    println!("Press the touch sensor again...");
22    beacon.wait_for_touch_with_callback_sync(|state| {
23        println!("Sensor state: {}", if state { "PRESSED" } else { "RELEASED" });
24    })?;
25    
26    // Set LED to purple for polling
27    beacon.set_light(LedColor::Purple, LedPattern::Pattern3)?;
28    
29    println!("\nExample 3: Poll sensor for 5 seconds");
30    let start = std::time::Instant::now();
31    beacon.poll_touch_sensor_sync(|state| {
32        println!("Polling... state: {}", if state { "PRESSED" } else { "RELEASED" });
33        
34        // Continue polling for 5 seconds
35        start.elapsed() < Duration::from_secs(5)
36    }, Duration::from_millis(100))?;
37    
38    // Turn off LED
39    beacon.reset()?;
40    
41    println!("\nAll examples completed!");
42    Ok(())
43}
Source

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

Examples found in repository?
examples/sync_touch.rs (lines 31-36)
5fn main() -> Result<()> {
6    println!("Opening beacon device...");
7    let beacon = Beacon::open()?;
8    
9    // Set LED to green while waiting
10    beacon.set_light(LedColor::Green, LedPattern::On)?;
11    
12    println!("Example 1: Simple synchronous wait for touch");
13    println!("Please press the touch sensor...");
14    beacon.wait_for_touch_sync()?;
15    println!("Touch detected!");
16    
17    // Set LED to yellow for next test
18    beacon.set_light(LedColor::Yellow, LedPattern::Pattern2)?;
19    
20    println!("\nExample 2: Wait with callback to show state");
21    println!("Press the touch sensor again...");
22    beacon.wait_for_touch_with_callback_sync(|state| {
23        println!("Sensor state: {}", if state { "PRESSED" } else { "RELEASED" });
24    })?;
25    
26    // Set LED to purple for polling
27    beacon.set_light(LedColor::Purple, LedPattern::Pattern3)?;
28    
29    println!("\nExample 3: Poll sensor for 5 seconds");
30    let start = std::time::Instant::now();
31    beacon.poll_touch_sensor_sync(|state| {
32        println!("Polling... state: {}", if state { "PRESSED" } else { "RELEASED" });
33        
34        // Continue polling for 5 seconds
35        start.elapsed() < Duration::from_secs(5)
36    }, Duration::from_millis(100))?;
37    
38    // Turn off LED
39    beacon.reset()?;
40    
41    println!("\nAll examples completed!");
42    Ok(())
43}

Trait Implementations§

Source§

impl Drop for Beacon

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl !Freeze for Beacon

§

impl RefUnwindSafe for Beacon

§

impl Send for Beacon

§

impl Sync for Beacon

§

impl Unpin for Beacon

§

impl UnwindSafe for Beacon

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.