Skip to content

Commit

Permalink
fix: revert led not working properly
Browse files Browse the repository at this point in the history
  • Loading branch information
davidgomesdev committed Dec 26, 2023
1 parent d1d78dd commit 124c146
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 16 deletions.
31 changes: 16 additions & 15 deletions server/src/ps_move/controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,29 @@ impl PsMoveController {
self.last_led_effect = current_effect;
self.setting.last_led = current_led;

let last_led_effect = &mut self.last_led_effect;

if let Some(duration) = last_led_effect.duration {
if last_led_effect.start.elapsed() >= duration {
info!("Last led effect '{}' of '{}' has already 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);
}

pub fn set_led_effect(&mut self, effect: LedEffect) {
self.last_led_effect = self.led_effect;
self.setting.last_led = self.setting.led;

let mut kind = effect.kind;

self.setting.led = kind.get_updated_hsv(self.setting.led);
self.led_effect = effect;
self.setting.led = kind.get_updated_hsv(self.setting.led);
}

pub fn set_led_effect_with_hsv(&mut self, effect: LedEffect, hsv: Hsv) {
Expand Down Expand Up @@ -185,20 +200,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;

Expand Down
2 changes: 1 addition & 1 deletion server/src/tasks/controllers_list_update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ pub async fn run(
get_on_connected_effect()
} else {
tracing::info!(
"Setting current initial effect on '{}'. ({initial_effect})",
"Setting current effect on '{}'. ({initial_effect})",
controller.bt_address
);
initial_effect
Expand Down

0 comments on commit 124c146

Please sign in to comment.