From cf84dbf80237c7bac294db5db8bbd8fda4c823ad Mon Sep 17 00:00:00 2001 From: Naxdy Date: Mon, 8 Apr 2024 23:36:24 +0200 Subject: [PATCH] feat(config): add ability to skip stick measurements --- src/config.rs | 34 ++++++++++++++++++++++++++++------ src/input.rs | 10 ++++++---- 2 files changed, 34 insertions(+), 10 deletions(-) diff --git a/src/config.rs b/src/config.rs index 1b6eb61..9e50109 100644 --- a/src/config.rs +++ b/src/config.rs @@ -466,7 +466,7 @@ pub struct OverrideStickState { } #[allow(dead_code)] -#[derive(Clone, Copy, Debug, Format)] +#[derive(Clone, Copy, Debug, Format, PartialEq, Eq)] pub enum AwaitableButtons { A, B, @@ -881,6 +881,21 @@ impl<'a> StickCalibrationProcess<'a> { } } + fn calibration_skip_measurement(&mut self) { + self.calibration_step = NO_OF_CALIBRATION_POINTS as u8; + + let stick_config = match self.which_stick { + Stick::ControlStick => &mut self.gcc_config.astick_config, + Stick::CStick => &mut self.gcc_config.cstick_config, + }; + + self.applied_calibration = AppliedCalibration::from_points( + stick_config.cal_points_x.to_regular_array(), + stick_config.cal_points_y.to_regular_array(), + stick_config, + ) + } + async fn calibration_advance(&mut self) -> bool { info!( "Running calibration advance on stick {} at step {}", @@ -987,7 +1002,9 @@ impl<'a> StickCalibrationProcess<'a> { let mut gcc_subscriber = CHANNEL_GCC_STATE.subscriber().unwrap(); SIGNAL_IS_CALIBRATING.signal(true); - while { + let mut done = false; + + while !done { if self.calibration_step < NO_OF_CALIBRATION_POINTS as u8 { // Calibration phase @@ -1013,9 +1030,14 @@ impl<'a> StickCalibrationProcess<'a> { // Prevent accidental double presses Timer::after_millis(100).await; - gcc_subscriber - .wait_for_button_press(&AwaitableButtons::A) + let btn_result = gcc_subscriber + .wait_and_filter_button_press(&[AwaitableButtons::A, AwaitableButtons::Start]) .await; + + if btn_result == AwaitableButtons::Start { + self.calibration_skip_measurement(); + continue; + } } else { // Notch adjustment phase @@ -1073,8 +1095,8 @@ impl<'a> StickCalibrationProcess<'a> { } }; - !self.calibration_advance().await - } {} + done = self.calibration_advance().await; + } SIGNAL_IS_CALIBRATING.signal(false); SIGNAL_OVERRIDE_STICK_STATE.signal(None); diff --git a/src/input.rs b/src/input.rs index c8bb023..d9cd7e1 100644 --- a/src/input.rs +++ b/src/input.rs @@ -155,8 +155,9 @@ async fn update_stick_states( let spi_acs = spi_acs_unlocked.as_mut().unwrap(); let spi_ccs = spi_ccs_unlocked.as_mut().unwrap(); - // "do-while at home" - while { + let mut done = false; + + while !done { let loop_start = Instant::now(); adc_count += 1; @@ -166,8 +167,9 @@ async fn update_stick_states( cy_sum += read_ext_adc(Stick::CStick, StickAxis::YAxis, spi, spi_acs, spi_ccs) as u32; let loop_end = Instant::now(); - loop_end < end_time - (loop_end - loop_start) - } {} + + done = loop_end >= end_time - (loop_end - loop_start); + } trace!("ADC Count: {}", adc_count);