Skip to content

Seltiix/blinkstick-rs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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"

About

An unofficial API implementation for BlinkStick devices.

Resources

License

Stars

Watchers

Forks

Languages