33use std:: { array:: from_fn, ops:: BitAnd } ;
44
55use bitflags:: bitflags;
6- use color_space:: Hsv ;
6+ use color_space:: { FromRgb , Hsv , Rgb } ;
77use smallvec:: SmallVec ;
88
99use 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 ) ]
672673pub 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+
674708impl Eq for Color { }
675709
676710impl 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