Skip to content

Commit 5ebcf73

Browse files
committed
WIP
1 parent d79434b commit 5ebcf73

3 files changed

Lines changed: 372 additions & 20 deletions

File tree

protocol/SPECIFICATION

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,7 @@
1111
0x0004 uint8 Flow Unit
1212
0x00 Liter
1313
0x02 Gallons
14-
0x0005 uint8 Display Flags
15-
0x01 Rotate
16-
0x04 Invert
17-
0x08 Auto Invert
18-
0x10 Disable Device Buttons
19-
0x20 Lock Menu
14+
0x0005 uint8 <constant 00>
2015
0x0006 uint8 Next Page Interval
2116
[3..60] Interval in Seconds
2217
61: Disable Automatic Page Change
@@ -48,7 +43,14 @@
4843
0x01 Medium
4944
0x02 Low
5045
0x03 Off
51-
0x0011 uint8[6] <contant 02 BC 02 58 00 00>
46+
0x0011 uint8[6] <contant 02 BC 02 58>
47+
0x0015 uint8 Display Flags
48+
0x01 Rotate
49+
0x04 Invert
50+
0x08 Auto Invert
51+
0x10 Disable Device Buttons
52+
0x20 Lock Menu
53+
0x0016 uint8 <contant 00>
5254
0x0017 uint8 Chart 1 Source
5355
0x00 Flow
5456
0x01 Water Temperature
@@ -288,7 +290,7 @@
288290
[1..5]
289291
Effect Specific Flags:
290292
0x02 Reverse Direction
291-
0x04 Fade
293+
0x08 Random Color
292294
0x80 Circular
293295
11 Color Sequence
294296
Color 0-5: User Defined Color

src/protocol/sensor_values.rs

Lines changed: 48 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use std::{array::from_fn, ops::BitAnd};
44

55
use bitflags::bitflags;
6-
use color_space::Hsv;
6+
use color_space::{FromRgb, Hsv, Rgb};
77
use smallvec::SmallVec;
88

99
use crate::{
@@ -103,14 +103,15 @@ impl BinaryRead for DisplaySettings {
103103
fn decode<R: Reader>(reader: &mut R) -> Result<ReaderOutput<R, Self>, BinaryIoError> {
104104
let temperature_unit = TemperatureUnit::decode(reader)?;
105105
let flow_unit = FlowUnit::decode(reader)?;
106-
let display_flags = DisplayFlags::decode(reader)?;
106+
reader.skip::<1>()?;
107107
let next_page_interval = Option::<NextPageInteral>::decode(reader)?;
108108
reader.skip::<2>()?;
109109
let page_flags = PageFlags::decode(reader)?;
110110
reader.skip::<4>()?;
111111
let display_brightness = DisplayBrightness::decode(reader)?;
112112
let idle_display_brightness = Option::<DisplayBrightness>::decode(reader)?;
113-
reader.skip::<5>()?;
113+
reader.skip::<4>()?;
114+
let display_flags = DisplayFlags::decode(reader)?;
114115
let charts = <[Chart; 4] as BinaryRead>::decode(reader)?;
115116

116117
Ok(R::guard(|x| Self {
@@ -345,7 +346,7 @@ pub struct EffectWave {
345346
pub width: EffectWidth,
346347

347348
pub reverse_direction: bool,
348-
pub fade: bool,
349+
pub random_color: bool,
349350
pub circular: bool,
350351

351352
pub source_control_speed: Option<SourceControl>,
@@ -593,7 +594,7 @@ impl BinaryRead for Option<Controller> {
593594
smoothness: x.extract(smoothness),
594595
width: x.extract(width),
595596
reverse_direction: flag_set(effect_flags, 0x02),
596-
fade: flag_set(effect_flags, 0x04),
597+
random_color: flag_set(effect_flags, 0x04),
597598
circular: flag_set(effect_flags, 0x80),
598599
source_control_speed: x.extract(source_control_speed),
599600
source_control_brightness: x.extract(source_control_brightness),
@@ -671,6 +672,39 @@ impl BinaryRead for SourceControl {
671672
#[derive(Debug, Clone)]
672673
pub struct Color(pub Hsv);
673674

675+
impl Color {
676+
#[must_use]
677+
pub fn from_hsv(h: f64, s: f64, v: f64) -> Self {
678+
Self(Hsv::new(h, s, v))
679+
}
680+
681+
#[must_use]
682+
pub fn from_rgb(r: u8, g: u8, b: u8) -> Self {
683+
Self(Hsv::from_rgb(&Rgb::new(
684+
f64::from(r),
685+
f64::from(g),
686+
f64::from(b),
687+
)))
688+
}
689+
690+
#[must_use]
691+
pub fn from_rgb_hex(hex: u32) -> Self {
692+
Self(Hsv::from_rgb(&Rgb::from_hex(hex)))
693+
}
694+
}
695+
696+
impl From<Hsv> for Color {
697+
fn from(value: Hsv) -> Self {
698+
Self(value)
699+
}
700+
}
701+
702+
impl From<Color> for Hsv {
703+
fn from(value: Color) -> Self {
704+
value.0
705+
}
706+
}
707+
674708
impl Eq for Color {}
675709

676710
impl PartialEq for Color {
@@ -687,7 +721,11 @@ impl BinaryRead for Color {
687721
let v = f64::from(reader.read_u8()?);
688722

689723
Ok(R::guard(|_| {
690-
Self(Hsv::new(60.0 * h_section + 60.0 * h_offset / 255.0, s, v))
724+
Self(Hsv::new(
725+
60.0 * h_section + 60.0 * h_offset / 255.0,
726+
s / 255.0,
727+
v / 255.0,
728+
))
691729
}))
692730
}
693731
}
@@ -1037,10 +1075,10 @@ bitflags! {
10371075
const COND_QUALITY = 0x0200;
10381076
const TEMPERATURE = 0x0400;
10391077
const FLOW_VOLUME = 0x0800;
1040-
const CHAR1 = 0x1000;
1041-
const CHAR2 = 0x2000;
1042-
const CHAR3 = 0x4000;
1043-
const CHAR4 = 0x8000;
1078+
const CHART1 = 0x1000;
1079+
const CHART2 = 0x2000;
1080+
const CHART3 = 0x4000;
1081+
const CHART4 = 0x8000;
10441082
}
10451083
}
10461084

0 commit comments

Comments
 (0)