rust-patlite-beacon 0.1.1

A Rust library and CLI tool for controlling USB PATLITE beacon devices
Documentation
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()?;
    
    // Set LED to green while waiting
    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!");
    
    // Set LED to yellow for next test
    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" });
    })?;
    
    // Set LED to purple for polling
    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" });
        
        // Continue polling for 5 seconds
        start.elapsed() < Duration::from_secs(5)
    }, Duration::from_millis(100))?;
    
    // Turn off LED
    beacon.reset()?;
    
    println!("\nAll examples completed!");
    Ok(())
}