Crate cherryrgb

Crate cherryrgb 

Source
Expand description

Library to interact with Cherry RGB keyboards

§Usage

Find usb keyboard and initialize it

use cherryrgb::{self, CherryKeyboard};

// Optionally, filter for product id if you have more than one cherry device.
let devices = cherryrgb::find_devices(Some(0x00dd)).unwrap();
let (vendor_id, product_id) = devices.first().unwrap().to_owned();
let keyboard = CherryKeyboard::new(vendor_id, product_id).unwrap();

keyboard.fetch_device_state().unwrap();

Set LED animation

use cherryrgb::rgb::RGB8;

// Create color: green
let color = RGB8::new(0, 0xff, 0);
let use_rainbow_colors: bool = false;

keyboard.set_led_animation(
    cherryrgb::LightingMode::Rain,
    cherryrgb::Brightness::Full,
    cherryrgb::Speed::Slow,
    color,
    use_rainbow_colors,
)
.unwrap();

Set custom LED color for individual key(s)

use cherryrgb::rgb::RGB8;

// Reset all colors first
keyboard.reset_custom_colors().unwrap();

// Create color: green
let color = RGB8::new(0, 0xff, 0);

// Create keys struct and set key with index 42 to desired color
let mut keys = cherryrgb::CustomKeyLeds::new();
keys.set_led(42, color).unwrap();

// Send packets to keyboard
keyboard.set_custom_colors(keys).unwrap();

Re-exports§

pub use hex;
pub use rgb;
pub use rusb;

Structs§

CherryKeyboard
Holds a handle to the USB keyboard device
CustomKeyLeds
Wrapper around custom LED color for all keys
OwnRGB8
Wrap around RGB8 type, to implement traits on it
Packet
Common packet structure
RpcAnimation
Parameters for set_led_animation (sent serialized from cherryrgb_ncli to cherryrgb_service).
VirtKbd
Virtual HID device for injecting key events into the Linux HID subsystem

Enums§

Brightness
LED brightness
CherryRgbError
LightingMode
Mode attributes: -> C: Supports color option -> S: Supports speed option -> U: Unofficial
Payload
Payloads
Speed
LED animation speed

Constants§

CHERRY_USB_VID
USB Vendor ID - Cherry GmbH

Traits§

ToVec
Shorthand for structs implementing BinWrite to serialize into Vec<u8>

Functions§

find_devices
Find supported Cherry USB keyboards and return collection of (vendor_id, product_id)
read_color_profile
Reads the given color profile and returns a vector of ProfileKey.