feat(config): add ability to skip stick measurements
All checks were successful
Code quality / check (pull_request) Successful in 1m40s

This commit is contained in:
Naxdy 2024-04-09 19:09:40 +02:00
parent a785fb69eb
commit b68a4a7f88
Signed by: Naxdy
GPG key ID: CC15075846BCE91B
2 changed files with 41 additions and 10 deletions

View file

@ -466,7 +466,7 @@ pub struct OverrideStickState {
} }
#[allow(dead_code)] #[allow(dead_code)]
#[derive(Clone, Copy, Debug, Format)] #[derive(Clone, Copy, Debug, Format, PartialEq, Eq)]
pub enum AwaitableButtons { pub enum AwaitableButtons {
A, A,
B, B,
@ -881,6 +881,28 @@ 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,
};
for i in 0..NO_OF_CALIBRATION_POINTS {
self.cal_points[i] = XyValuePair {
x: *stick_config.cal_points_x[i],
y: *stick_config.cal_points_y[i],
};
}
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 { async fn calibration_advance(&mut self) -> bool {
info!( info!(
"Running calibration advance on stick {} at step {}", "Running calibration advance on stick {} at step {}",
@ -987,7 +1009,9 @@ impl<'a> StickCalibrationProcess<'a> {
let mut gcc_subscriber = CHANNEL_GCC_STATE.subscriber().unwrap(); let mut gcc_subscriber = CHANNEL_GCC_STATE.subscriber().unwrap();
SIGNAL_IS_CALIBRATING.signal(true); SIGNAL_IS_CALIBRATING.signal(true);
while { let mut done = false;
while !done {
if self.calibration_step < NO_OF_CALIBRATION_POINTS as u8 { if self.calibration_step < NO_OF_CALIBRATION_POINTS as u8 {
// Calibration phase // Calibration phase
@ -1013,9 +1037,14 @@ impl<'a> StickCalibrationProcess<'a> {
// Prevent accidental double presses // Prevent accidental double presses
Timer::after_millis(100).await; Timer::after_millis(100).await;
gcc_subscriber let btn_result = gcc_subscriber
.wait_for_button_press(&AwaitableButtons::A) .wait_and_filter_button_press(&[AwaitableButtons::A, AwaitableButtons::Start])
.await; .await;
if btn_result == AwaitableButtons::Start {
self.calibration_skip_measurement();
continue;
}
} else { } else {
// Notch adjustment phase // Notch adjustment phase
@ -1073,8 +1102,8 @@ impl<'a> StickCalibrationProcess<'a> {
} }
}; };
!self.calibration_advance().await done = self.calibration_advance().await;
} {} }
SIGNAL_IS_CALIBRATING.signal(false); SIGNAL_IS_CALIBRATING.signal(false);
SIGNAL_OVERRIDE_STICK_STATE.signal(None); SIGNAL_OVERRIDE_STICK_STATE.signal(None);

View file

@ -155,8 +155,9 @@ async fn update_stick_states(
let spi_acs = spi_acs_unlocked.as_mut().unwrap(); let spi_acs = spi_acs_unlocked.as_mut().unwrap();
let spi_ccs = spi_ccs_unlocked.as_mut().unwrap(); let spi_ccs = spi_ccs_unlocked.as_mut().unwrap();
// "do-while at home" let mut done = false;
while {
while !done {
let loop_start = Instant::now(); let loop_start = Instant::now();
adc_count += 1; 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; cy_sum += read_ext_adc(Stick::CStick, StickAxis::YAxis, spi, spi_acs, spi_ccs) as u32;
let loop_end = Instant::now(); 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); trace!("ADC Count: {}", adc_count);