chore: refactor according to clippy & clean up config #6
3 changed files with 625 additions and 576 deletions
411
src/config.rs
411
src/config.rs
|
@ -13,7 +13,9 @@ use embassy_rp::{
|
|||
use packed_struct::{derive::PackedStruct, PackedStruct};
|
||||
|
||||
use crate::{
|
||||
gcc_hid::{SIGNAL_CHANGE_RUMBLE_STRENGTH, SIGNAL_INPUT_CONSISTENCY_MODE_STATUS},
|
||||
gcc_hid::{
|
||||
Buttons1, Buttons2, SIGNAL_CHANGE_RUMBLE_STRENGTH, SIGNAL_INPUT_CONSISTENCY_MODE_STATUS,
|
||||
},
|
||||
helpers::{PackedFloat, ToPackedFloatArray, ToRegularArray, XyValuePair},
|
||||
input::{
|
||||
read_ext_adc, Stick, StickAxis, FLOAT_ORIGIN, SPI_ACS_SHARED, SPI_CCS_SHARED, SPI_SHARED,
|
||||
|
@ -561,8 +563,6 @@ impl ControllerConfig {
|
|||
if r.is_err() {
|
||||
warn!("Controller config not found in flash, using default.");
|
||||
controller_config_packed = [0u8; 659];
|
||||
} else {
|
||||
r.unwrap();
|
||||
}
|
||||
|
||||
match ControllerConfig::unpack(&controller_config_packed) {
|
||||
|
@ -1044,9 +1044,8 @@ fn get_stick_display_coords(current_step: usize) -> (f32, f32) {
|
|||
let idx = CALIBRATION_ORDER[current_step];
|
||||
if idx % 2 != 0 {
|
||||
let notch_idx = idx / 2;
|
||||
match calc_stick_values(DEFAULT_ANGLES[notch_idx]) {
|
||||
(x, y) => (x + FLOAT_ORIGIN, y + FLOAT_ORIGIN),
|
||||
}
|
||||
let (x, y) = calc_stick_values(DEFAULT_ANGLES[notch_idx]);
|
||||
(x + FLOAT_ORIGIN, y + FLOAT_ORIGIN)
|
||||
} else {
|
||||
(127.5, 127.5)
|
||||
}
|
||||
|
@ -1065,7 +1064,7 @@ async fn configuration_main_loop<
|
|||
const P: usize,
|
||||
>(
|
||||
current_config: &ControllerConfig,
|
||||
mut flash: &mut Flash<'static, FLASH, Async, FLASH_SIZE>,
|
||||
flash: &mut Flash<'static, FLASH, Async, FLASH_SIZE>,
|
||||
gcc_subscriber: &mut Subscriber<'a, M, GcReport, C, S, P>,
|
||||
) -> ControllerConfig {
|
||||
let mut final_config = current_config.clone();
|
||||
|
@ -1114,29 +1113,31 @@ async fn configuration_main_loop<
|
|||
];
|
||||
|
||||
'main: loop {
|
||||
match gcc_subscriber
|
||||
let selection = gcc_subscriber
|
||||
.wait_and_filter_simultaneous_button_presses(&config_options)
|
||||
.await
|
||||
{
|
||||
selection => match selection {
|
||||
.await;
|
||||
match selection {
|
||||
// exit
|
||||
0 => {
|
||||
override_gcc_state_and_wait(&OverrideGcReportInstruction {
|
||||
report: match GcReport::default() {
|
||||
mut a => {
|
||||
a.trigger_r = 255;
|
||||
a.trigger_l = 255;
|
||||
a.buttons_2.button_l = true;
|
||||
a.buttons_2.button_r = true;
|
||||
a.buttons_1.button_x = true;
|
||||
a.buttons_1.button_y = true;
|
||||
a.buttons_1.button_a = true;
|
||||
a.stick_x = 127;
|
||||
a.stick_y = 127;
|
||||
a.cstick_x = 127;
|
||||
a.cstick_y = 127;
|
||||
a
|
||||
}
|
||||
report: GcReport {
|
||||
trigger_r: 255,
|
||||
trigger_l: 255,
|
||||
buttons_2: Buttons2 {
|
||||
button_r: true,
|
||||
button_l: true,
|
||||
..Default::default()
|
||||
},
|
||||
buttons_1: Buttons1 {
|
||||
button_x: true,
|
||||
button_y: true,
|
||||
button_a: true,
|
||||
..Default::default()
|
||||
},
|
||||
stick_x: 127,
|
||||
stick_y: 127,
|
||||
cstick_x: 127,
|
||||
cstick_y: 127,
|
||||
},
|
||||
duration_ms: 1000,
|
||||
})
|
||||
|
@ -1147,20 +1148,24 @@ async fn configuration_main_loop<
|
|||
// calibrate lstick
|
||||
1 => {
|
||||
override_gcc_state_and_wait(&OverrideGcReportInstruction {
|
||||
report: match GcReport::default() {
|
||||
mut a => {
|
||||
a.trigger_r = 255;
|
||||
a.trigger_l = 255;
|
||||
a.buttons_2.button_r = true;
|
||||
a.buttons_2.button_l = true;
|
||||
a.buttons_1.button_x = true;
|
||||
a.buttons_1.button_a = true;
|
||||
a.stick_x = 255;
|
||||
a.stick_y = 255;
|
||||
a.cstick_x = 127;
|
||||
a.cstick_y = 127;
|
||||
a
|
||||
}
|
||||
report: GcReport {
|
||||
trigger_r: 255,
|
||||
trigger_l: 255,
|
||||
buttons_2: Buttons2 {
|
||||
button_r: true,
|
||||
button_l: true,
|
||||
..Default::default()
|
||||
},
|
||||
buttons_1: Buttons1 {
|
||||
button_x: true,
|
||||
button_y: true,
|
||||
button_a: true,
|
||||
..Default::default()
|
||||
},
|
||||
stick_x: 255,
|
||||
stick_y: 255,
|
||||
cstick_x: 127,
|
||||
cstick_y: 127,
|
||||
},
|
||||
duration_ms: 1000,
|
||||
})
|
||||
|
@ -1172,20 +1177,24 @@ async fn configuration_main_loop<
|
|||
// calibrate rstick
|
||||
2 => {
|
||||
override_gcc_state_and_wait(&OverrideGcReportInstruction {
|
||||
report: match GcReport::default() {
|
||||
mut a => {
|
||||
a.trigger_r = 255;
|
||||
a.trigger_l = 255;
|
||||
a.buttons_2.button_r = true;
|
||||
a.buttons_2.button_l = true;
|
||||
a.buttons_1.button_x = true;
|
||||
a.buttons_1.button_a = true;
|
||||
a.stick_x = 127;
|
||||
a.stick_y = 127;
|
||||
a.cstick_x = 255;
|
||||
a.cstick_y = 255;
|
||||
a
|
||||
}
|
||||
report: GcReport {
|
||||
trigger_r: 255,
|
||||
trigger_l: 255,
|
||||
buttons_2: Buttons2 {
|
||||
button_r: true,
|
||||
button_l: true,
|
||||
..Default::default()
|
||||
},
|
||||
buttons_1: Buttons1 {
|
||||
button_x: true,
|
||||
button_y: true,
|
||||
button_a: true,
|
||||
..Default::default()
|
||||
},
|
||||
stick_x: 127,
|
||||
stick_y: 127,
|
||||
cstick_x: 255,
|
||||
cstick_y: 255,
|
||||
},
|
||||
duration_ms: 1000,
|
||||
})
|
||||
|
@ -1227,48 +1236,52 @@ async fn configuration_main_loop<
|
|||
.clamp(-ABS_MAX_SNAPBACK, ABS_MAX_SNAPBACK);
|
||||
|
||||
override_gcc_state_and_wait(&OverrideGcReportInstruction {
|
||||
report: match GcReport::default() {
|
||||
mut a => {
|
||||
a.trigger_r = 255;
|
||||
a.trigger_l = 255;
|
||||
a.buttons_2.button_r = true;
|
||||
a.buttons_2.button_l = true;
|
||||
a.buttons_1.button_x = true;
|
||||
a.buttons_1.button_a = true;
|
||||
a.stick_x = (127
|
||||
report: GcReport {
|
||||
trigger_r: 255,
|
||||
trigger_l: 255,
|
||||
buttons_2: Buttons2 {
|
||||
button_r: true,
|
||||
button_l: true,
|
||||
..Default::default()
|
||||
},
|
||||
buttons_1: Buttons1 {
|
||||
button_x: true,
|
||||
button_y: true,
|
||||
button_a: true,
|
||||
..Default::default()
|
||||
},
|
||||
stick_x: (127
|
||||
+ match stick {
|
||||
Stick::ControlStick => match axis {
|
||||
StickAxis::XAxis => *to_adjust,
|
||||
StickAxis::YAxis => 0,
|
||||
},
|
||||
Stick::CStick => 0,
|
||||
}) as u8;
|
||||
a.stick_y = (127
|
||||
}) as u8,
|
||||
stick_y: (127
|
||||
+ match stick {
|
||||
Stick::ControlStick => match axis {
|
||||
StickAxis::XAxis => 0,
|
||||
StickAxis::YAxis => *to_adjust,
|
||||
},
|
||||
Stick::CStick => 0,
|
||||
}) as u8;
|
||||
a.cstick_x = (127
|
||||
}) as u8,
|
||||
cstick_x: (127
|
||||
+ match stick {
|
||||
Stick::ControlStick => 0,
|
||||
Stick::CStick => match axis {
|
||||
StickAxis::XAxis => *to_adjust,
|
||||
StickAxis::YAxis => 0,
|
||||
},
|
||||
}) as u8;
|
||||
a.cstick_y = (127
|
||||
}) as u8,
|
||||
cstick_y: (127
|
||||
+ match stick {
|
||||
Stick::ControlStick => 0,
|
||||
Stick::CStick => match axis {
|
||||
StickAxis::XAxis => 0,
|
||||
StickAxis::YAxis => *to_adjust,
|
||||
},
|
||||
}) as u8;
|
||||
a
|
||||
}
|
||||
}) as u8,
|
||||
},
|
||||
duration_ms: 750,
|
||||
})
|
||||
|
@ -1309,48 +1322,52 @@ async fn configuration_main_loop<
|
|||
.clamp(0, MAX_WAVESHAPING) as u8;
|
||||
|
||||
override_gcc_state_and_wait(&OverrideGcReportInstruction {
|
||||
report: match GcReport::default() {
|
||||
mut a => {
|
||||
a.trigger_r = 255;
|
||||
a.trigger_l = 255;
|
||||
a.buttons_2.button_r = true;
|
||||
a.buttons_2.button_l = true;
|
||||
a.buttons_1.button_x = true;
|
||||
a.buttons_1.button_a = true;
|
||||
a.stick_x = (127
|
||||
report: GcReport {
|
||||
trigger_r: 255,
|
||||
trigger_l: 255,
|
||||
buttons_2: Buttons2 {
|
||||
button_r: true,
|
||||
button_l: true,
|
||||
..Default::default()
|
||||
},
|
||||
buttons_1: Buttons1 {
|
||||
button_x: true,
|
||||
button_y: true,
|
||||
button_a: true,
|
||||
..Default::default()
|
||||
},
|
||||
stick_x: (127
|
||||
+ match stick {
|
||||
Stick::ControlStick => match axis {
|
||||
StickAxis::XAxis => *to_adjust,
|
||||
StickAxis::YAxis => 0,
|
||||
},
|
||||
Stick::CStick => 0,
|
||||
}) as u8;
|
||||
a.stick_y = (127
|
||||
}) as u8,
|
||||
stick_y: (127
|
||||
+ match stick {
|
||||
Stick::ControlStick => match axis {
|
||||
StickAxis::XAxis => 0,
|
||||
StickAxis::YAxis => *to_adjust,
|
||||
},
|
||||
Stick::CStick => 0,
|
||||
}) as u8;
|
||||
a.cstick_x = (127
|
||||
}) as u8,
|
||||
cstick_x: (127
|
||||
+ match stick {
|
||||
Stick::ControlStick => 0,
|
||||
Stick::CStick => match axis {
|
||||
StickAxis::XAxis => *to_adjust,
|
||||
StickAxis::YAxis => 0,
|
||||
},
|
||||
}) as u8;
|
||||
a.cstick_y = (127
|
||||
}) as u8,
|
||||
cstick_y: (127
|
||||
+ match stick {
|
||||
Stick::ControlStick => 0,
|
||||
Stick::CStick => match axis {
|
||||
StickAxis::XAxis => 0,
|
||||
StickAxis::YAxis => *to_adjust,
|
||||
},
|
||||
}) as u8;
|
||||
a
|
||||
}
|
||||
}) as u8,
|
||||
},
|
||||
duration_ms: 750,
|
||||
})
|
||||
|
@ -1391,48 +1408,52 @@ async fn configuration_main_loop<
|
|||
.clamp(0, MAX_SMOOTHING) as u8;
|
||||
|
||||
override_gcc_state_and_wait(&OverrideGcReportInstruction {
|
||||
report: match GcReport::default() {
|
||||
mut a => {
|
||||
a.trigger_r = 255;
|
||||
a.trigger_l = 255;
|
||||
a.buttons_2.button_r = true;
|
||||
a.buttons_2.button_l = true;
|
||||
a.buttons_1.button_x = true;
|
||||
a.buttons_1.button_a = true;
|
||||
a.stick_x = (127
|
||||
report: GcReport {
|
||||
trigger_r: 255,
|
||||
trigger_l: 255,
|
||||
buttons_2: Buttons2 {
|
||||
button_r: true,
|
||||
button_l: true,
|
||||
..Default::default()
|
||||
},
|
||||
buttons_1: Buttons1 {
|
||||
button_x: true,
|
||||
button_y: true,
|
||||
button_a: true,
|
||||
..Default::default()
|
||||
},
|
||||
stick_x: (127
|
||||
+ match stick {
|
||||
Stick::ControlStick => match axis {
|
||||
StickAxis::XAxis => *to_adjust,
|
||||
StickAxis::YAxis => 0,
|
||||
},
|
||||
Stick::CStick => 0,
|
||||
}) as u8;
|
||||
a.stick_y = (127
|
||||
}) as u8,
|
||||
stick_y: (127
|
||||
+ match stick {
|
||||
Stick::ControlStick => match axis {
|
||||
StickAxis::XAxis => 0,
|
||||
StickAxis::YAxis => *to_adjust,
|
||||
},
|
||||
Stick::CStick => 0,
|
||||
}) as u8;
|
||||
a.cstick_x = (127
|
||||
}) as u8,
|
||||
cstick_x: (127
|
||||
+ match stick {
|
||||
Stick::ControlStick => 0,
|
||||
Stick::CStick => match axis {
|
||||
StickAxis::XAxis => *to_adjust,
|
||||
StickAxis::YAxis => 0,
|
||||
},
|
||||
}) as u8;
|
||||
a.cstick_y = (127
|
||||
}) as u8,
|
||||
cstick_y: (127
|
||||
+ match stick {
|
||||
Stick::ControlStick => 0,
|
||||
Stick::CStick => match axis {
|
||||
StickAxis::XAxis => 0,
|
||||
StickAxis::YAxis => *to_adjust,
|
||||
},
|
||||
}) as u8;
|
||||
a
|
||||
}
|
||||
}) as u8,
|
||||
},
|
||||
duration_ms: 750,
|
||||
})
|
||||
|
@ -1463,28 +1484,32 @@ async fn configuration_main_loop<
|
|||
.clamp(-1, MAX_CARDINAL_SNAP);
|
||||
|
||||
override_gcc_state_and_wait(&OverrideGcReportInstruction {
|
||||
report: match GcReport::default() {
|
||||
mut a => {
|
||||
a.trigger_r = 255;
|
||||
a.trigger_l = 255;
|
||||
a.buttons_2.button_r = true;
|
||||
a.buttons_2.button_l = true;
|
||||
a.buttons_1.button_x = true;
|
||||
a.buttons_1.button_a = true;
|
||||
a.stick_x = 127;
|
||||
a.stick_y = (127
|
||||
report: GcReport {
|
||||
trigger_r: 255,
|
||||
trigger_l: 255,
|
||||
buttons_2: Buttons2 {
|
||||
button_r: true,
|
||||
button_l: true,
|
||||
..Default::default()
|
||||
},
|
||||
buttons_1: Buttons1 {
|
||||
button_x: true,
|
||||
button_y: true,
|
||||
button_a: true,
|
||||
..Default::default()
|
||||
},
|
||||
stick_x: 127,
|
||||
stick_y: (127
|
||||
+ match stick {
|
||||
Stick::ControlStick => *to_adjust,
|
||||
Stick::CStick => 0,
|
||||
}) as u8;
|
||||
a.cstick_x = 127;
|
||||
a.cstick_y = (127
|
||||
}) as u8,
|
||||
cstick_x: 127,
|
||||
cstick_y: (127
|
||||
+ match stick {
|
||||
Stick::ControlStick => 0,
|
||||
Stick::CStick => *to_adjust,
|
||||
}) as u8;
|
||||
a
|
||||
}
|
||||
}) as u8,
|
||||
},
|
||||
duration_ms: 750,
|
||||
})
|
||||
|
@ -1515,28 +1540,32 @@ async fn configuration_main_loop<
|
|||
.clamp(MIN_ANALOG_SCALER, MAX_ANALOG_SCALER);
|
||||
|
||||
override_gcc_state_and_wait(&OverrideGcReportInstruction {
|
||||
report: match GcReport::default() {
|
||||
mut a => {
|
||||
a.trigger_r = 255;
|
||||
a.trigger_l = 255;
|
||||
a.buttons_2.button_r = true;
|
||||
a.buttons_2.button_l = true;
|
||||
a.buttons_1.button_x = true;
|
||||
a.buttons_1.button_a = true;
|
||||
a.stick_x = 127;
|
||||
a.stick_y = (127
|
||||
report: GcReport {
|
||||
trigger_r: 255,
|
||||
trigger_l: 255,
|
||||
buttons_2: Buttons2 {
|
||||
button_r: true,
|
||||
button_l: true,
|
||||
..Default::default()
|
||||
},
|
||||
buttons_1: Buttons1 {
|
||||
button_x: true,
|
||||
button_y: true,
|
||||
button_a: true,
|
||||
..Default::default()
|
||||
},
|
||||
stick_x: 127,
|
||||
stick_y: (127
|
||||
+ match stick {
|
||||
Stick::ControlStick => *to_adjust,
|
||||
Stick::CStick => 0,
|
||||
}) as u8;
|
||||
a.cstick_x = 127;
|
||||
a.cstick_y = (127
|
||||
}) as u8,
|
||||
cstick_x: 127,
|
||||
cstick_y: (127
|
||||
+ match stick {
|
||||
Stick::ControlStick => 0,
|
||||
Stick::CStick => *to_adjust,
|
||||
}) as u8;
|
||||
a
|
||||
}
|
||||
}) as u8,
|
||||
},
|
||||
duration_ms: 750,
|
||||
})
|
||||
|
@ -1559,21 +1588,25 @@ async fn configuration_main_loop<
|
|||
SIGNAL_CHANGE_RUMBLE_STRENGTH.signal(*to_adjust);
|
||||
|
||||
override_gcc_state_and_wait(&OverrideGcReportInstruction {
|
||||
report: match GcReport::default() {
|
||||
mut a => {
|
||||
a.trigger_r = 255;
|
||||
a.trigger_l = 255;
|
||||
a.buttons_2.button_r = true;
|
||||
a.buttons_2.button_l = true;
|
||||
a.buttons_1.button_x = true;
|
||||
a.buttons_1.button_a = true;
|
||||
a.buttons_2.button_z = true; // makes the controller rumble in smashscope
|
||||
a.stick_x = 127;
|
||||
a.stick_y = 127;
|
||||
a.cstick_x = 127;
|
||||
a.cstick_y = 127;
|
||||
a
|
||||
}
|
||||
report: GcReport {
|
||||
trigger_r: 255,
|
||||
trigger_l: 255,
|
||||
buttons_2: Buttons2 {
|
||||
button_r: true,
|
||||
button_l: true,
|
||||
button_z: true,
|
||||
..Default::default()
|
||||
},
|
||||
buttons_1: Buttons1 {
|
||||
button_x: true,
|
||||
button_y: true,
|
||||
button_a: true,
|
||||
..Default::default()
|
||||
},
|
||||
stick_x: 127,
|
||||
stick_y: 127,
|
||||
cstick_x: 127,
|
||||
cstick_y: 127,
|
||||
},
|
||||
duration_ms: 750,
|
||||
})
|
||||
|
@ -1586,24 +1619,28 @@ async fn configuration_main_loop<
|
|||
final_config.input_consistency_mode = !final_config.input_consistency_mode;
|
||||
|
||||
override_gcc_state_and_wait(&OverrideGcReportInstruction {
|
||||
report: match GcReport::default() {
|
||||
mut a => {
|
||||
a.trigger_r = 255;
|
||||
a.trigger_l = 255;
|
||||
a.buttons_2.button_r = true;
|
||||
a.buttons_2.button_l = true;
|
||||
a.buttons_1.button_x = true;
|
||||
a.buttons_1.button_a = true;
|
||||
a.stick_x = 127;
|
||||
a.stick_y = (127_i8
|
||||
report: GcReport {
|
||||
trigger_r: 255,
|
||||
trigger_l: 255,
|
||||
buttons_2: Buttons2 {
|
||||
button_r: true,
|
||||
button_l: true,
|
||||
..Default::default()
|
||||
},
|
||||
buttons_1: Buttons1 {
|
||||
button_x: true,
|
||||
button_y: true,
|
||||
button_a: true,
|
||||
..Default::default()
|
||||
},
|
||||
stick_x: 127,
|
||||
stick_y: (127_i8
|
||||
+ match final_config.input_consistency_mode {
|
||||
true => 69,
|
||||
false => -69,
|
||||
}) as u8;
|
||||
a.cstick_x = 127;
|
||||
a.cstick_y = 127;
|
||||
a
|
||||
}
|
||||
}) as u8,
|
||||
cstick_x: 127,
|
||||
cstick_y: 127,
|
||||
},
|
||||
duration_ms: 750,
|
||||
})
|
||||
|
@ -1615,7 +1652,6 @@ async fn configuration_main_loop<
|
|||
error!("Invalid selection in config loop: {}", s);
|
||||
continue;
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
final_config.write_to_flash(flash).unwrap();
|
||||
|
@ -1656,21 +1692,24 @@ pub async fn config_task(mut flash: Flash<'static, FLASH, Async, FLASH_SIZE>) {
|
|||
info!("Entering config mode.");
|
||||
|
||||
override_gcc_state_and_wait(&OverrideGcReportInstruction {
|
||||
report: match GcReport::default() {
|
||||
mut a => {
|
||||
a.trigger_r = 255;
|
||||
a.trigger_l = 255;
|
||||
a.buttons_2.button_l = true;
|
||||
a.buttons_2.button_r = true;
|
||||
a.buttons_1.button_x = true;
|
||||
a.buttons_1.button_y = true;
|
||||
a.buttons_1.button_a = true;
|
||||
a.stick_x = 127;
|
||||
a.stick_y = 127;
|
||||
a.cstick_x = 127;
|
||||
a.cstick_y = 127;
|
||||
a
|
||||
}
|
||||
report: GcReport {
|
||||
trigger_r: 255,
|
||||
trigger_l: 255,
|
||||
buttons_2: Buttons2 {
|
||||
button_l: true,
|
||||
button_r: true,
|
||||
..Default::default()
|
||||
},
|
||||
buttons_1: Buttons1 {
|
||||
button_x: true,
|
||||
button_y: true,
|
||||
button_a: true,
|
||||
..Default::default()
|
||||
},
|
||||
stick_x: 127,
|
||||
stick_y: 127,
|
||||
cstick_x: 127,
|
||||
cstick_y: 127,
|
||||
},
|
||||
duration_ms: 1000,
|
||||
})
|
||||
|
|
53
src/input.rs
53
src/input.rs
|
@ -122,6 +122,7 @@ pub fn read_ext_adc<
|
|||
|
||||
/// Gets the average stick state over a 1ms interval in a non-blocking fashion.
|
||||
/// Will wait until end_time is reached before continuing after reading the ADCs.
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
#[link_section = ".time_critical.update_stick_states"]
|
||||
async fn update_stick_states(
|
||||
current_stick_state: &StickState,
|
||||
|
@ -200,15 +201,16 @@ async fn update_stick_states(
|
|||
let (x_pos_filt, y_pos_filt) =
|
||||
kalman_state.run_kalman(x_z, y_z, &controller_config.astick_config, filter_gains);
|
||||
|
||||
let shaped_astick = match run_waveshaping(
|
||||
let shaped_astick = {
|
||||
let (x, y) = run_waveshaping(
|
||||
x_pos_filt,
|
||||
y_pos_filt,
|
||||
controller_config.astick_config.x_waveshaping,
|
||||
controller_config.astick_config.y_waveshaping,
|
||||
controlstick_waveshaping_values,
|
||||
filter_gains,
|
||||
) {
|
||||
(x, y) => XyValuePair { x, y },
|
||||
);
|
||||
XyValuePair { x, y }
|
||||
};
|
||||
|
||||
trace!("Shaped Controlstick: {}", shaped_astick);
|
||||
|
@ -220,15 +222,16 @@ async fn update_stick_states(
|
|||
old_stick_pos.x = pos_x;
|
||||
old_stick_pos.y = pos_y;
|
||||
|
||||
let shaped_cstick = match run_waveshaping(
|
||||
let shaped_cstick = {
|
||||
let (x, y) = run_waveshaping(
|
||||
pos_cx,
|
||||
pos_cy,
|
||||
controller_config.cstick_config.x_waveshaping,
|
||||
controller_config.cstick_config.y_waveshaping,
|
||||
cstick_waveshaping_values,
|
||||
filter_gains,
|
||||
) {
|
||||
(x, y) => XyValuePair { x, y },
|
||||
);
|
||||
XyValuePair { x, y }
|
||||
};
|
||||
|
||||
let old_c_pos = XyValuePair {
|
||||
|
@ -250,41 +253,45 @@ async fn update_stick_states(
|
|||
|
||||
trace!("Cstick position: {}, {}", pos_cx, pos_cy);
|
||||
|
||||
let mut remapped = match notch_remap(
|
||||
let mut remapped = {
|
||||
let (x, y) = notch_remap(
|
||||
pos_x,
|
||||
pos_y,
|
||||
controlstick_params,
|
||||
&controller_config.astick_config,
|
||||
is_calibrating,
|
||||
) {
|
||||
(x, y) => XyValuePair { x, y },
|
||||
);
|
||||
XyValuePair { x, y }
|
||||
};
|
||||
let mut remapped_c = match notch_remap(
|
||||
let mut remapped_c = {
|
||||
let (x, y) = notch_remap(
|
||||
pos_cx_filt,
|
||||
pos_cy_filt,
|
||||
cstick_params,
|
||||
&controller_config.cstick_config,
|
||||
is_calibrating,
|
||||
) {
|
||||
(x, y) => XyValuePair { x, y },
|
||||
);
|
||||
XyValuePair { x, y }
|
||||
};
|
||||
let remapped_unfiltered = match notch_remap(
|
||||
let remapped_unfiltered = {
|
||||
let (x, y) = notch_remap(
|
||||
raw_stick_values.a_linearized.x,
|
||||
raw_stick_values.a_linearized.y,
|
||||
controlstick_params,
|
||||
&controller_config.astick_config,
|
||||
is_calibrating,
|
||||
) {
|
||||
(x, y) => XyValuePair { x, y },
|
||||
);
|
||||
XyValuePair { x, y }
|
||||
};
|
||||
let remapped_c_unfiltered = match notch_remap(
|
||||
let remapped_c_unfiltered = {
|
||||
let (x, y) = notch_remap(
|
||||
raw_stick_values.c_linearized.x,
|
||||
raw_stick_values.c_linearized.y,
|
||||
cstick_params,
|
||||
&controller_config.cstick_config,
|
||||
is_calibrating,
|
||||
) {
|
||||
(x, y) => XyValuePair { x, y },
|
||||
);
|
||||
XyValuePair { x, y }
|
||||
};
|
||||
|
||||
trace!(
|
||||
|
@ -337,6 +344,7 @@ async fn update_stick_states(
|
|||
out_stick_state
|
||||
}
|
||||
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
fn update_button_states<
|
||||
A: Pin,
|
||||
B: Pin,
|
||||
|
@ -405,6 +413,7 @@ pub async fn input_integrity_benchmark() {
|
|||
|
||||
/// Task responsible for updating the button states.
|
||||
/// Publishes the result to CHANNEL_GCC_STATE.
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
#[embassy_executor::task]
|
||||
pub async fn update_button_state_task(
|
||||
btn_z: Input<'static, AnyPin>,
|
||||
|
@ -424,6 +433,8 @@ pub async fn update_button_state_task(
|
|||
if btn_a.is_low() && btn_x.is_low() && btn_y.is_low() {
|
||||
info!("Detected reset button press, booting into flash.");
|
||||
embassy_rp::rom_data::reset_to_usb_boot(0, 0);
|
||||
|
||||
#[allow(clippy::empty_loop)]
|
||||
loop {}
|
||||
}
|
||||
|
||||
|
@ -561,14 +572,14 @@ pub async fn update_stick_states_task(
|
|||
}
|
||||
}
|
||||
|
||||
match Instant::now() {
|
||||
n => {
|
||||
{
|
||||
let n = Instant::now();
|
||||
|
||||
match (n - last_loop_time).as_micros() {
|
||||
a if a > 1666 => debug!("Loop took {} us", a),
|
||||
_ => {}
|
||||
};
|
||||
last_loop_time = n;
|
||||
}
|
||||
};
|
||||
|
||||
SIGNAL_STICK_STATE.signal(current_stick_state.clone());
|
||||
|
|
33
src/stick.rs
33
src/stick.rs
|
@ -123,10 +123,10 @@ impl CleanedCalibrationPoints {
|
|||
out.cleaned_points.x[i + 1] = cal_points_x[i * 2 + 1];
|
||||
out.cleaned_points.y[i + 1] = cal_points_y[i * 2 + 1];
|
||||
|
||||
(out.notch_points.x[i + 1], out.notch_points.y[i + 1]) =
|
||||
match calc_stick_values(notch_angles[i]) {
|
||||
(a, b) => (roundf(a), roundf(b)),
|
||||
};
|
||||
(out.notch_points.x[i + 1], out.notch_points.y[i + 1]) = {
|
||||
let (a, b) = calc_stick_values(notch_angles[i]);
|
||||
(roundf(a), roundf(b))
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: put the below in a macro to clean it up a bit, once it's confirmed to work
|
||||
|
@ -186,6 +186,7 @@ impl CleanedCalibrationPoints {
|
|||
out.cleaned_points.x[0] /= (NO_OF_NOTCHES - 4) as f32;
|
||||
out.cleaned_points.y[0] /= (NO_OF_NOTCHES - 4) as f32;
|
||||
|
||||
#[allow(clippy::needless_range_loop)]
|
||||
for i in 0..NO_OF_NOTCHES {
|
||||
let delta_x = out.cleaned_points.x[i + 1] - out.cleaned_points.x[0];
|
||||
let delta_y = out.cleaned_points.y[i + 1] - out.cleaned_points.y[0];
|
||||
|
@ -241,11 +242,9 @@ impl LinearizedCalibration {
|
|||
///
|
||||
/// Generate a fit to linearize the stick response.
|
||||
///
|
||||
/// Inputs:
|
||||
/// cleaned points X and Y, (must be 17 points for each of these, the first being the center, the others starting at 3 oclock and going around counterclockwise)
|
||||
/// Inputs: cleaned points X and Y, (must be 17 points for each of these, the first being the center, the others starting at 3 oclock and going around counterclockwise)
|
||||
///
|
||||
/// Outputs:
|
||||
/// linearization fit coefficients for X and Y
|
||||
/// Outputs: linearization fit coefficients for X and Y
|
||||
pub fn from_calibration_points(cleaned_calibration_points: &CleanedCalibrationPoints) -> Self {
|
||||
let mut fit_points_x = [0f64; 5];
|
||||
let mut fit_points_y = [0f64; 5];
|
||||
|
@ -376,6 +375,7 @@ impl NotchCalibration {
|
|||
|
||||
trace!("The transform matrix is: {:?}", a);
|
||||
|
||||
#[allow(clippy::needless_range_loop)]
|
||||
for j in 0..2 {
|
||||
for k in 0..2 {
|
||||
out.affine_coeffs[i - 1][j * 2 + k] = a[j][k];
|
||||
|
@ -721,6 +721,7 @@ fn inverse(in_mat: &[[f32; 3]; 3]) -> [[f32; 3]; 3] {
|
|||
out_mat
|
||||
}
|
||||
|
||||
#[allow(clippy::needless_range_loop)]
|
||||
fn matrix_mult(a: &[[f32; 3]; 3], b: &[[f32; 3]; 3]) -> [[f32; 3]; 3] {
|
||||
let mut out = [[0f32; 3]; 3];
|
||||
|
||||
|
@ -777,8 +778,8 @@ fn det<const N: usize>(matrix: &[[f64; N]; N]) -> f64 {
|
|||
|
||||
let mut p = 1f64;
|
||||
|
||||
for i in 0..N {
|
||||
p *= matrix[i][i];
|
||||
for (i, elem) in matrix.iter().enumerate().take(N) {
|
||||
p *= elem[i];
|
||||
}
|
||||
|
||||
p * (sign as f64)
|
||||
|
@ -846,11 +847,11 @@ fn fit_curve<const N: usize, const NCOEFFS: usize>(
|
|||
for i in 0..N {
|
||||
let x = px[i];
|
||||
let y = py[i];
|
||||
for j in 0..NCOEFFS * 2 - 1 {
|
||||
s[j] += curve_fit_power(x, j as u32);
|
||||
for (j, elem) in s.iter_mut().enumerate().take(NCOEFFS * 2 - 1) {
|
||||
*elem += curve_fit_power(x, j as u32);
|
||||
}
|
||||
for j in 0..NCOEFFS {
|
||||
t[j] += y * curve_fit_power(x, j as u32);
|
||||
for (j, elem) in t.iter_mut().enumerate().take(NCOEFFS) {
|
||||
*elem += y * curve_fit_power(x, j as u32);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -858,9 +859,7 @@ fn fit_curve<const N: usize, const NCOEFFS: usize>(
|
|||
let mut matrix = [[0f64; NCOEFFS]; NCOEFFS];
|
||||
|
||||
for i in 0..NCOEFFS {
|
||||
for j in 0..NCOEFFS {
|
||||
matrix[i][j] = s[i + j];
|
||||
}
|
||||
matrix[i][..NCOEFFS].copy_from_slice(&s[i..(NCOEFFS + i)]);
|
||||
}
|
||||
|
||||
let denom = det(&matrix);
|
||||
|
|
Loading…
Reference in a new issue