| 189 | } |
| 190 | |
| 191 | pub trait TouchScreen { |
| 192 | fn open_device(usage_page: u16, skip: u8) -> Option<Self> |
| 193 | where |
| 194 | Self: std::marker::Sized; |
| 195 | fn send_message(&self, message_id: u8, read_len: usize, data: Vec<u8>) -> Option<Vec<u8>>; |
| 196 | |
| 197 | fn check_fw_version(&self) -> Option<()> { |
| 198 | println!("Touchscreen"); |
| 199 | |
| 200 | let res = self.send_message(0x42, 3, vec![0])?; |
| 201 | let ver = res |
| 202 | .iter() |
| 203 | .skip(1) |
| 204 | .fold(format!("{:02X}", res[0]), |acc, &x| { |
| 205 | acc + "." + &format!("{:02X}", x) |
| 206 | }); |
| 207 | // Expecting 06.00.0A |
| 208 | debug!(" Protocol Version: v{}", ver); |
| 209 | |
| 210 | let res = self.send_message(0x40, 8, vec![0])?; |
| 211 | let ver = res |
| 212 | .iter() |
| 213 | .skip(1) |
| 214 | .fold(res[0].to_string(), |acc, &x| acc + "." + &x.to_string()); |
| 215 | println!(" Firmware Version: v{}", ver); |
| 216 | |
| 217 | let res = self.send_message(0x20, 16, vec![0])?; |
| 218 | let mut protocols = vec![]; |
| 219 | if (res[15] & USI_BITMAP) > 0 { |
| 220 | protocols.push("USI"); |
| 221 | } |
| 222 | if (res[15] & MPP_BITMAP) > 0 { |
| 223 | protocols.push("MPP"); |
| 224 | } |
| 225 | println!(" Protocols: {}", protocols.join(", ")); |
| 226 | |
| 227 | Some(()) |
| 228 | } |
| 229 | |
| 230 | fn enable_touch(&self, enable: bool) -> Option<()> { |
| 231 | self.send_message(0x38, 0, vec![!enable as u8, 0x00])?; |
| 232 | Some(()) |
| 233 | } |
| 234 | |
| 235 | fn get_stylus_fw(&self) -> Option<()>; |
| 236 | fn get_battery_status(&self) -> Option<u8>; |
| 237 | } |
| 238 | |
| 239 | pub fn get_battery_level() -> Option<u8> { |
| 240 | for skip in 0..5 { |
no outgoing calls
no test coverage detected