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

Structs

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

Enums

Constants

Traits

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

Functions

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