#devices #color #led #pulse #transform #blink-stick #blinkstick

blinkstick-rs

A library for interacting with any BlinkStick device

8 releases

1.0.2 Nov 19, 2021
0.3.2 Jan 10, 2022
0.3.0 Dec 15, 2021
0.2.3 Dec 10, 2021
0.1.2 Nov 20, 2021

#1125 in Hardware support

MIT license

44KB
521 lines

blinkstick-rs Version License: MIT Documentation

blinkstick-rs provides an interface to control any BlinkStick device using Rust.

Examples

❗ For the non-published updates, please refer to function documentation for the latest examples.

Sets the color of a single led to red

use blinkstick_rs::{BlinkStick, Color};

let blinkstick = BlinkStick::new().unwrap();

blinkstick.set_led_color(0, Color {r: 50, g: 0, b: 0});

Sets a random color to every led on the BlinkStick device

use blinkstick_rs::{BlinkStick, Color};

let blinkstick = BlinkStick::new().unwrap();

let mut colors: Vec<Color> = blinkstick.get_color_vec();
for led in 0..blinkstick.max_leds as usize {
   colors[led] = BlinkStick::get_random_color();
}
blinkstick.set_all_leds_colors(&colors).unwrap();

Makes the 1st, 3rd, 5th LED blink 2 times, once every 200 milliseconds, with a yellow glow

use blinkstick_rs::{BlinkStick, Color};

let blinkstick = BlinkStick::new().unwrap();

blinkstick.blink_multiple_leds_color(&vec![1, 3, 5], std::time::Duration::from_millis(200), 2, Color {r: 50, g: 50, b: 0}).unwrap();

Makes every led pulse between being turned off and a green color

use blinkstick_rs::{BlinkStick, Color};

let blinkstick = BlinkStick::new().unwrap();

let color = Color {r: 0, g: 25, b: 0};
blinkstick.pulse_all_leds_color(std::time::Duration::from_secs(2), 50, Color {r: 0, g: 25, b: 0}).unwrap();

Makes the first led transform from a red color into a green color over a period of five seconds, with 50 color updates.

use blinkstick_rs::{BlinkStick, Color};

let blinkstick = BlinkStick::new().unwrap();

blinkstick.set_led_color(1, Color {r: 50, g: 0, b: 0}).unwrap();
blinkstick.transform_led_color(1, std::time::Duration::from_secs(5), 50, Color {r: 0, g: 50, b: 0}).unwrap();

Running tests

Tests are only runnable when a BlinkStick device is plugged in. Furthermore, tests should be run using cargo test -- --test-threads=1 or they might fail.

Dependencies

Linux

  • libusb - Can be installed using for example "apt install usbutils" or "yum install usbutils"

Dependencies

~0.6–1.2MB
~22K SLoC