mirror of
https://github.com/marcriera/ddgo-pnp-controller.git
synced 2025-04-11 06:29:29 +02:00
Finish TCPP-20009, initial work on VOK-00106
This commit is contained in:
parent
37cd8456d1
commit
c500940f26
3 changed files with 71 additions and 5 deletions
|
@ -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);
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
|
|
46
src/controller/emulated/tcpp20009.rs
Normal file
46
src/controller/emulated/tcpp20009.rs
Normal file
|
@ -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];
|
||||
}
|
10
src/controller/emulated/vok00106.rs
Normal file
10
src/controller/emulated/vok00106.rs
Normal file
|
@ -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];
|
||||
}
|
Loading…
Add table
Reference in a new issue