mirror of
https://github.com/marcriera/ddgo-pnp-controller.git
synced 2025-05-15 04:27:04 +02:00
Add button combos
This commit is contained in:
parent
1c7eb05cab
commit
8bd5b463c1
12 changed files with 194 additions and 84 deletions
|
@ -12,7 +12,7 @@ pub const DESCRIPTORS: [u8; 48] = [0x01, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x0
|
|||
0x07, 0x05, 0x81, 0x03, 0x08, 0x00, 0x14];
|
||||
pub const STRINGS: [u8; 16] = [0x02, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00];
|
||||
|
||||
pub const DEVICE_DESCRIPTOR: DeviceDescriptor = DeviceDescriptor{b_device_class: 0x00, b_device_sub_class: 0x0, id_vendor: 0x0AE4, id_product: 0x0101, i_manufacturer: "TAITO", i_product: "Densha de Go! Plug & Play (MTC P4/B2-B7 mode)", i_serial_number: "SOTP-031201"};
|
||||
pub const DEVICE_DESCRIPTOR: DeviceDescriptor = DeviceDescriptor{b_device_class: 0x00, b_device_sub_class: 0x0, id_vendor: 0x0AE4, id_product: 0x0101, bcd_device: 0x0400, i_manufacturer: "TAITO", i_product: "Densha de Go! Plug & Play (MTC P4/B2-B7 mode)", i_serial_number: "SOTP-031201"};
|
||||
|
||||
const POWER_NOTCHES: [u8; 6] = [0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0C];
|
||||
const BRAKE_NOTCHES: [u8; 10] = [0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x02, 0x02, 0x01];
|
||||
|
@ -45,24 +45,42 @@ pub fn update_gadget(state: &mut ControllerState) {
|
|||
handle = BRAKE_NOTCHES[state.brake as usize];
|
||||
}
|
||||
|
||||
// Calculate data for buttons 1
|
||||
// Calculate data for buttons
|
||||
let mut buttons1 = Buttons1::NONE;
|
||||
if state.button_a { buttons1.insert(Buttons1::A) }
|
||||
if state.button_b { buttons1.insert(Buttons1::B) }
|
||||
if state.button_c { buttons1.insert(Buttons1::C) }
|
||||
if state.button_d { buttons1.insert(Buttons1::D) }
|
||||
|
||||
// Calculate data for buttons 2
|
||||
let mut buttons2 = Buttons2::NONE;
|
||||
if state.button_up { buttons2.insert(Buttons2::UP) }
|
||||
if state.button_down { buttons2.insert(Buttons2::DOWN) }
|
||||
if state.button_left { buttons2.insert(Buttons2::LEFT) }
|
||||
if !state.button_select_hold && state.button_select && state.button_a {
|
||||
buttons1.insert(Buttons1::A2);
|
||||
state.combo = true;
|
||||
}
|
||||
if !state.button_select_hold && state.button_select && state.button_d {
|
||||
buttons1.insert(Buttons1::S);
|
||||
state.combo = true;
|
||||
}
|
||||
if !state.button_select_hold && state.button_select && state.button_up {
|
||||
state.reverser = 0x80;
|
||||
state.combo = true;
|
||||
}
|
||||
if !state.button_select_hold && state.button_select && state.button_left {
|
||||
state.reverser = 0x00;
|
||||
state.combo = true;
|
||||
}
|
||||
if !state.button_select_hold && state.button_select && state.button_down {
|
||||
state.reverser = 0x40;
|
||||
state.combo = true;
|
||||
}
|
||||
if !state.combo && state.button_a { buttons1.insert(Buttons1::A) }
|
||||
if state.button_b { buttons1.insert(Buttons1::B) }
|
||||
if !state.combo && state.button_c { buttons1.insert(Buttons1::C) }
|
||||
if state.button_d { buttons1.insert(Buttons1::D) }
|
||||
if !state.combo && state.button_up { buttons2.insert(Buttons2::UP) }
|
||||
if !state.combo && state.button_down { buttons2.insert(Buttons2::DOWN) }
|
||||
if !state.combo && state.button_left { buttons2.insert(Buttons2::LEFT) }
|
||||
if state.button_right { buttons2.insert(Buttons2::RIGHT) }
|
||||
if state.button_start { buttons2.insert(Buttons2::START) }
|
||||
if state.button_select { buttons2.insert(Buttons2::SELECT) }
|
||||
if !state.combo && state.button_select_hold { buttons2.insert(Buttons2::SELECT) }
|
||||
|
||||
// Assemble data and send it to endpoint
|
||||
let data = [0x1, handle, buttons1.bits, buttons2.bits];
|
||||
let data = [0x1, state.reverser + handle, buttons1.bits, buttons2.bits];
|
||||
if let Ok(mut file) = File::create(ENDPOINT1) {
|
||||
file.write(&data).ok();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue