From c500940f26e13a05f57169fa16a190a817a05713 Mon Sep 17 00:00:00 2001 From: Marc Riera Date: Fri, 3 Mar 2023 18:16:56 +0100 Subject: [PATCH] Finish TCPP-20009, initial work on VOK-00106 --- src/controller/emulated.rs | 20 +++++++++--- src/controller/emulated/tcpp20009.rs | 46 ++++++++++++++++++++++++++++ src/controller/emulated/vok00106.rs | 10 ++++++ 3 files changed, 71 insertions(+), 5 deletions(-) create mode 100644 src/controller/emulated/tcpp20009.rs create mode 100644 src/controller/emulated/vok00106.rs diff --git a/src/controller/emulated.rs b/src/controller/emulated.rs index 7e65eff..5efb98c 100644 --- a/src/controller/emulated.rs +++ b/src/controller/emulated.rs @@ -1,11 +1,14 @@ use crate::state::ControllerState; mod dgoc44u; +mod tcpp20009; +mod vok00106; #[derive(PartialEq)] pub enum ControllerModel { NONE, DGOC44U, - TYPE2, + TCPP20009, + VOK00106, } pub fn set_model(state: &ControllerState) -> ControllerModel { @@ -15,7 +18,11 @@ pub fn set_model(state: &ControllerState) -> ControllerModel { } else if state.button_up { println!("Selected controller TCPP-20009."); - return ControllerModel::TYPE2; + return ControllerModel::TCPP20009; + } + else if state.button_a { + println!("Selected controller VOK-00106."); + return ControllerModel::VOK00106; } else { println!("No controller selected."); @@ -28,9 +35,12 @@ pub fn set_state(state: &mut ControllerState, model: &ControllerModel) { ControllerModel::DGOC44U => { dgoc44u::update_gadget(state); } - ControllerModel::TYPE2 => { - + ControllerModel::TCPP20009 => { + tcpp20009::update_gadget(state); } - ControllerModel::NONE => (), + ControllerModel::VOK00106 => { + vok00106::update_gadget(state); + } + _ => (), } } diff --git a/src/controller/emulated/tcpp20009.rs b/src/controller/emulated/tcpp20009.rs new file mode 100644 index 0000000..81c1c93 --- /dev/null +++ b/src/controller/emulated/tcpp20009.rs @@ -0,0 +1,46 @@ +use bitflags::bitflags; +use crate::state::ControllerState; + +const POWER_NOTCHES: [u8; 6] = [0x81, 0x6D, 0x54, 0x3F, 0x21, 0x00]; +const BRAKE_NOTCHES: [u8; 10] = [0x79, 0x8A, 0x94, 0x9A, 0xA2, 0xA8, 0xAF, 0xB2, 0xB5, 0xB9]; + +bitflags! { + struct Buttons: u8 { + const NONE = 0; + const B = 1; + const A = 2; + const C = 4; + const D = 8; + const SELECT = 16; + const START = 32; + } + } + +pub fn update_gadget(state: &mut ControllerState) { + // Calculate data for handles + let power = POWER_NOTCHES[state.power as usize]; + let brake = BRAKE_NOTCHES[state.brake as usize]; + + // Calculate data for buttons + let mut buttons = Buttons::NONE; + if state.button_a { buttons.insert(Buttons::A) } + if state.button_b { buttons.insert(Buttons::B) } + if state.button_c { buttons.insert(Buttons::C) } + if state.button_d { buttons.insert(Buttons::D) } + if state.button_select { buttons.insert(Buttons::SELECT) } + if state.button_start { buttons.insert(Buttons::START) } + + // Calculate data for D-pad + let mut dpad: u8 = 0x8; + if state.button_up { dpad = 0x0 } + if state.button_down { dpad = 0x4 } + if state.button_left { dpad = 0x6 } + if state.button_right { dpad = 0x2 } + if state.button_up & state.button_left { dpad = 0x7 } + if state.button_up & state.button_right { dpad = 0x1 } + if state.button_down & state.button_left { dpad = 0x5 } + if state.button_down & state.button_right { dpad = 0x3 } + + // Assemble data and send it to gadget + let data = [0x1, brake, power, 0xFF, dpad, buttons.bits]; +} \ No newline at end of file diff --git a/src/controller/emulated/vok00106.rs b/src/controller/emulated/vok00106.rs new file mode 100644 index 0000000..5c6f8b5 --- /dev/null +++ b/src/controller/emulated/vok00106.rs @@ -0,0 +1,10 @@ +use crate::state::ControllerState; + +const POWER_NOTCHES: [&str; 6] = ["TSA50", "TSA55", "TSA65", "TSA75", "TSA85", "TSA95"]; +const BRAKE_NOTCHES: [&str; 10] = ["TSA50", "TSA45", "TSA35", "TSA25", "TSA15", "TSA05", "TSE99", "TSB40", "TSB30", "TSB20"]; + +pub fn update_gadget(state: &mut ControllerState) { + // Calculate data for handles + let power = POWER_NOTCHES[state.power as usize]; + let brake = BRAKE_NOTCHES[state.brake as usize]; +} \ No newline at end of file