Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix revert not working #65

Merged
merged 2 commits into from
Dec 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
2 changes: 1 addition & 1 deletion server/src/tracing_setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ fn build_loki_layer() -> (tracing_loki::Layer, BackgroundTask) {

pub async fn setup_loki() {
let filter = filter::Targets::new()
.with_target("rusty_controller", Level::DEBUG)
.with_target("rusty_controller", Level::TRACE)
.with_default(Level::WARN);

let registry = tracing_subscriber::registry().with(filter).with(
Expand Down
Loading