项目作者: aeshirey

项目描述 :
A Rust library for MagicLight bulbs
高级语言: Rust
项目地址: git://github.com/aeshirey/magiclight-rs.git
创建时间: 2020-05-02T21:57:46Z
项目社区:https://github.com/aeshirey/magiclight-rs

开源协议:Apache License 2.0

下载


magiclight-rs

A Rust library for MagicLight bulbs.

  1. use magiclight_rust::*;
  2. use std::time::Duration;
  3. fn main() -> Result<(), MagicLightError>{
  4. let mut bulb = MagicLight::new("192.168.0.123")?;
  5. // Set the color to blue and delay for 1000ms
  6. let blue = Color {
  7. red: 0,
  8. green: 0,
  9. blue: 255,
  10. };
  11. bulb.set_color(blue)?;
  12. bulb.delay_msec(1000);
  13. // Set the color to green via a tuple and delay for 800ms
  14. let g = (0, 255, 0).into();
  15. bulb.set_color(g);
  16. bulb.delay_sec(0.8);
  17. // Turn off for 2 sec
  18. bulb.off()?;
  19. bulb.delay_msec(2000);
  20. // Turn on as red for 1sec
  21. let r = (255, 0, 0).into();
  22. bulb.set_color(r);
  23. bulb.delay_sec(1.);
  24. // Fade from red to blue in five seconds
  25. bulb.fade_between(r, blue, 100, Duration::from_secs(5));
  26. // Then blink ten times, on 0.5s, off 0.25s
  27. bulb.blink(blue, Duration::from_secs_f32(0.5), Duration::from_secs_f32(0.25), 10);
  28. // And finally, fade out and disconnect
  29. bulb.fade_out(blue, 10, Duration::SECOND);
  30. bulb.disconnect()?;
  31. Ok(())
  32. }