# Rust PATLITE Beacon
A Rust library and CLI tool for controlling USB PATLITE beacon devices.
## Features
- Control LED color (off, red, green, yellow, blue, purple, lightblue, white)
- Set LED patterns (solid, pattern1-6)
- Control buzzer patterns (continuous, sweep, intermittent, weak/strong attention, shining star, london bridge)
- Set buzzer volume (0-10)
- Read touch sensor state
- Scan for connected beacon devices
## Installation
```bash
cargo build --release
```
### USB Device Permissions
#### Linux
On Linux, you need to set up udev rules to access the USB beacon without root privileges:
1. Copy the provided udev rules file to your system:
```bash
sudo cp udev/99-patlite-beacon.rules /etc/udev/rules.d/
```
2. Reload the udev rules:
```bash
sudo udevadm control --reload-rules
sudo udevadm trigger
```
3. Disconnect and reconnect your USB beacon device.
After these steps, you should be able to run the beacon commands without sudo.
#### macOS
On macOS, you need to run the beacon commands with root privileges:
```bash
sudo cargo run -- --color red
```
Or if using the compiled binary:
```bash
sudo ./target/release/rust-beacon --color red
```
## Usage
### Quick Start
Set LED to red:
```bash
cargo run -- --color red
```
### Commands
#### Scan for devices
```bash
cargo run -- scan
```
#### Set LED color and pattern
```bash
cargo run -- light red on
cargo run -- light blue pattern1
```
#### Control buzzer
```bash
cargo run -- buzzer sweep 3 # Play sweep sound 3 times
cargo run -- buzzer on 0 # Continuous buzzer
```
#### Set buzzer volume
```bash
cargo run -- volume 5
```
#### Advanced buzzer control (pattern, count, volume)
```bash
cargo run -- buzzer-ex shining-star 2 7
```
#### Read touch sensor
```bash
cargo run -- touch-sensor
```
#### Reset device (turn off LED and buzzer)
```bash
cargo run -- reset
```
#### Connection display settings
```bash
cargo run -- setting on
cargo run -- setting off
```
### Shorthand Options
You can also use shorthand options:
```bash
cargo run -- --color red --pattern pattern1
cargo run -- --buzzer sweep --count 3 --volume 5
```
## Library Usage
```rust
use rust_patlite_beacon::{Beacon, LedColor, LedPattern};
fn main() -> anyhow::Result<()> {
let beacon = Beacon::open()?;
beacon.set_light(LedColor::Red, LedPattern::On)?;
Ok(())
}
```