diff --git a/src/rgb_controller/controller.rs b/src/rgb_controller/controller.rs index 30351a1..df1d901 100644 --- a/src/rgb_controller/controller.rs +++ b/src/rgb_controller/controller.rs @@ -3,6 +3,7 @@ use crate::Effects; use crate::HidWrapperError; use crate::Keymap; use crate::hid_wrapper::HidWrapper; +use crate::rgb_controller::effects::Effect; pub struct RGBController { hid_wrapper: HidWrapper, @@ -224,7 +225,7 @@ impl RGBController { speed: u8, direction: u8, keymap: Option<[[u8; 3]; 144]>, - ) -> Result<(), HidWrapperError> { + ) -> Result { self.hid_wrapper.open_device()?; self.prepare_device()?; @@ -263,7 +264,15 @@ impl RGBController { self.hid_wrapper.close_device(); - Ok(()) + Ok(Effect { + effect, + color, + full_color, + brightness, + speed, + direction, + keymap, + }) } pub fn set_static_effect( @@ -271,7 +280,7 @@ impl RGBController { color: Color, brightness: u8, full_color: Option, - ) -> Result<(), HidWrapperError> { + ) -> Result { self.set_effect( Effects::Static, color, @@ -289,7 +298,7 @@ impl RGBController { brightness: u8, speed: u8, full_color: Option, - ) -> Result<(), HidWrapperError> { + ) -> Result { self.set_effect( Effects::SingleOff, color, @@ -307,7 +316,7 @@ impl RGBController { brightness: u8, speed: u8, full_color: Option, - ) -> Result<(), HidWrapperError> { + ) -> Result { self.set_effect( Effects::SingleOn, color, @@ -325,7 +334,7 @@ impl RGBController { brightness: u8, speed: u8, full_color: Option, - ) -> Result<(), HidWrapperError> { + ) -> Result { self.set_effect( Effects::Glittering, color, @@ -343,7 +352,7 @@ impl RGBController { brightness: u8, speed: u8, full_color: Option, - ) -> Result<(), HidWrapperError> { + ) -> Result { self.set_effect( Effects::Rain, color, @@ -359,7 +368,7 @@ impl RGBController { &mut self, brightness: u8, speed: u8, - ) -> Result<(), HidWrapperError> { + ) -> Result { self.set_effect( Effects::Colorful, Color::default(), @@ -377,7 +386,7 @@ impl RGBController { brightness: u8, speed: u8, full_color: Option, - ) -> Result<(), HidWrapperError> { + ) -> Result { self.set_effect( Effects::Breath, color, @@ -393,7 +402,7 @@ impl RGBController { &mut self, brightness: u8, speed: u8, - ) -> Result<(), HidWrapperError> { + ) -> Result { self.set_effect( Effects::Spectrum, Color::default(), @@ -411,7 +420,7 @@ impl RGBController { brightness: u8, speed: u8, full_color: Option, - ) -> Result<(), HidWrapperError> { + ) -> Result { self.set_effect( Effects::CentrifugalWave, color, @@ -430,7 +439,7 @@ impl RGBController { speed: u8, direction: u8, full_color: Option, - ) -> Result<(), HidWrapperError> { + ) -> Result { self.set_effect( Effects::VerticalWave, color, @@ -449,7 +458,7 @@ impl RGBController { speed: u8, direction: u8, full_color: Option, - ) -> Result<(), HidWrapperError> { + ) -> Result { self.set_effect( Effects::HorizontalWave, color, @@ -467,7 +476,7 @@ impl RGBController { brightness: u8, speed: u8, full_color: Option, - ) -> Result<(), HidWrapperError> { + ) -> Result { self.set_effect( Effects::Rotating, color, @@ -485,7 +494,7 @@ impl RGBController { brightness: u8, speed: u8, full_color: Option, - ) -> Result<(), HidWrapperError> { + ) -> Result { self.set_effect( Effects::Explosion, color, @@ -503,7 +512,7 @@ impl RGBController { brightness: u8, speed: u8, full_color: Option, - ) -> Result<(), HidWrapperError> { + ) -> Result { self.set_effect( Effects::Launch, color, @@ -521,7 +530,7 @@ impl RGBController { brightness: u8, speed: u8, full_color: Option, - ) -> Result<(), HidWrapperError> { + ) -> Result { self.set_effect( Effects::Ripples, color, @@ -539,7 +548,7 @@ impl RGBController { brightness: u8, speed: u8, full_color: Option, - ) -> Result<(), HidWrapperError> { + ) -> Result { self.set_effect( Effects::Snake, color, @@ -557,7 +566,7 @@ impl RGBController { brightness: u8, speed: u8, full_color: Option, - ) -> Result<(), HidWrapperError> { + ) -> Result { self.set_effect( Effects::Pulse, color, @@ -575,7 +584,7 @@ impl RGBController { brightness: u8, speed: u8, full_color: Option, - ) -> Result<(), HidWrapperError> { + ) -> Result { self.set_effect( Effects::Tilt, color, @@ -593,7 +602,7 @@ impl RGBController { brightness: u8, speed: u8, full_color: Option, - ) -> Result<(), HidWrapperError> { + ) -> Result { self.set_effect( Effects::Shuttle, color, @@ -609,7 +618,7 @@ impl RGBController { &mut self, brightness: u8, keymap: Keymap, - ) -> Result<(), HidWrapperError> { + ) -> Result { self.set_effect( Effects::StaticPerKey, Color::default(), diff --git a/src/rgb_controller/effects.rs b/src/rgb_controller/effects.rs index fa27cf3..9b8ed7a 100644 --- a/src/rgb_controller/effects.rs +++ b/src/rgb_controller/effects.rs @@ -4,6 +4,8 @@ use Effects::{ VerticalWave, }; +use crate::Color; + /// Effects of the keyboard pub enum Effects { Static, @@ -54,7 +56,7 @@ impl Effects { StaticPerKey => 20, } } - + pub fn from_u8(n: u8) -> Option { match n { 1 => Some(Static), @@ -77,7 +79,17 @@ impl Effects { 18 => Some(Tilt), 19 => Some(Shuttle), 20 => Some(StaticPerKey), - _ => None + _ => None, } } } + +pub struct Effect { + pub effect: Effects, + pub color: Color, + pub full_color: bool, + pub brightness: u8, + pub speed: u8, + pub direction: u8, + pub keymap: Option<[[u8; 3]; 144]>, +}