feat: 测试灯效,流光溢彩

This commit is contained in:
2022-11-23 00:36:28 +08:00
parent f7b290dcbf
commit a9394bd73c
11 changed files with 139 additions and 36 deletions

View File

@@ -1,3 +1,4 @@
use color_space::{Hsv, Rgb};
use paris::info;
use serde::Serialize;
@@ -15,6 +16,33 @@ impl LedColor {
Self { bits: [r, g, b] }
}
pub fn from_hsv(h: f64, s: f64, v: f64) -> Self {
let rgb = Rgb::from(Hsv::new(h, s, v));
// let h = h % 360;
// let rgb_max = v * 255.0;
// let rgb_min = rgb_max * (1.0 - s as f32);
// let i = h / 60;
// let diff = h % 60;
// let rgb_adj = (rgb_max - rgb_min) * diff as f32 / 60.0;
// let bits: [u8; 3] = if i == 0 {
// [rgb_max as u8, (rgb_min + rgb_adj) as u8, rgb_min as u8]
// } else if i == 1 {
// [(rgb_max - rgb_adj) as u8, rgb_max as u8, rgb_min as u8]
// } else if i == 2 {
// [rgb_min as u8, rgb_max as u8, (rgb_min + rgb_adj) as u8]
// } else if i == 3 {
// [rgb_min as u8, (rgb_max - rgb_adj) as u8, rgb_max as u8]
// } else if i == 4 {
// [(rgb_min + rgb_adj) as u8, rgb_min as u8, rgb_max as u8]
// } else {
// [rgb_max as u8, rgb_min as u8, (rgb_max - rgb_adj) as u8]
// };
Self { bits: [rgb.r as u8, rgb.g as u8, rgb.b as u8] }
}
pub fn get_rgb(&self) -> [u8; 3] {
self.bits
}
@@ -43,7 +71,6 @@ impl Serialize for LedColor {
where
S: serde::Serializer,
{
info!("{:?}", self.bits);
let hex = format!("#{}", hex::encode(self.bits));
serializer.serialize_str(hex.as_str())
}