|
| 1 | +use hidapi::{HidApi, HidDevice, HidError}; |
| 2 | + |
| 3 | +pub const ILI_VID: u16 = 0x32AC; |
| 4 | +pub const USI_BITMAP: u8 = 1 << 1; |
| 5 | +pub const MPP_BITMAP: u8 = 1 << 2; |
| 6 | + |
| 7 | +fn send_message(device: &HidDevice, message_id: u8, read_len: usize) -> Result<Vec<u8>, HidError> { |
| 8 | + let report_id = 0x03; |
| 9 | + let write_len = 0x01; |
| 10 | + let mut msg = vec![report_id, 0xA3, write_len, read_len as u8, message_id]; |
| 11 | + device |
| 12 | + .send_feature_report(&msg) |
| 13 | + .expect("Failed to unlock device"); |
| 14 | + |
| 15 | + msg.pop(); |
| 16 | + let mut buf: [u8; 255] = [0; 255]; |
| 17 | + device.read(&mut buf[..read_len + msg.len()])?; |
| 18 | + Ok(buf[msg.len()..msg.len() + read_len].to_vec()) |
| 19 | +} |
| 20 | + |
| 21 | +fn check_fw_version(device: &HidDevice) -> Result<(), HidError> { |
| 22 | + println!("Touchscreen"); |
| 23 | + |
| 24 | + let res = send_message(device, 0x40, 8)?; |
| 25 | + let ver = res |
| 26 | + .iter() |
| 27 | + .skip(1) |
| 28 | + .fold(res[0].to_string(), |acc, &x| acc + "." + &x.to_string()); |
| 29 | + println!(" Firmware Version: v{}", ver); |
| 30 | + |
| 31 | + let res = send_message(device, 0x20, 16)?; |
| 32 | + println!(" USI Protocol: {:?}", (res[15] & USI_BITMAP) > 0); |
| 33 | + println!(" MPP Protocol: {:?}", (res[15] & MPP_BITMAP) > 0); |
| 34 | + |
| 35 | + Ok(()) |
| 36 | +} |
| 37 | + |
| 38 | +pub fn print_touchscreen_fw_ver() -> Result<(), HidError> { |
| 39 | + match HidApi::new() { |
| 40 | + Ok(api) => { |
| 41 | + for dev_info in api.device_list() { |
| 42 | + let vid = dev_info.vendor_id(); |
| 43 | + let pid = dev_info.product_id(); |
| 44 | + let usage_page = dev_info.usage_page(); |
| 45 | + |
| 46 | + debug!("Found {:X}:{:X} Usage Page: {}", vid, pid, usage_page); |
| 47 | + if vid != 0x222A || pid != 0x5539 { |
| 48 | + continue; |
| 49 | + } |
| 50 | + if usage_page != 0xFF00 { |
| 51 | + continue; |
| 52 | + } |
| 53 | + |
| 54 | + let device = dev_info.open_device(&api).unwrap(); |
| 55 | + |
| 56 | + // On Windows this value is "Control Interface", probably hijacked by the kernel driver |
| 57 | + debug!( |
| 58 | + " Product String: {}", |
| 59 | + dev_info.product_string().unwrap_or("") |
| 60 | + ); |
| 61 | + |
| 62 | + check_fw_version(&device)?; |
| 63 | + } |
| 64 | + } |
| 65 | + Err(e) => { |
| 66 | + eprintln!("Error: {e}"); |
| 67 | + } |
| 68 | + }; |
| 69 | + |
| 70 | + Ok(()) |
| 71 | +} |
0 commit comments