known_characteristic/
known_characteristic.rs1use ble_ledly::capability::color::*;
2use ble_ledly::capability::light::*;
3use ble_ledly::communication_protocol::GenericRGB;
4use ble_ledly::Controller;
5use ble_ledly::device::LedDevice;
6use ble_ledly::device::Device;
7use ble_ledly::device::{CharKind, UuidKind};
8
9use std::error::Error;
10use std::time::Duration;
11use tokio::time;
12
13#[tokio::main]
14async fn main() -> Result<(), Box<dyn Error>> {
15 let mut controller = Controller::<LedDevice>::new().await?;
17
18 let led_devices = controller.device_discovery().await?;
20
21 for device in led_devices.iter() {
23 println!("Found device: {}", device);
24 }
25 let lights: Vec<LedDevice> = led_devices
27 .into_iter()
28 .filter(|device| device.name.contains("QHM-"))
29 .collect();
30
31 controller.connect_with_devices(lights).await?;
33
34 let protocol = GenericRGB::default();
36
37 let connected_lights = controller.list();
39 for light in connected_lights.iter_mut() {
40 println!("-- Manipulating light {} --", light);
41
42 light.set_char(&CharKind::Write, &UuidKind::Uuid16(0xFFD9))?;
48
49 println!("Turning light on...");
55 light.turn_on(&protocol).await?;
56
57 println!("Setting color...");
59 light.color(&protocol, 255, 0, 0).await?;
60 time::sleep(Duration::from_millis(800)).await;
61 light.color(&protocol, 0, 255, 0).await?;
62 time::sleep(Duration::from_millis(800)).await;
63 light.color(&protocol, 0, 0, 255).await?;
64 time::sleep(Duration::from_millis(800)).await;
65
66 println!("Turning light off...");
67 light.turn_off(&protocol).await?;
68 }
69
70 Ok(())
71}