|
1 | 1 | use hidapi::{HidApi, HidDevice, HidError}; |
2 | 2 |
|
3 | 3 | pub const PIX_VID: u16 = 0x093A; |
4 | | -pub const PIX_REPORT_ID: u8 = 0x43; |
| 4 | +pub const P274_REPORT_ID: u8 = 0x43; |
| 5 | +pub const P239_REPORT_ID: u8 = 0x42; |
5 | 6 |
|
6 | | -fn read_byte(device: &HidDevice, addr: u8) -> Result<u8, HidError> { |
7 | | - device.send_feature_report(&[PIX_REPORT_ID, addr, 0x10, 0])?; |
| 7 | +fn read_byte(device: &HidDevice, report_id: u8, addr: u8) -> Result<u8, HidError> { |
| 8 | + device.send_feature_report(&[report_id, addr, 0x10, 0])?; |
8 | 9 |
|
9 | 10 | let mut buf = [0u8; 4]; |
10 | | - buf[0] = PIX_REPORT_ID; |
| 11 | + buf[0] = report_id; |
11 | 12 |
|
12 | 13 | device.get_feature_report(&mut buf)?; |
13 | 14 | Ok(buf[3]) |
14 | 15 | } |
15 | 16 |
|
16 | | -fn read_ver(device: &HidDevice) -> Result<u16, HidError> { |
| 17 | +fn read_239_ver(device: &HidDevice) -> Result<u16, HidError> { |
17 | 18 | Ok(u16::from_le_bytes([ |
18 | | - read_byte(device, 0xb2)?, |
19 | | - read_byte(device, 0xb3)?, |
| 19 | + read_byte(device, P239_REPORT_ID, 0x16)?, |
| 20 | + read_byte(device, P239_REPORT_ID, 0x18)?, |
| 21 | + ])) |
| 22 | +} |
| 23 | + |
| 24 | +fn read_274_ver(device: &HidDevice) -> Result<u16, HidError> { |
| 25 | + Ok(u16::from_le_bytes([ |
| 26 | + read_byte(device, P274_REPORT_ID, 0xb2)?, |
| 27 | + read_byte(device, P274_REPORT_ID, 0xb3)?, |
20 | 28 | ])) |
21 | 29 | } |
22 | 30 |
|
@@ -50,7 +58,13 @@ pub fn print_touchpad_fw_ver() -> Result<(), HidError> { |
50 | 58 |
|
51 | 59 | println!("Touchpad"); |
52 | 60 | println!(" IC Type: {:04X}", pid); |
53 | | - println!(" Firmware Version: v{:04X}", read_ver(&device)?); |
| 61 | + let ver = match pid { |
| 62 | + 0x0239 => format!("{:04X}", read_239_ver(&device)?), |
| 63 | + 0x0274 => format!("{:04X}", read_274_ver(&device)?), |
| 64 | + _ => "Unsupported".to_string(), |
| 65 | + }; |
| 66 | + println!(" Firmware Version: v{}", ver); |
| 67 | + |
54 | 68 | // If we found one, there's no need to look for more |
55 | 69 | return Ok(()); |
56 | 70 | } |
|
0 commit comments