From 7ef15c0e7bf8d4ad1eb460f287ca87a2d3396a47 Mon Sep 17 00:00:00 2001 From: Naxdy Date: Tue, 2 Apr 2024 19:19:17 +0200 Subject: [PATCH] change(input): always yield at least once per stick update --- src/input.rs | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/src/input.rs b/src/input.rs index 1defb1e..dc17d8a 100644 --- a/src/input.rs +++ b/src/input.rs @@ -551,6 +551,10 @@ pub async fn update_stick_states_task( if let Some(new_calibrating) = SIGNAL_IS_CALIBRATING.try_take() { is_calibrating = new_calibrating; + if !is_calibrating { + debug!("Reset the ticker."); + ticker.reset(); + } } match Instant::now() { @@ -566,12 +570,7 @@ pub async fn update_stick_states_task( SIGNAL_STICK_STATE.signal(current_stick_state.clone()); ticker.next().await; - - // we need this because during calibration, we might - // not run at the desired interval - if is_calibrating { - yield_now().await; - } + yield_now().await; if let Some(new_config) = SIGNAL_CONFIG_CHANGE.try_take() { controller_config = new_config; @@ -579,14 +578,5 @@ pub async fn update_stick_states_task( cstick_params = StickParams::from_stick_config(&controller_config.cstick_config); filter_gains = FILTER_GAINS.get_normalized_gains(&controller_config); } - - #[cfg(debug_assertions)] - { - // give other tasks a chance to do something - // in debug, this loop runs noticeably slower, so this is necessary - // prefer running with `cargo run --release` for this reason, when - // developing stick related features - yield_now().await; - } } }