From 45ef1f205a2b9c42c2342a59b891fa956648debb Mon Sep 17 00:00:00 2001 From: David Gomes <10091092+davidgomesdev@users.noreply.github.com> Date: Sun, 24 Dec 2023 11:46:45 +0000 Subject: [PATCH] fix: revert led not working properly --- server/src/ps_move/controller.rs | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/server/src/ps_move/controller.rs b/server/src/ps_move/controller.rs index 946fb7e1..e677f1c5 100644 --- a/server/src/ps_move/controller.rs +++ b/server/src/ps_move/controller.rs @@ -103,6 +103,20 @@ impl PsMoveController { self.last_led_effect = current_effect; self.setting.last_led = current_led; + let last_led_effect = &mut self.last_led_effect; + + if last_led_effect.duration.is_some() { + let duration = last_led_effect.duration.unwrap(); + + if last_led_effect.start.elapsed() >= duration { + info!("Last led effect '{}' of '{}' has expired, setting to off", last_led_effect, self.bt_address); + let off_effect = LedEffect::off(); + + self.led_effect = off_effect; + self.setting.led = off_effect.kind.get_initial_hsv() + } + } + info!("Reverted '{:?}' to '{}'", self.bt_address, self.led_effect); } @@ -185,20 +199,6 @@ impl PsMoveController { } pub fn transform_led(&mut self) { - let last_led_effect = &mut self.last_led_effect; - - if last_led_effect.duration.is_some() { - let duration = last_led_effect.duration.unwrap(); - - if last_led_effect.start.elapsed() >= duration { - info!("Last led effect '{}' of '{}' expired", last_led_effect, self.bt_address); - let off_effect = LedEffect::off(); - - self.last_led_effect = off_effect; - self.setting.last_led = off_effect.kind.get_initial_hsv() - } - }; - let led_effect = &mut self.led_effect; let current_hsv = self.setting.led;