@@ -2,15 +2,15 @@ use std::io::prelude::*;
22use std:: io:: { BufReader , Cursor } ;
33use std:: fs:: File ;
44use std:: sync:: { Arc , Mutex } ;
5- use std:: thread;
5+ use std:: { thread} ;
66use std:: time:: { SystemTime , Duration } ;
77use byteorder:: { BigEndian , ReadBytesExt } ;
88use enigo:: * ;
99
10- static MOVE_DIVISOR : f64 = 1638.4 ; // = (x/32768)*20 // smaller -- > faster
10+ static MOVE_DIVISOR : f64 = 1638.4 ; // = (x/32768)*20 // smaller -> faster
1111static CLAMP_THRESHOLD : f64 = 0.04 ;
12-
1312static SCROLL_MUTLIPLIER : f64 = 1.5 ;
13+ static CONTROLLER_NAMEPARTS : [ & ' static str ; 2 ] = [ "gamepad" , "controller" ] ;
1414
1515struct State {
1616 running : bool ,
@@ -22,6 +22,7 @@ struct State {
2222 rz : i16 ,
2323}
2424
25+
2526fn get_gamepad_handler ( ) -> String {
2627 // 1. open device file
2728 // 2. read 2nd line and then evry 10 lines further to get device name. find a name containing 'gamepad' (case insensitive)
@@ -31,8 +32,21 @@ fn get_gamepad_handler() -> String {
3132 let reader = BufReader :: new ( f) ;
3233
3334 let mut lines = reader. lines ( ) ;
34-
35- while !lines. next ( ) . unwrap ( ) . unwrap ( ) . to_lowercase ( ) . contains ( "gamepad" ) {
35+
36+ let mut found_controller = false ;
37+ while !found_controller {
38+ let line = lines. next ( ) ;
39+ if line. is_none ( ) {
40+ println ! ( "No controler found! This could be caused by the controllers name not containing any of the words:" ) ;
41+ println ! ( "{:?}" , CONTROLLER_NAMEPARTS ) ;
42+ std:: process:: exit ( 1 ) ;
43+ }
44+ let controller_name = line. unwrap ( ) . unwrap ( ) . to_lowercase ( ) ;
45+ for name in CONTROLLER_NAMEPARTS {
46+ if controller_name. contains ( name) {
47+ found_controller = true ;
48+ }
49+ }
3650 }
3751
3852 let handlers_line = lines. nth ( 3 ) . unwrap ( ) . unwrap ( ) ;
0 commit comments