From 32812ba160c54a0db0eef030c5e9ebfd0e8410ef Mon Sep 17 00:00:00 2001 From: Naxdy Date: Sun, 1 Sep 2024 17:32:01 +0200 Subject: [PATCH 1/3] chore(input): improve stick update comments --- src/input.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/input.rs b/src/input.rs index c0d0d0b..d671d41 100644 --- a/src/input.rs +++ b/src/input.rs @@ -540,7 +540,7 @@ pub async fn update_button_state_task( } /// Task responsible for updating the stick states. -/// Publishes the result to STICK_SIGNAL. +/// Publishes the result to SIGNAL_STICK_STATE. /// /// Has to run on core0 because it makes use of SPI0. #[embassy_executor::task] @@ -621,6 +621,7 @@ pub async fn update_stick_states_task( SIGNAL_STICK_STATE.signal(current_stick_state.clone()); + // the yield_now is in case we took too long for the ticker yield_now().await; ticker.next().await; -- 2.47.0 From 0b56bab6e869801ba9440ce970f97cfc9f2d0cf3 Mon Sep 17 00:00:00 2001 From: Naxdy Date: Sun, 1 Sep 2024 17:36:35 +0200 Subject: [PATCH 2/3] chore(input/stick_params): use From trait --- src/input.rs | 8 ++++---- src/stick.rs | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/input.rs b/src/input.rs index d671d41..9eb5c12 100644 --- a/src/input.rs +++ b/src/input.rs @@ -561,8 +561,8 @@ pub async fn update_stick_states_task( let mut controller_config = SIGNAL_CONFIG_CHANGE.wait().await; - let mut controlstick_params = StickParams::from_stick_config(&controller_config.astick_config); - let mut cstick_params = StickParams::from_stick_config(&controller_config.cstick_config); + let mut controlstick_params = StickParams::from(&controller_config.astick_config); + let mut cstick_params = StickParams::from(&controller_config.cstick_config); let mut filter_gains = FILTER_GAINS.get_normalized_gains(&controller_config); let mut current_stick_state = StickState { @@ -627,8 +627,8 @@ pub async fn update_stick_states_task( if let Some(new_config) = SIGNAL_CONFIG_CHANGE.try_take() { controller_config = new_config; - controlstick_params = StickParams::from_stick_config(&controller_config.astick_config); - cstick_params = StickParams::from_stick_config(&controller_config.cstick_config); + controlstick_params = StickParams::from(&controller_config.astick_config); + cstick_params = StickParams::from(&controller_config.cstick_config); filter_gains = FILTER_GAINS.get_normalized_gains(&controller_config); info!("Controlstick params: {:?}", controlstick_params); diff --git a/src/stick.rs b/src/stick.rs index 09f065d..1d517c1 100644 --- a/src/stick.rs +++ b/src/stick.rs @@ -40,9 +40,9 @@ pub struct StickParams { pub boundary_angles: [f32; 16], // angles at the boundaries between regions of the stick (in the plane) } -impl StickParams { - /// Generate StickParams structs for the sticks, returned as a tuple of (analog_stick, c_stick) - pub fn from_stick_config(stick_config: &StickConfig) -> Self { +impl From<&StickConfig> for StickParams { + /// Generate a StickParam struct from a stick config + fn from(stick_config: &StickConfig) -> Self { let cleaned_cal_points = CleanedCalibrationPoints::from_temp_calibration_points( stick_config.cal_points_x.to_regular_array(), stick_config.cal_points_y.to_regular_array(), @@ -427,7 +427,7 @@ impl AppliedCalibration { cal_points_y: &[f32; NO_OF_CALIBRATION_POINTS], stick_config: &StickConfig, ) -> Self { - let mut stick_params = StickParams::from_stick_config(stick_config); + let mut stick_params = StickParams::from(stick_config); let (stripped_cal_points_x, stripped_cal_points_y) = strip_cal_points(cal_points_x, cal_points_y); -- 2.47.0 From 082c11229390c24c19b50fd35af5f1340ee3dc0e Mon Sep 17 00:00:00 2001 From: Naxdy Date: Sun, 1 Sep 2024 17:37:05 +0200 Subject: [PATCH 3/3] chore(stick): improve comments --- src/stick.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/stick.rs b/src/stick.rs index 1d517c1..d91ea51 100644 --- a/src/stick.rs +++ b/src/stick.rs @@ -32,12 +32,14 @@ pub const NOTCH_ADJUSTMENT_ORDER: [usize; NO_OF_ADJ_NOTCHES] = [2, 6, #[derive(Clone, Debug, Default, Format)] pub struct StickParams { - // these are the linearization coefficients + /// these are the linearization coefficients pub fit_coeffs: XyValuePair<[f32; NUM_COEFFS]>, // these are the notch remap parameters - pub affine_coeffs: [[f32; 4]; 16], // affine transformation coefficients for all regions of the stick - pub boundary_angles: [f32; 16], // angles at the boundaries between regions of the stick (in the plane) + /// affine transformation coefficients for all regions of the stick + pub affine_coeffs: [[f32; 4]; 16], + /// angles at the boundaries between regions of the stick (in the plane) + pub boundary_angles: [f32; 16], } impl From<&StickConfig> for StickParams { -- 2.47.0