1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
//! `ble-ledly` is a _Customizable_ and _extensible_ cross-platform high-level _Bluetooth Low Energy_ light controller. Built on top of btleplug, it i designed to control _ble led lights_ and _led strips_. Provides out-of-the-box _hardware-specific_ controls and animation as well as non-transferable (requires continuous client connection).
//!
//!
//! ## Usage
//!
//! An example of how to use the library
//!
//! ```rust, no_run
//! use ble_ledly::communication_protocol::generic_rgb_light::{
//! AnimationSpeedSetting, PulsatingColor,
//! };
//! use ble_ledly::controller::Controller;
//! use ble_ledly::device::led_device::LedDevice;
//! use ble_ledly::device::traits::{Device, Light, RGB};
//!
//! use ble_ledly::animation::{AnimationRepeat, AnimationSpeed};
//! use ble_ledly::animation;
//!
//! use std::time::Duration;
//! use tokio::time;
//!
//! #[tokio::main]
//! async fn main() {
//! // Create a new Light controller with prefix
//! let mut controller = Controller::<LedDevice>::new("QHM-").await.unwrap();
//! // Discover devices (scan)
//! let led_devices = controller.device_discovery().await.unwrap();
//! // inspect all found devices
//! for device in led_devices.iter() {
//! println!("Found device: {}", device.name());
//! }
//! // filter devices
//! let lights: Vec<LedDevice> = led_devices
//! .into_iter()
//! .filter(|device| device.name().contains("1249"))
//! .collect();
//! // print filtered using debug trait
//! println!("Filtered Lights: {:?}", lights);
//!
//! // Connect
//! controller.connect(Some(lights), None).await.unwrap();
//! // list all connected devices
//! let connected_lights = controller.list();
//! for light in connected_lights.iter_mut() {
//! println!("Connected to : {}", light.name());
//!
//! // Control the lights
//! light.set_color(255, 255, 255).await;
//! time::sleep(Duration::from_millis(800)).await;
//!
//! // Test RGB
//! light.set_color(255, 0, 0).await;
//! time::sleep(Duration::from_millis(800)).await;
//!
//! light.set_color(0, 255, 0).await;
//! time::sleep(Duration::from_millis(800)).await;
//!
//! light.set_color(0, 0, 255).await;
//! time::sleep(Duration::from_millis(800)).await;
//!
//! // Client, non-transferrable animation
//! animation::breathing(light, 255, 0, 0, &AnimationRepeat::FiniteCount(1), &AnimationSpeed::Fastest).await;
//! animation::breathing(light, 0, 255, 0, &AnimationRepeat::FiniteCount(1), &AnimationSpeed::Fastest).await;
//! animation::breathing(light, 0, 0, 255, &AnimationRepeat::FiniteCount(1), &AnimationSpeed::Fastest).await;
//!
//! // HWspecific animation
//! light.pulsating(&PulsatingColor::Red, &AnimationSpeedSetting::Speed9).await;
//! time::sleep(Duration::from_millis(2000)).await;
//! light.pulsating(&PulsatingColor::Green, &AnimationSpeedSetting::Speed9).await;
//! time::sleep(Duration::from_millis(2000)).await;
//! light.pulsating(&PulsatingColor::Blue, &AnimationSpeedSetting::Speed9).await;
//! time::sleep(Duration::from_millis(2000)).await;
//!
//! // turn-off
//! light.turn_off().await;
//! }
//! }
//! ```