Skip to content

Commit 97761d0

Browse files
committed
Test addition of dial capability
Signed-off-by: Luke Jones <[email protected]>
1 parent b5f39e0 commit 97761d0

File tree

17 files changed

+280
-5
lines changed

17 files changed

+280
-5
lines changed

rootfs/usr/share/inputplumber/capability_maps/zone_type1.yaml

+37
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,43 @@ mapping:
6767
target_event:
6868
gamepad:
6969
button: RightPaddle1
70+
- name: Left Dial Counter-clockwise
71+
source_events:
72+
- evdev:
73+
event_type: REL
74+
event_code: REL_HWHEEL
75+
value_type: joystick_x
76+
target_event:
77+
keyboard: KeyVolumeDown
78+
- name: Left Dial Clockwise
79+
source_events:
80+
- evdev:
81+
event_type: REL
82+
event_code: REL_HWHEEL
83+
value_type: joystick_x
84+
target_event:
85+
keyboard: KeyVolumeUp
86+
- name: Right Dial Counter-clockwise
87+
source_events:
88+
- evdev:
89+
event_code: REL_WHEEL
90+
event_type: REL
91+
value_type: joystick_x
92+
target_event:
93+
gamepad:
94+
dial:
95+
name: RightStickDial
96+
direction: clockwise
97+
- name: Right Dial Clockwise
98+
source_events:
99+
- evdev:
100+
event_code: REL_WHEEL
101+
event_type: REL
102+
value_type: joystick_x
103+
target_event:
104+
dial:
105+
name: RightStickDial
106+
direction: counter_clockwise
70107

71108
# List of events to filter from the source devices
72109
filtered_events: []

rootfs/usr/share/inputplumber/devices/50-zotac-zone.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ source_devices:
5353
vendor_id: "1ee9"
5454
product_id: "1590"
5555
handler: event*
56+
capability_map_id: zone1
5657
- group: imu
5758
iio:
5859
name: i2c-BMI0160:00

rootfs/usr/share/inputplumber/profiles/default.yaml

+35
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,38 @@ mapping:
4646
target_events:
4747
- gamepad:
4848
button: Screenshot
49+
- name: Left Dial Counter-clockwise
50+
source_event:
51+
gamepad:
52+
dial:
53+
name: LeftStick
54+
direction: counter-clockwise
55+
target_events:
56+
- mouse:
57+
button: "WheelLeft"
58+
- name: Left Dial Clockwise
59+
source_event:
60+
gamepad:
61+
dial:
62+
name: LeftStick
63+
direction: clockwise
64+
target_events:
65+
- mouse:
66+
button: "WheelRight"
67+
- name: Right Dial Counter-clockwise
68+
source_event:
69+
gamepad:
70+
dial:
71+
name: RightStick
72+
direction: counter-clockwise
73+
target_events:
74+
- mouse:
75+
button: "WheelUp"
76+
- name: Right Dial Clockwise
77+
source_event:
78+
dial:
79+
name: RightStick
80+
direction: clockwise
81+
target_events:
82+
- mouse:
83+
button: "WheelDown"

rootfs/usr/share/inputplumber/schema/capability_map_v2.json

+31-2
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,25 @@
186186
}
187187
}
188188
},
189+
"DialCapability": {
190+
"description": "The Dial direction can be used to map clockwise or counter-clockwise turns.",
191+
"type": "object",
192+
"required": [
193+
"name",
194+
"direction"
195+
],
196+
"properties": {
197+
"name": {
198+
"type": "string"
199+
},
200+
"direction": {
201+
"enum": [
202+
"clockwise",
203+
"counter_clockwise"
204+
]
205+
}
206+
}
207+
},
189208
"EvdevConfig": {
190209
"description": "An [EvdevConfig] defines a matching evdev input event",
191210
"type": "object",
@@ -1121,7 +1140,17 @@
11211140
"type": "null"
11221141
}
11231142
]
1124-
}
1143+
},
1144+
"dial": {
1145+
"anyOf": [
1146+
{
1147+
"$ref": "#/definitions/DialCapability"
1148+
},
1149+
{
1150+
"type": "null"
1151+
}
1152+
]
1153+
},
11251154
}
11261155
},
11271156
"GyroCapability": {
@@ -1362,4 +1391,4 @@
13621391
]
13631392
}
13641393
}
1365-
}
1394+
}

rootfs/usr/share/inputplumber/schema/device_profile_v1.json

