chore(input/stick_params): use From trait

This commit is contained in:
Naxdy 2024-09-01 17:36:35 +02:00
parent 489b0ad105
commit 0fc2b9b4ae
Signed by: Naxdy
GPG key ID: CC15075846BCE91B
2 changed files with 8 additions and 8 deletions

View file

@ -556,8 +556,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 {
@ -622,8 +622,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);

View file

@ -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);