@@ -5,12 +5,21 @@ pub const ILI_PID: u16 = 0x5539;
5
5
pub const USI_BITMAP : u8 = 1 << 1 ;
6
6
pub const MPP_BITMAP : u8 = 1 << 2 ;
7
7
8
- fn send_message ( device : & HidDevice , message_id : u8 , read_len : usize ) -> Result < Vec < u8 > , HidError > {
8
+ fn send_message ( device : & HidDevice , message_id : u8 , read_len : usize , data : Vec < u8 > ) -> Result < Vec < u8 > , HidError > {
9
9
let report_id = 0x03 ;
10
- let write_len = 0x01 ;
11
- let mut msg = vec ! [ report_id, 0xA3 , write_len, read_len as u8 , message_id] ;
10
+ let data_len = data. len ( ) ;
11
+ let mut msg = [ 0u8 ; 0x40 ] ;
12
+ msg[ 0 ] = report_id;
13
+ msg[ 1 ] = 0xA3 ;
14
+ msg[ 2 ] = data_len as u8 ;
15
+ msg[ 3 ] = read_len as u8 ;
16
+ msg[ 4 ] = message_id;
17
+ for ( i, b) in data. into_iter ( ) . enumerate ( ) {
18
+ msg[ 5 + i] = b;
19
+ }
12
20
13
21
// Not sure why, but on Windows we just have to write an output report
22
+ // HidApiError { message: "HidD_SetFeature: (0x00000057) The parameter is incorrect." }
14
23
#[ cfg( target_os = "windows" ) ]
15
24
let send_feature_report = false ;
16
25
#[ cfg( not( target_os = "windows" ) ) ]
@@ -24,16 +33,46 @@ fn send_message(device: &HidDevice, message_id: u8, read_len: usize) -> Result<V
24
33
device. write ( & msg) ?;
25
34
}
26
35
27
- msg. pop ( ) ;
28
- let mut buf: [ u8 ; 255 ] = [ 0 ; 255 ] ;
36
+ use std:: { thread, time} ;
37
+ thread:: sleep ( time:: Duration :: from_millis ( 1000 ) ) ;
38
+
39
+ if read_len == 0 {
40
+ return Ok ( vec ! [ ] ) ;
41
+ }
42
+
43
+ let msg_len = 3 + data_len;
44
+ let mut buf: [ u8 ; 0x40 ] = [ 0 ; 0x40 ] ;
29
45
debug ! ( " Reading" ) ;
30
- device. read ( & mut buf[ ..read_len + msg. len ( ) ] ) ?;
46
+ let mut res = device. read ( & mut buf) ;
47
+ debug ! ( " res: {:?}" , res) ;
31
48
debug ! ( " Read buf: {:X?}" , buf) ;
32
- Ok ( buf[ msg. len ( ) ..msg. len ( ) + read_len] . to_vec ( ) )
49
+ if let Err ( _) = res {
50
+ res = device. read_timeout ( & mut buf[ ..read_len + msg_len] , 100 ) ;
51
+ debug ! ( " res: {:?}" , res) ;
52
+ debug ! ( " Read buf: {:X?}" , buf) ;
53
+ }
54
+ if let Err ( _) = res {
55
+ res = device. read_timeout ( & mut buf[ ..read_len + msg_len] , 100 ) ;
56
+ debug ! ( " res: {:?}" , res) ;
57
+ debug ! ( " Read buf: {:X?}" , buf) ;
58
+ }
59
+ if let Err ( _) = res {
60
+ res = device. read_timeout ( & mut buf[ ..read_len + msg_len] , 100 ) ;
61
+ debug ! ( " res: {:?}" , res) ;
62
+ debug ! ( " Read buf: {:X?}" , buf) ;
63
+ }
64
+ if let Err ( _) = res {
65
+ device. read_timeout ( & mut buf[ ..read_len + msg_len] , 100 ) ?;
66
+ debug ! ( " Read buf: {:X?}" , buf) ;
67
+ }
68
+ Ok ( buf[ msg_len..msg_len + read_len] . to_vec ( ) )
33
69
}
34
70
35
71
fn check_fw_version ( device : & HidDevice ) -> Result < ( ) , HidError > {
36
- let res = send_message ( device, 0x42 , 3 ) ?;
72
+ device. set_blocking_mode ( true ) . unwrap ( ) ;
73
+ send_message ( device, 0xF0 , 0 , vec ! [ 3 , 0 , 0 ] ) . unwrap ( ) ;
74
+
75
+ let res = send_message ( device, 0x42 , 3 , vec ! [ 0 ] ) ?;
37
76
let ver = res
38
77
. iter ( )
39
78
. skip ( 1 )
@@ -42,15 +81,16 @@ fn check_fw_version(device: &HidDevice) -> Result<(), HidError> {
42
81
} ) ;
43
82
// Expecting 06.00.0A
44
83
debug ! ( " Protocol Version: v{}" , ver) ;
84
+ return Ok ( ( ) ) ;
45
85
46
- let res = send_message ( device, 0x40 , 8 ) ?;
86
+ let res = send_message ( device, 0x40 , 8 , vec ! [ 0 ] ) ?;
47
87
let ver = res
48
88
. iter ( )
49
89
. skip ( 1 )
50
90
. fold ( res[ 0 ] . to_string ( ) , |acc, & x| acc + "." + & x. to_string ( ) ) ;
51
91
println ! ( " Firmware Version: v{}" , ver) ;
52
92
53
- let res = send_message ( device, 0x20 , 16 ) ?;
93
+ let res = send_message ( device, 0x20 , 16 , vec ! [ 0 ] ) ?;
54
94
println ! ( " USI Protocol: {:?}" , ( res[ 15 ] & USI_BITMAP ) > 0 ) ;
55
95
println ! ( " MPP Protocol: {:?}" , ( res[ 15 ] & MPP_BITMAP ) > 0 ) ;
56
96
@@ -65,17 +105,16 @@ pub fn print_touchscreen_fw_ver() -> Result<(), HidError> {
65
105
let vid = dev_info. vendor_id ( ) ;
66
106
let pid = dev_info. product_id ( ) ;
67
107
let usage_page = dev_info. usage_page ( ) ;
68
-
108
+ if vid != ILI_VID {
109
+ trace ! ( " Skipping VID:PID. Expected {:04X}:*" , ILI_VID ) ;
110
+ continue ;
111
+ }
69
112
debug ! (
70
113
" Found {:04X}:{:04X} (Usage Page {:04X})" ,
71
114
vid, pid, usage_page
72
115
) ;
73
- if vid != ILI_VID {
74
- debug ! ( " Skipping VID:PID. Expected {:04X}:*" , ILI_VID ) ;
75
- continue ;
76
- }
77
116
if usage_page != 0xFF00 {
78
- debug ! ( " Skipping usage page. Expected {:04X}" , 0xFF00 ) ;
117
+ debug ! ( " Skipping usage page. Expected {:04X}" , 0xFF00 ) ;
79
118
continue ;
80
119
}
81
120
if pid != ILI_PID {
@@ -84,6 +123,7 @@ pub fn print_touchscreen_fw_ver() -> Result<(), HidError> {
84
123
85
124
debug ! ( " Found matching touchscreen HID device" ) ;
86
125
println ! ( "Touchscreen" ) ;
126
+ println ! ( " Path: {:?}" , dev_info. path( ) ) ;
87
127
println ! ( " IC Type: {:04X}" , pid) ;
88
128
89
129
// Unwrapping because if we can enumerate it, we should be able to open it
0 commit comments