pub struct Beacon { /* private fields */ }Implementations§
Source§impl Beacon
impl Beacon
Sourcepub fn open() -> Result<Self>
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
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}pub fn scan() -> Result<Vec<(u8, u8, u16, u16)>>
Sourcepub fn set_light(&self, color: LedColor, pattern: LedPattern) -> Result<()>
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
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}pub fn set_buzzer( &self, pattern: BuzzerPattern, count: BuzzerCount, ) -> Result<()>
pub fn set_volume(&self, volume: BuzzerVolume) -> Result<()>
pub fn set_buzzer_ex( &self, pattern: BuzzerPattern, count: BuzzerCount, volume: BuzzerVolume, ) -> Result<()>
pub fn set_setting(&self, setting: Setting) -> Result<()>
pub fn get_touch_sensor_state(&self) -> Result<bool>
Sourcepub fn reset(&self) -> Result<()>
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}Sourcepub fn wait_for_touch_sync(&self) -> Result<()>
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}Sourcepub fn wait_for_touch_with_callback_sync<F>(&self, callback: F) -> Result<()>
pub fn wait_for_touch_with_callback_sync<F>(&self, callback: F) -> Result<()>
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}Sourcepub fn poll_touch_sensor_sync<F>(
&self,
callback: F,
poll_interval: Duration,
) -> Result<()>
pub fn poll_touch_sensor_sync<F>( &self, callback: F, poll_interval: Duration, ) -> Result<()>
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§
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> 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