Skip to content

Commit b04c680

Browse files
committed
fix(HardwareSupport): Ensure default capabilities & misc fixes
- Adds (temporary) target device translations for screenshot capability for all target gamepads. Each device uses a different combination, and some devices (steam deck, horipad) need to queue events to avoid issues with input collision. These will be fairly difficult to manage with profiles. This makes them unsuitable for the default profile. - Adds (temporary) target device translations for CenterPad -> RightPad and RightPad -> CenterPad for all target gamepads with touch capabilities. Ensures that any source -> target combination has a working default behavior. Fixes multiple reports of "Dualsense Touchpad doesn't work in InputPlumber" from devices with right pads. As some devices need CenterPad -> RightPad, some need RightPad -> CenterPad, and some need no translations, depending on the target, they are not suitable for the defualt profile. - Fixed touchpad translation for Dualsense source device. It was using normalize_signed when it should have been unsigned. - Reduce poll rate of dualsense target to match the real hardware (250Hz) - Add IMU timestamp to dualsense target. - Fix logic for touch events in Dualsense target. Previously it was assumed that 127 = touching and 128 = released, but it is actually a touch counter that ranged 0-127, and the "off" state for each touch is + 128 of the current counter. - Fix max value for X and Y of the Dualsense (off by 1). - Switch dualsense to use the new pitch/roll/yaw names for gyro events. - Implement new gyro/accel events for Steam Deck, Dualsense, and horipad targets. We should review any remaining source devices for the deprecated Gamepad:Gyrosope|Accelerometer events and update them in another PR to remove the Composite Device direct translations. (This one already got out of hand a bit) - Switch Legion Go 2 driver to use QuickAccess2 instead of Screenshot for one of the new buttons. This will still be Screenshot when using the default capability map. - Change a few debug statements to trace. - Clean up some target device match trees with catch all's to improve readability and reduce nesting in some cases. Signed-off-by: Derek J. Clark <derekjohn.clark@gmail.com>
1 parent 03f6509 commit b04c680

File tree

15 files changed

+410
-258
lines changed

15 files changed

+410
-258
lines changed

src/drivers/dualsense/driver.rs

Lines changed: 8 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
use packed_struct::prelude::*;
2-
use std::{
3-
error::Error,
4-
ffi::CString,
5-
time::{Duration, Instant},
6-
};
2+
use std::{error::Error, ffi::CString, time::Instant};
73

84
use hidapi::HidDevice;
95

@@ -53,8 +49,8 @@ pub const TRIGGER_MAX: f64 = u8::MAX as f64;
5349

5450
// DualSense hardware limits
5551
pub const DS5_ACC_RES_PER_G: u32 = 8192;
56-
pub const DS5_TOUCHPAD_WIDTH: f64 = 1920.0;
57-
pub const DS5_TOUCHPAD_HEIGHT: f64 = 1080.0;
52+
pub const DS5_TOUCHPAD_WIDTH: f64 = 1919.0;
53+
pub const DS5_TOUCHPAD_HEIGHT: f64 = 1079.0;
5854

