mirror of
https://github.com/marcriera/ddgo-pnp-controller.git
synced 2025-04-11 06:29:29 +02:00
Finish DGOC-44U data structure
This commit is contained in:
parent
4c18e70ce8
commit
37cd8456d1
2 changed files with 37 additions and 6 deletions
|
@ -4,4 +4,5 @@ version = "0.1.0"
|
|||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
bitflags = "1.3.2"
|
||||
evdev = "0.12.1"
|
||||
|
|
|
@ -1,13 +1,43 @@
|
|||
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];
|
||||
|
||||
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];
|
||||
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;
|
||||
const UP = Self::SELECT.bits | Self::D.bits;
|
||||
const DOWN = Self::SELECT.bits | Self::B.bits;
|
||||
const LEFT = Self::SELECT.bits | Self::A.bits;
|
||||
const RIGHT = Self::SELECT.bits | Self::C.bits;
|
||||
}
|
||||
}
|
||||
|
||||
// Assemble data and send it to gadget
|
||||
let data = [brake, power, 0, 0, 0, 0];
|
||||
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) }
|
||||
if state.button_up { buttons.insert(Buttons::UP) }
|
||||
if state.button_down { buttons.insert(Buttons::DOWN) }
|
||||
if state.button_left { buttons.insert(Buttons::LEFT) }
|
||||
if state.button_right { buttons.insert(Buttons::RIGHT) }
|
||||
|
||||
// Assemble data and send it to gadget
|
||||
let data = [brake, power, 0, buttons.bits, 0, 0];
|
||||
}
|
Loading…
Add table
Reference in a new issue