+29
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,9 @@
421421
"trigger": {
422422
"$ref": "#/definitions/TriggerEvent"
423423
},
424+
"dial": {
425+
"$ref": "#/definitions/DialEvent"
426+
},
424427
"button": {
425428
"type": "string",
426429
"enum": [
@@ -567,6 +570,32 @@
567570
"required": [
568571
"name"
569572
]
573+
},
574+
"DialEvent": {
575+
"title": "DialEvent",
576+
"type": "object",
577+
"description": "Dial or Wheel events such as LeftStick, RightStick, etc.",
578+
"additionalProperties": false,
579+
"properties": {
580+
"name": {
581+
"type": "string",
582+
"enum": [
583+
"LeftStick",
584+
"RightStick"
585+
]
586+
},
587+
"direction": {
588+
"type": "string",
589+
"description": "Optional direction of the axis. Used when converting axis events into button events.",
590+
"enum": [
591+
"clockwise",
592+
"counter-clockwise"
593+
]
594+
}
595+
},
596+
"required": [
597+
"name"
598+
]
570599
}
571600
}
572601
}

src/config/capability_map.rs

+8
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ pub struct GamepadCapability {
218218
pub trigger: Option<TriggerCapability>,
219219
pub gyro: Option<GyroCapability>,
220220
pub accelerometer: Option<AccelerometerCapability>,
221+
pub dial: Option<DialCapability>,
221222
}
222223

223224
#[derive(Debug, Deserialize, Serialize, Clone, JsonSchema, PartialEq)]
@@ -253,6 +254,13 @@ pub struct AccelerometerCapability {
253254
pub axis: Option<String>,
254255
}
255256

257+
#[derive(Debug, Deserialize, Serialize, Clone, JsonSchema, PartialEq)]
258+
#[serde(rename_all = "snake_case")]
259+
pub struct DialCapability {
260+
pub name: String,
261+
pub direction: Option<String>,
262+
}
263+
256264
#[derive(Debug, Deserialize, Serialize, Clone, JsonSchema, PartialEq)]
257265
#[serde(rename_all = "snake_case")]
258266
pub struct MouseCapability {

src/dbus/interface/composite_device.rs

+2
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,7 @@ impl CompositeDeviceInterface {
275275
Gamepad::Trigger(trigger) => format!("Gamepad:Trigger:{}", trigger),
276276
Gamepad::Accelerometer => "Gamepad:Accelerometer".to_string(),
277277
Gamepad::Gyro => "Gamepad:Gyro".to_string(),
278+
Gamepad::Dial(dial) => format!("Gamepad:Dial:{dial}"),
278279
},
279280
Capability::Mouse(mouse) => match mouse {
280281
Mouse::Motion => "Mouse:Motion".to_string(),
@@ -307,6 +308,7 @@ impl CompositeDeviceInterface {
307308
Gamepad::Trigger(trigger) => format!("Gamepad:Trigger:{}", trigger),
308309
Gamepad::Accelerometer => "Gamepad:Accelerometer".to_string(),
309310
Gamepad::Gyro => "Gamepad:Gyro".to_string(),
311+
Gamepad::Dial(dial) => format!("Gamepad:Dial:{dial}"),
310312
},
311313
Capability::Mouse(mouse) => match mouse {
312314
Mouse::Motion => "Mouse:Motion".to_string(),

src/drivers/unified_gamepad/capability.rs

+5
Original file line numberDiff line numberDiff line change
@@ -686,6 +686,11 @@ pub enum InputCapability {
686686
/// Right analog stick force sensor, Steam Deck right stick force
687687
GamepadTriggerRightStickForce = 0x505,
688688

689+
/// Left dial/wheel, Zotac Zone left dial
690+
GamepadDialLeft = 0x550,
691+
/// Right dial/wheel, Zotac Zone right dial
692+
GamepadDialRight = 0x551,
693+
689694
/// Center or main gyro sensor
690695
GamepadGyroCenter = 0x600,
691696
/// Left side gamepad gyro

src/input/capability.rs

+44
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,17 @@ impl From<CapabilityConfig> for Capability {
139139

140140
return Capability::Gamepad(Gamepad::Accelerometer);
141141
}
142+
143+
// Dials/wheels
144+
if let Some(dial_config) = gamepad.dial.as_ref() {
145+
let dial = GamepadDial::from_str(&dial_config.name);
146+
if dial.is_err() {
147+
log::error!("Invalid or unimplemented dial: {}", dial_config.name);
148+
return Capability::NotImplemented;
149+
}
150+
let dial = dial.unwrap();
151+
return Capability::Gamepad(Gamepad::Dial(dial));
152+
}
142153
}
143154

144155
// Keyboard
@@ -251,6 +262,8 @@ pub enum Gamepad {
251262
/// Gyro events measure the angular velocity of a device measured
252263
/// with (x, y, z) values normalized to degrees per second.
253264
Gyro,
265+
/// Dials and wheels
266+
Dial(GamepadDial),
254267
}
255268

256269
impl fmt::Display for Gamepad {
@@ -261,6 +274,7 @@ impl fmt::Display for Gamepad {
261274
Gamepad::Trigger(_) => write!(f, "Trigger"),
262275
Gamepad::Accelerometer => write!(f, "Accelerometer"),
263276
Gamepad::Gyro => write!(f, "Gyro"),
277+
Gamepad::Dial(_) => write!(f, "Dial"),
264278
}
265279
}
266280
}
@@ -284,6 +298,9 @@ impl FromStr for Gamepad {
284298
)?)),
285299
"Accelerometer" => Ok(Gamepad::Accelerometer),
286300
"Gyro" => Ok(Gamepad::Gyro),
301+
"Dial" => Ok(Gamepad::Dial(GamepadDial::from_str(
302+
parts.join(":").as_str(),
303+
)?)),
287304
_ => Err(()),
288305
}
289306
}
@@ -609,6 +626,33 @@ impl FromStr for GamepadTrigger {
609626
}
610627
}
611628

