@@ -139,6 +139,17 @@ impl From<CapabilityConfig> for Capability {
139
139
140
140
return Capability :: Gamepad ( Gamepad :: Accelerometer ) ;
141
141
}
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
+ }
142
153
}
143
154
144
155
// Keyboard
@@ -251,6 +262,8 @@ pub enum Gamepad {
251
262
/// Gyro events measure the angular velocity of a device measured
252
263
/// with (x, y, z) values normalized to degrees per second.
253
264
Gyro ,
265
+ /// Dials and wheels
266
+ Dial ( GamepadDial ) ,
254
267
}
255
268
256
269
impl fmt:: Display for Gamepad {
@@ -261,6 +274,7 @@ impl fmt::Display for Gamepad {
261
274
Gamepad :: Trigger ( _) => write ! ( f, "Trigger" ) ,
262
275
Gamepad :: Accelerometer => write ! ( f, "Accelerometer" ) ,
263
276
Gamepad :: Gyro => write ! ( f, "Gyro" ) ,
277
+ Gamepad :: Dial ( _) => write ! ( f, "Dial" ) ,
264
278
}
265
279
}
266
280
}
@@ -284,6 +298,9 @@ impl FromStr for Gamepad {
284
298
) ?) ) ,
285
299
"Accelerometer" => Ok ( Gamepad :: Accelerometer ) ,
286
300
"Gyro" => Ok ( Gamepad :: Gyro ) ,
301
+ "Dial" => Ok ( Gamepad :: Dial ( GamepadDial :: from_str (
302
+ parts. join ( ":" ) . as_str ( ) ,
303
+ ) ?) ) ,
287
304
_ => Err ( ( ) ) ,
288
305
}
289
306
}
@@ -609,6 +626,33 @@ impl FromStr for GamepadTrigger {
609
626
}
610
627
}
611
628
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
+
612
656
#[ derive( Clone , Debug , PartialEq , Eq , Hash ) ]
613
657
pub enum Keyboard {
614
658
Key0 ,
0 commit comments