use anyhow::Result;
use rust_patlite_beacon::{Beacon, LedColor, LedPattern};
use std::time::Duration;
fn main() -> Result<()> {
println!("Opening beacon device...");
let beacon = Beacon::open()?;
beacon.set_light(LedColor::Green, LedPattern::On)?;
println!("Example 1: Simple synchronous wait for touch");
println!("Please press the touch sensor...");
beacon.wait_for_touch_sync()?;
println!("Touch detected!");
beacon.set_light(LedColor::Yellow, LedPattern::Pattern2)?;
println!("\nExample 2: Wait with callback to show state");
println!("Press the touch sensor again...");
beacon.wait_for_touch_with_callback_sync(|state| {
println!("Sensor state: {}", if state { "PRESSED" } else { "RELEASED" });
})?;
beacon.set_light(LedColor::Purple, LedPattern::Pattern3)?;
println!("\nExample 3: Poll sensor for 5 seconds");
let start = std::time::Instant::now();
beacon.poll_touch_sensor_sync(|state| {
println!("Polling... state: {}", if state { "PRESSED" } else { "RELEASED" });
start.elapsed() < Duration::from_secs(5)
}, Duration::from_millis(100))?;
beacon.reset()?;
println!("\nAll examples completed!");
Ok(())
}