Crate luxafor

Crate luxafor 

Source
Expand description

Library, and CLI, for Luxafor lights via either USB or webhooks.

The main entry point for clients is the trait Device that has implementations for USB connected devices such as the flag as well as webhooks for both the flag and bluetooth lights.

Each connection has its own discovery or connection methods but will provide a Device implementation for the manipulation of the light state.

§API Examples

The following example shows a function that sets the light to a solid red color. It demonstrates the use of a USB connected device.

use luxafor::usb_hid::USBDeviceDiscovery;
use luxafor::{Device, SolidColor, TargetedDevice};
use luxafor::error::Result;

fn set_do_not_disturb() -> Result<()> {
    let discovery = USBDeviceDiscovery::new()?;
    let device = discovery.device()?;
    println!("USB device: '{}'", device.id());
    device.set_specific_led(SpecificLED::AllFront);
    device.set_solid_color(SolidColor::Red, false)
}

The following shows the same function but using the webhook connection. Note that the webhook API is more limited in the features it exposes; it does not support set_specific_led for a start.

use luxafor::webhook::new_device_for;
use luxafor::{Device, SolidColor};
use luxafor::error::Result;

fn set_do_not_disturb(device_id: &str) -> Result<()> {
    let device = new_device_for(device_id)?;
    println!("Webhook device: '{}'", device.id());
    device.set_solid_color(SolidColor::Red, false)
}

§CLI Examples

The following shows the command line tool setting the color to red.

❯ lux -d 2a0f2c73b72 solid red

The following shows the command line tool setting the color to a blinking green. This example uses the environment variable LUX_DEVICE to save repeating the device identifier on each call.

❯ export LUX_DEVICE=2a0f2c73b72
❯ lux blink green

The following shows the command line tool turning the light off.

❯ lux -vvv -d 2a0f2c73b72 off
 INFO  luxafor > Setting the color of device '2a0f2c73b72e' to 000000
 INFO  luxafor > call successful

The following shows the how to set USB connected lights.

❯ lux -d usb solid red

§Features

  • command-line; provides the command line tool lux, it is not on by default for library clients.
  • usb; provides access to USB connected devices.
  • webhook (default); provides access to USB, or Bluetooth, devices via webhooks.

Modules§

error
Provides the crate’s Error and Result types as well as helper functions.
usb_hid
Implementation of the Device trait for USB connected lights.
webhook
Implementation of the Device trait for webhook connected lights.

Enums§

Pattern
A pattern the light can be set to show.
SolidColor
A color that the light can be set to.
SpecificLED
Denotes which LED in the light should be the target of any device operations.
Wave
Waves produce a pattern that starts at the bottom of the light, fills the light and then fades out at the top.

Traits§

Device
A trait implemented by different access methods to control a light.
TargetedDevice
Extension trait to allow targeting specific LEDs on the device.