diff --git a/src/input.rs b/src/input.rs index c0d0d0b..9eb5c12 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] @@ -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 { @@ -621,13 +621,14 @@ 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; 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..d91ea51 100644 --- a/src/stick.rs +++ b/src/stick.rs @@ -32,17 +32,19 @@ 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 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 +429,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);