Expand description
Control the blink(1) USB RGB LED.
A small synchronous API over hidapi, aimed at wiring a blink(1) into
alerting: red when the build breaks, green when it passes, dark when the
thing that was watching stops running.
§Light it up
use blink1rs::{Blink1, Color};
use std::time::Duration;
let mut b = Blink1::open()?;
b.fade(Color::RED, Duration::from_millis(500))?;
std::thread::sleep(Duration::from_secs(1));
b.off()?;§Watchdog
The device can change its own colour when you stop talking to it, which is the part a desktop notification cannot do. Arm it, then tickle it from your health-check loop; if the loop dies, the light goes red on its own.
use blink1rs::{Blink1, Color, OnTimeout};
use std::time::Duration;
let mut b = Blink1::open()?;
b.set(Color::GREEN)?;
b.write_pattern_line(0, Color::RED, Duration::from_millis(200), blink1rs::Led::All)?;
b.watchdog_enable(Duration::from_secs(30), OnTimeout::PlayPattern { start: 0, end: 0 })?;
loop {
// ... check whatever you are watching ...
b.watchdog_tickle()?;
std::thread::sleep(Duration::from_secs(10));
}§Several devices
Blink1::list sorts by serial number, the same order blink1-tool -d N
uses, so indices agree between the two.
use blink1rs::Blink1;
for info in Blink1::list()? {
println!("{} ({})", info.serial, info.kind);
}§Colours are sent as given
Unlike blink1-tool, gamma correction is off by default, so #ff8000 is
the byte triple the device receives and
read_rgb gives it straight back. Turn it on with
set_gamma to match blink1-tool’s appearance.
§Threads
Blink1 is Send but not Sync: move it into a thread, or share one
behind a Mutex.
Structs§
- Blink1
- An open blink(1).
- Color
- A 24-bit RGB color.
- Device
Info - A blink(1) found by
Blink1::list. - Pattern
Line - One line of the device’s stored colour pattern.
- Play
State - Snapshot of the device’s pattern playback state.
- Startup
Params - Power-on behaviour, readable and writable on firmware 206+ and mk3+.
Enums§
- Boot
Mode - What the device does when it is plugged in.
- Device
Kind - Which generation of blink(1) hardware this is.
- Error
- Errors returned by this crate.
- Led
- Which LED a command addresses.
- OnTimeout
- What the device should do when the watchdog fires.
Constants§
- PRODUCT_
ID - USB product ID for every blink(1) generation.
- VENDOR_
ID - USB vendor ID, ThingM.
Type Aliases§
- Result
- Convenience alias for results from this crate.