629+
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
630+
pub enum GamepadDial {
631+
LeftStickDial,
632+
RightStickDial,
633+
}
634+
635+
impl fmt::Display for GamepadDial {
636+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
637+
match self {
638+
GamepadDial::LeftStickDial => write!(f, "LeftStickDial"),
639+
GamepadDial::RightStickDial => write!(f, "RightStickDial"),
640+
}
641+
}
642+
}
643+
644+
impl FromStr for GamepadDial {
645+
type Err = ();
646+
647+
fn from_str(s: &str) -> Result<Self, Self::Err> {
648+
match s {
649+
"LeftStickDial" => Ok(GamepadDial::LeftStickDial),
650+
"RightStickDial" => Ok(GamepadDial::RightStickDial),
651+
_ => Err(()),
652+
}
653+
}
654+
}
655+
612656
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
613657
pub enum Keyboard {
614658
Key0,

src/input/composite_device/mod.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -928,7 +928,8 @@ impl CompositeDevice {
928928
Gamepad::Axis(_)
929929
| Gamepad::Trigger(_)
930930
| Gamepad::Accelerometer
931-
| Gamepad::Gyro => {}
931+
| Gamepad::Gyro
932+
| Gamepad::Dial(_) => {}
932933
},
933934
Capability::Mouse(ref t) => match t {
934935
Mouse::Motion => {}

src/input/event/evdev.rs

+9
Original file line numberDiff line numberDiff line change
@@ -573,6 +573,7 @@ fn event_type_from_capability(capability: Capability) -> Option<EventType> {
573573
},
574574
Gamepad::Axis(_) => Some(EventType::ABSOLUTE),
575575
Gamepad::Trigger(_) => Some(EventType::ABSOLUTE),
576+
Gamepad::Dial(_) => Some(EventType::ABSOLUTE),
576577
Gamepad::Accelerometer => None,
577578
Gamepad::Gyro => None,
578579
},
@@ -678,6 +679,14 @@ fn event_codes_from_capability(capability: Capability) -> Vec<u16> {
678679
},
679680
Gamepad::Accelerometer => vec![],
680681
Gamepad::Gyro => vec![],
682+
Gamepad::Dial(dial) => match dial {
683+
crate::input::capability::GamepadDial::LeftStickDial => {
684+
vec![RelativeAxisCode::REL_HWHEEL.0]
685+
}
686+
crate::input::capability::GamepadDial::RightStickDial => {
687+
vec![RelativeAxisCode::REL_WHEEL.0]
688+
}
689+
},
681690
},
682691
Capability::Mouse(mouse) => match mouse {
683692
Mouse::Motion => vec![RelativeAxisCode::REL_X.0, RelativeAxisCode::REL_Y.0],

0 commit comments

Comments
 (0)