5955
/// PS5 Dualsense controller driver for reading gamepad input
6056
pub struct Driver {
@@ -400,7 +396,7 @@ impl Driver {
400396
let finger_data_0 = state.touch_data.touch_finger_data[0];
401397
let old_finger_data_0 = old_state.touch_data.touch_finger_data[0];
402398
if finger_data_0 != old_finger_data_0 {
403-
let is_touching = finger_data_0.context != 128; // Set to 128 when not touching
399+
let is_touching = finger_data_0.context <= 127;
404400
self.touch_state[0] = is_touching;
405401
events.push(Event::Axis(AxisEvent::Pad(TouchAxisInput {
406402
index: 0,
@@ -412,7 +408,7 @@ impl Driver {
412408
let finger_data_1 = state.touch_data.touch_finger_data[1];
413409
let old_finger_data_1 = old_state.touch_data.touch_finger_data[1];
414410
if finger_data_1 != old_finger_data_1 {
415-
let is_touching = finger_data_1.context != 128; // Set to 128 when not touching
411+
let is_touching = finger_data_1.context <= 127;
416412
self.touch_state[1] = is_touching;
417413
events.push(Event::Axis(AxisEvent::Pad(TouchAxisInput {
418414
index: 1,
@@ -421,28 +417,6 @@ impl Driver {
421417
y: finger_data_1.get_y(),
422418
})))
423419
}
424-
} else if (self.touch_state[0] || self.touch_state[1])
425-
&& (self.last_touch.elapsed() > Duration::from_millis(200))
426-
{
427-
// Lack of timestamp updates mean that all touches have lifted
428-
if self.touch_state[0] {
429-
self.touch_state[0] = false;
430-
events.push(Event::Axis(AxisEvent::Pad(TouchAxisInput {
431-
index: 0,
432-
is_touching: false,
433-
x: 0,
434-
y: 0,
435-
})));
436-
}
437-
if self.touch_state[1] {
438-
self.touch_state[1] = false;
439-
events.push(Event::Axis(AxisEvent::Pad(TouchAxisInput {
440-
index: 1,
441-
is_touching: false,
442-
x: 0,
443-
y: 0,
444-
})));
445-
}
446420
}
447421

448422
// Accelerometer events
@@ -455,9 +429,9 @@ impl Driver {
455429
)));
456430
events.push(Event::Accelerometer(AccelerometerEvent::Gyro(
457431
AccelerometerInput {
458-
x: state.gyro_x.to_primitive(),
459-
y: state.gyro_y.to_primitive(),
460-
z: state.gyro_z.to_primitive(),
432+
x: state.pitch.to_primitive(),
433+
y: state.yaw.to_primitive(),
434+
z: state.roll.to_primitive(),
461435
},
462436
)));
463437

src/drivers/dualsense/hid_report.rs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -148,11 +148,12 @@ pub struct TouchFingerData {
148148
impl Default for TouchFingerData {
149149
fn default() -> Self {
150150
Self {
151-
context: 128,
152-
x_lo: Default::default(),
153-
y_lo: Default::default(),
154-
x_hi: Default::default(),
155-
y_hi: Default::default(),
151+
// Copied from actual hardware
152+
context: 228,
153+
x_lo: 100,
154+
y_lo: Integer::from_primitive(0),
155+
x_hi: Integer::from_primitive(6),
156+
y_hi: 8,
156157
}
157158
}
158159
}
@@ -277,11 +278,11 @@ pub struct InputState {
277278

278279
// byte 15-26
279280
#[packed_field(bytes = "15..=16", endian = "lsb")]
280-
pub gyro_x: Integer<i16, packed_bits::Bits<16>>, // Gyro
281+
pub pitch: Integer<i16, packed_bits::Bits<16>>, // Gyro
281282
#[packed_field(bytes = "17..=18", endian = "lsb")]
282-
pub gyro_y: Integer<i16, packed_bits::Bits<16>>,
283+
pub yaw: Integer<i16, packed_bits::Bits<16>>,
283284
#[packed_field(bytes = "19..=20", endian = "lsb")]
284-
pub gyro_z: Integer<i16, packed_bits::Bits<16>>,
285+
pub roll: Integer<i16, packed_bits::Bits<16>>,
285286
#[packed_field(bytes = "21..=22", endian = "lsb")]
286287
pub accel_x: Integer<i16, packed_bits::Bits<16>>, // Accelerometer
287288
#[packed_field(bytes = "23..=24", endian = "lsb")]
@@ -392,9 +393,9 @@ impl Default for InputState {
392393
ps: Default::default(),
393394
_unkn_1: Default::default(),
394395
_unkn_counter: Default::default(),
395-
gyro_x: Default::default(),
396-
gyro_y: Default::default(),
397-
gyro_z: Default::default(),
396+
pitch: Default::default(),
397+
yaw: Default::default(),
398+
roll: Default::default(),
398399
accel_x: Default::default(),
399400
accel_y: Default::default(),
400401
accel_z: Default::default(),

src/drivers/dualsense/hid_report_test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ async fn test_ds_hid() -> Result<(), Box<dyn Error>> {
1818
report.touch_data.touch_finger_data[0]
1919
.pack_to_vec()
2020
.unwrap(),
21-
vec![0x80, 0x7F, 0xC7, 0x42]
21+
vec![0xE4, 0x7F, 0xC7, 0x42]
2222
);
2323

2424
Ok(())

src/drivers/horipad_steam/driver.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -295,9 +295,9 @@ impl Driver {
295295
},
296296
)));
297297
events.push(Event::Inertia(InertialEvent::Gyro(InertialInput {
298-
x: -state.gyro_x.to_primitive(),
299-
y: state.gyro_y.to_primitive(),
300-
z: -state.gyro_z.to_primitive(),
298+
x: -state.pitch.to_primitive(),
299+
y: state.yaw.to_primitive(),
300+
z: -state.roll.to_primitive(),
301301
})));
302302

303303
log::trace!("Got events: {events:?}");

src/drivers/horipad_steam/hid_report.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -135,11 +135,11 @@ pub struct PackedInputDataReport {
135135

136136
// bytes 12-17 // Gyro
137137
#[packed_field(bytes = "12..=13", endian = "lsb")]
138-
pub gyro_z: Integer<i16, packed_bits::Bits<16>>,
138+
pub roll: Integer<i16, packed_bits::Bits<16>>,
139139
#[packed_field(bytes = "14..=15", endian = "lsb")]
140-
pub gyro_y: Integer<i16, packed_bits::Bits<16>>,
140+
pub yaw: Integer<i16, packed_bits::Bits<16>>,
141141
#[packed_field(bytes = "16..=17", endian = "lsb")]
142-
pub gyro_x: Integer<i16, packed_bits::Bits<16>>,
142+
pub pitch: Integer<i16, packed_bits::Bits<16>>,
143143
// bytes 18-23 // Accelerometer
144144
#[packed_field(bytes = "18..=19", endian = "lsb")]
145145
pub accel_z: Integer<i16, packed_bits::Bits<16>>,
@@ -187,9 +187,9 @@ impl Default for PackedInputDataReport {
187187
rt_analog: 0,
188188
lt_analog: 0,
189189
tick: Integer::from_primitive(0),
190-
gyro_z: Integer::from_primitive(0),
191-
gyro_y: Integer::from_primitive(0),
192-
gyro_x: Integer::from_primitive(0),
190+
roll: Integer::from_primitive(0),
191+
yaw: Integer::from_primitive(0),
192+
pitch: Integer::from_primitive(0),
193193
accel_z: Integer::from_primitive(0),
194194
accel_y: Integer::from_primitive(0),
195195
accel_x: Integer::from_primitive(0),

src/drivers/lego/driver.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -517,8 +517,8 @@ impl Driver {
517517

518518
// If this is the first event of a new touch, log the time.
519519
if !self.touch_started {
520-
log::debug!("START Touch");
521-
log::debug!("Last touch elapsed: {:?}", self.last_touch.elapsed());
520+
log::trace!("START Touch");
521+
log::trace!("Last touch elapsed: {:?}", self.last_touch.elapsed());
522522

523523
self.touch_started = true;
524524
self.first_touch = Instant::now();
@@ -530,7 +530,7 @@ impl Driver {
530530
{
531531
// Handle double click
532532
if self.is_clicked && self.first_touch.elapsed() < RELEASE_DELAY {
533-
log::debug!("Double Click");
533+
log::trace!("Double Click");
534534
let mut new_events = self.release_click();
535535
events.append(&mut new_events);
536536
}
@@ -547,7 +547,7 @@ impl Driver {
547547
// Clear this touch sequence
548548
if self.touch_started {
549549
self.touch_started = false;
550-
log::debug!("END Touch");
550+
log::trace!("END Touch");
551551
}
552552
}
553553

@@ -565,12 +565,12 @@ impl Driver {
565565

566566
fn start_click(&mut self) -> Vec<Event> {
567567
if self.is_clicked {
568-
log::debug!("Rejecting extra click");
568+
log::trace!("Rejecting extra click");
569569
return vec![];
570570
}
571-
log::debug!("Started CLICK event.");
572-
log::debug!("First touch elapsed: {:?}", self.first_touch.elapsed());
573-
log::debug!("Last touch elapsed: {:?}", self.last_touch.elapsed());
571+
log::trace!("Started CLICK event.");
572+
log::trace!("First touch elapsed: {:?}", self.first_touch.elapsed());
573+
log::trace!("Last touch elapsed: {:?}", self.last_touch.elapsed());
574574
self.is_clicked = true;
575575
let mut events = Vec::new();
576576

@@ -587,9 +587,9 @@ impl Driver {
587587
}
588588

589589
fn release_click(&mut self) -> Vec<Event> {
590-
log::debug!("Released CLICK event.");
591-
log::debug!("First touch elapsed: {:?}", self.first_touch.elapsed());
592-
log::debug!("Last touch elapsed: {:?}", self.last_touch.elapsed());
590+
log::trace!("Released CLICK event.");
591+
log::trace!("First touch elapsed: {:?}", self.first_touch.elapsed());
592+
log::trace!("Last touch elapsed: {:?}", self.last_touch.elapsed());
593593
self.is_clicked = false;
594594
self.touch_started = false;
595595
let mut events = Vec::new();

src/input/source/hidraw/dualsense.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -377,14 +377,13 @@ fn translate_event(event: dualsense::event::Event) -> NativeEvent {
377377
fn normalize_axis_value(event: &dualsense::event::AxisEvent) -> InputValue {
378378
match event {
379379
dualsense::event::AxisEvent::Pad(value) => {
380-
let min = 0.0;
381380
let max = dualsense::driver::DS5_TOUCHPAD_WIDTH;
382-
let x = normalize_signed_value(value.x as f64, min, max);
381+
382+
let x = normalize_unsigned_value(value.x as f64, max);
383383
let x = Some(x);
384384

385-
let min = 0.0;
386385
let max = dualsense::driver::DS5_TOUCHPAD_HEIGHT;
387-
let y = normalize_signed_value(value.y as f64, min, max);
386+
let y = normalize_unsigned_value(value.y as f64, max);
388387
let y = Some(y);
389388

390389
InputValue::Touch {

src/input/source/hidraw/legion_go.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ impl LegionGoController {
158158
InputValue::Bool(value.pressed),
159159
),
160160
event::GamepadButtonEvent::AltTab(value) => NativeEvent::new(
161-
Capability::Gamepad(Gamepad::Button(GamepadButton::Screenshot)),
161+
Capability::Gamepad(Gamepad::Button(GamepadButton::QuickAccess2)),
162162
InputValue::Bool(value.pressed),
163163
),
164164
},
@@ -379,14 +379,14 @@ pub const CAPABILITIES: &[Capability] = &[
379379
Capability::Gamepad(Gamepad::Button(GamepadButton::LeftTrigger)),
380380
Capability::Gamepad(Gamepad::Button(GamepadButton::North)),
381381
Capability::Gamepad(Gamepad::Button(GamepadButton::QuickAccess)),
382+
Capability::Gamepad(Gamepad::Button(GamepadButton::QuickAccess2)),
382383
Capability::Gamepad(Gamepad::Button(GamepadButton::RightBumper)),
383384
Capability::Gamepad(Gamepad::Button(GamepadButton::RightPaddle1)),
384385
Capability::Gamepad(Gamepad::Button(GamepadButton::RightPaddle2)),
385386
Capability::Gamepad(Gamepad::Button(GamepadButton::RightPaddle3)),
386387
Capability::Gamepad(Gamepad::Button(GamepadButton::RightStick)),
387388
Capability::Gamepad(Gamepad::Button(GamepadButton::RightStickTouch)),
388389
Capability::Gamepad(Gamepad::Button(GamepadButton::RightTrigger)),
389-
Capability::Gamepad(Gamepad::Button(GamepadButton::Screenshot)),
390390
Capability::Gamepad(Gamepad::Button(GamepadButton::Select)),
391391
Capability::Gamepad(Gamepad::Button(GamepadButton::South)),
392392
Capability::Gamepad(Gamepad::Button(GamepadButton::Start)),

0 commit comments

Comments
 (0)