chore: refactor according to clippy & clean up config #6
1 changed files with 25 additions and 23 deletions
|
@ -552,13 +552,13 @@ impl Default for ControllerConfig {
|
|||
|
||||
impl ControllerConfig {
|
||||
pub fn from_flash_memory(
|
||||
mut flash: &mut Flash<'static, FLASH, Async, FLASH_SIZE>,
|
||||
flash: &mut Flash<'static, FLASH, Async, FLASH_SIZE>,
|
||||
) -> Result<Self, embassy_rp::flash::Error> {
|
||||
let mut controller_config_packed: <ControllerConfig as packed_struct::PackedStruct>::ByteArray = ControllerConfig::default().pack().unwrap();
|
||||
|
||||
let r = flash.blocking_read(ADDR_OFFSET, &mut controller_config_packed);
|
||||
|
||||
if let Err(_) = r {
|
||||
if r.is_err() {
|
||||
warn!("Controller config not found in flash, using default.");
|
||||
controller_config_packed = [0u8; 659];
|
||||
} else {
|
||||
|
@ -582,7 +582,7 @@ impl ControllerConfig {
|
|||
|
||||
let cfg = ControllerConfig::default();
|
||||
info!("Going to save default controller config.");
|
||||
cfg.write_to_flash(&mut flash)?;
|
||||
cfg.write_to_flash(flash)?;
|
||||
Ok(cfg)
|
||||
}
|
||||
|
||||
|
@ -725,7 +725,7 @@ impl<'a, T: RawMutex, const I: usize, const J: usize, const K: usize> WaitForBut
|
|||
}
|
||||
}
|
||||
|
||||
return None;
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -779,7 +779,9 @@ impl<'a> StickCalibrationProcess<'a> {
|
|||
|
||||
if self.applied_calibration.cleaned_calibration.notch_status[notch_idx]
|
||||
== NotchStatus::TertInactive
|
||||
{}
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// assumes a tick rate of 1ms
|
||||
match notch_adjustment_type {
|
||||
|
@ -828,7 +830,7 @@ impl<'a> StickCalibrationProcess<'a> {
|
|||
stick_config.angles = *legalize_notches(
|
||||
self.calibration_step as usize,
|
||||
&self.applied_calibration.measured_notch_angles,
|
||||
&stick_config.angles.to_regular_array(),
|
||||
stick_config.angles.to_regular_array(),
|
||||
)
|
||||
.to_packed_float_array();
|
||||
|
||||
|
@ -883,7 +885,7 @@ impl<'a> StickCalibrationProcess<'a> {
|
|||
self.applied_calibration = AppliedCalibration::from_points(
|
||||
&self.cal_points.map(|e| e.x),
|
||||
&self.cal_points.map(|e| e.y),
|
||||
&stick_config,
|
||||
stick_config,
|
||||
);
|
||||
|
||||
stick_config.angles = *legalize_notches(
|
||||
|
@ -907,7 +909,7 @@ impl<'a> StickCalibrationProcess<'a> {
|
|||
stick_config.angles = *legalize_notches(
|
||||
self.calibration_step as usize,
|
||||
&self.applied_calibration.measured_notch_angles,
|
||||
&stick_config.angles.to_regular_array(),
|
||||
stick_config.angles.to_regular_array(),
|
||||
)
|
||||
.to_packed_float_array();
|
||||
|
||||
|
@ -935,7 +937,7 @@ impl<'a> StickCalibrationProcess<'a> {
|
|||
SIGNAL_CONFIG_CHANGE.signal(self.gcc_config.clone());
|
||||
}
|
||||
|
||||
return false;
|
||||
false
|
||||
}
|
||||
|
||||
pub async fn calibrate_stick(&mut self) {
|
||||
|
@ -1193,10 +1195,10 @@ async fn configuration_main_loop<
|
|||
.await;
|
||||
}
|
||||
// snapback changes
|
||||
i if i >= 3 && i <= 10 => {
|
||||
i if (3..=10).contains(&i) => {
|
||||
let stick = match i {
|
||||
3 | 4 | 5 | 6 => Stick::ControlStick,
|
||||
7 | 8 | 9 | 10 => Stick::CStick,
|
||||
3..=6 => Stick::ControlStick,
|
||||
7..=10 => Stick::CStick,
|
||||
_ => unreachable!(),
|
||||
};
|
||||
|
||||
|
@ -1275,10 +1277,10 @@ async fn configuration_main_loop<
|
|||
SIGNAL_CONFIG_CHANGE.signal(final_config.clone());
|
||||
}
|
||||
// waveshaping changes
|
||||
i if i >= 11 && i <= 18 => {
|
||||
i if (11..=18).contains(&i) => {
|
||||
let stick = match i {
|
||||
11 | 12 | 13 | 14 => Stick::ControlStick,
|
||||
15 | 16 | 17 | 18 => Stick::CStick,
|
||||
11..=14 => Stick::ControlStick,
|
||||
15..=18 => Stick::CStick,
|
||||
_ => unreachable!(),
|
||||
};
|
||||
|
||||
|
@ -1357,10 +1359,10 @@ async fn configuration_main_loop<
|
|||
SIGNAL_CONFIG_CHANGE.signal(final_config.clone());
|
||||
}
|
||||
// smoothing changes
|
||||
i if i >= 19 && i <= 26 => {
|
||||
i if (19..=26).contains(&i) => {
|
||||
let stick = match i {
|
||||
19 | 20 | 21 | 22 => Stick::ControlStick,
|
||||
23 | 24 | 25 | 26 => Stick::CStick,
|
||||
19..=22 => Stick::ControlStick,
|
||||
23..=26 => Stick::CStick,
|
||||
_ => unreachable!(),
|
||||
};
|
||||
|
||||
|
@ -1439,7 +1441,7 @@ async fn configuration_main_loop<
|
|||
SIGNAL_CONFIG_CHANGE.signal(final_config.clone());
|
||||
}
|
||||
// cardinalsnap increase/decrease
|
||||
i if i >= 27 && i <= 30 => {
|
||||
i if (27..=30).contains(&i) => {
|
||||
let stick = match i {
|
||||
27 | 28 => Stick::ControlStick,
|
||||
29 | 30 => Stick::CStick,
|
||||
|
@ -1491,7 +1493,7 @@ async fn configuration_main_loop<
|
|||
SIGNAL_CONFIG_CHANGE.signal(final_config.clone());
|
||||
}
|
||||
// scaling changes
|
||||
i if i >= 31 && i <= 34 => {
|
||||
i if (31..=34).contains(&i) => {
|
||||
let stick = match i {
|
||||
31 | 32 => Stick::ControlStick,
|
||||
33 | 34 => Stick::CStick,
|
||||
|
@ -1543,7 +1545,7 @@ async fn configuration_main_loop<
|
|||
SIGNAL_CONFIG_CHANGE.signal(final_config.clone());
|
||||
}
|
||||
// rumble strength changes
|
||||
i if i >= 35 && i <= 36 => {
|
||||
i if (35..=36).contains(&i) => {
|
||||
let to_adjust = &mut final_config.rumble_strength;
|
||||
|
||||
*to_adjust = (*to_adjust as i8
|
||||
|
@ -1593,7 +1595,7 @@ async fn configuration_main_loop<
|
|||
a.buttons_1.button_x = true;
|
||||
a.buttons_1.button_a = true;
|
||||
a.stick_x = 127;
|
||||
a.stick_y = (127 as i8
|
||||
a.stick_y = (127_i8
|
||||
+ match final_config.input_consistency_mode {
|
||||
true => 69,
|
||||
false => -69,
|
||||
|
@ -1616,7 +1618,7 @@ async fn configuration_main_loop<
|
|||
},
|
||||
};
|
||||
|
||||
final_config.write_to_flash(&mut flash).unwrap();
|
||||
final_config.write_to_flash(flash).unwrap();
|
||||
}
|
||||
|
||||
info!("Exiting config main loop.");
|
||||
|
|
Loading…
Reference in a new issue