Added more examples.

This commit is contained in:
Simon Johnston 2020-08-18 12:22:35 -07:00
parent 636a1722f8
commit 4c93786f1c
3 changed files with 70 additions and 5 deletions

View File

@ -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 <johnstonskj@gmail.com>"]
repository = "https://github.com/johnstonskj/rust-luxafor"

View File

@ -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.

View File

@ -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.