From 4c93786f1c6cf8adcc0e8d1c4be8e7be1c569aad Mon Sep 17 00:00:00 2001 From: Simon Johnston Date: Tue, 18 Aug 2020 12:22:35 -0700 Subject: [PATCH] Added more examples. --- Cargo.toml | 2 +- README.md | 36 ++++++++++++++++++++++++++++++++++-- src/lib.rs | 37 +++++++++++++++++++++++++++++++++++-- 3 files changed, 70 insertions(+), 5 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 093dce1..1003b77 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "luxafor" -description = "Library, and CLI, for Luxafor lights via webhooks." +description = "Library, and CLI, for Luxafor lights via either USB or webhooks." version = "0.2.0" authors = ["Simon Johnston "] repository = "https://github.com/johnstonskj/rust-luxafor" diff --git a/README.md b/README.md index 5a9c6b9..11ee1d3 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Crate luxafor -Library, and CLI, for [Luxafor](https://luxafor.com/products/) lights via webhooks or USB. +Library, and CLI, for [Luxafor](https://luxafor.com/products/) lights via either USB or webhooks. ![Rust](https://github.com/johnstonskj/rust-luxafor/workflows/Rust/badge.svg) ![Minimum Rust Version](https://img.shields.io/badge/Min%20Rust-1.40-green.svg) @@ -12,7 +12,39 @@ Library, and CLI, for [Luxafor](https://luxafor.com/products/) lights via webhoo This has been tested with the USB connected [flag](https://luxafor.com/flag-usb-busylight-availability-indicator/) as well as the [Bluetooth](https://luxafor.com/bluetooth-busy-light-availability-indicator/) lights. -## Examples +## 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. + +```rust +use luxafor::usb_hid::USBDeviceDiscovery; +use luxafor::{Device, SolidColor}; +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_solid_color(SolidColor::Red, false) +} +``` + +The following shows the same function but using the webhook connection. + +```rust +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. diff --git a/src/lib.rs b/src/lib.rs index bbdddae..f2f2704 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,11 +1,44 @@ /*! -Library, and CLI, for [Luxafor](https://luxafor.com/products/) lights via webhooks or USB. +Library, and CLI, for [Luxafor](https://luxafor.com/products/) lights via either USB or webhooks. This has been tested with the USB connected [flag](https://luxafor.com/flag-usb-busylight-availability-indicator/) as well as the [Bluetooth](https://luxafor.com/bluetooth-busy-light-availability-indicator/) lights. -# Examples + +# 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. + +```rust,norun +use luxafor::usb_hid::USBDeviceDiscovery; +use luxafor::{Device, SolidColor}; +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_solid_color(SolidColor::Red, false) +} +``` + +The following shows the same function but using the webhook connection. + +```rust,norun +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.