ble-ledly

Customizable and extensible cross-platform high-level BLE light controller

ble-ledly is a Customizable and extensible cross-platform high-level Bluetooth Low Energy light controller. Built on top of btleplug, it is the designed to control ble led lights and _RGB 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 to control a generic led strip.

```rust use bleledly::communicationprotocol::genericrgblight::{ AnimationSpeedSetting, PulsatingColor, }; use bleledly::controller::Controller; use bleledly::device::leddevice::LedDevice; use bleledly::device::traits::{Device, Light, RGB};

use bleledly::animation::{AnimationRepeat, AnimationSpeed}; use bleledly::animation;

use std::time::Duration; use tokio::time;

#[tokio::main] async fn main() { // Create a new Light controller with prefix let mut controller = Controller::::new("QHM-").await.unwrap(); // Discover devices (scan) let leddevices = controller.devicediscovery().await.unwrap(); // inspect all found devices for device in leddevices.iter() { println!("Found device: {}", device.name()); } // filter devices let lights: Vec = leddevices .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;

      // Disconnect
      light.disconnect().await.unwrap();
   }

} ```

Contributing

Open a PR or issue

License

MIT