MCPcopy Create free account
hub / github.com/FrameworkComputer/framework-system / send_message

Method send_message

framework_lib/src/touchscreen.rs:79–119  ·  view source on GitHub ↗
(&self, message_id: u8, read_len: usize, data: Vec<u8>)

Source from the content-addressed store, hash-verified

77 }
78
79 fn send_message(&self, message_id: u8, read_len: usize, data: Vec<u8>) -> Option<Vec<u8>> {
80 let report_id = 0x03;
81 let data_len = data.len();
82 let mut msg = [0u8; 0x40];
83 msg[0] = report_id;
84 msg[1] = 0xA3;
85 msg[2] = data_len as u8;
86 msg[3] = read_len as u8;
87 msg[4] = message_id;
88 for (i, b) in data.into_iter().enumerate() {
89 msg[5 + i] = b;
90 }
91
92 // Not sure why, but on Windows we just have to write an output report
93 // HidApiError { message: "HidD_SetFeature: (0x00000057) The parameter is incorrect." }
94 // Still doesn't work on Windows. Need to write a byte more than the buffer is long
95 #[cfg(target_os = "windows")]
96 let send_feature_report = false;
97 #[cfg(not(target_os = "windows"))]
98 let send_feature_report = true;
99
100 if send_feature_report {
101 debug!(" send_feature_report {:X?}", msg);
102 self.device.send_feature_report(&msg).ok()?;
103 } else {
104 debug!(" Writing {:X?}", msg);
105 self.device.write(&msg).ok()?;
106 };
107
108 if read_len == 0 {
109 return Some(vec![]);
110 }
111
112 let msg_len = 3 + data_len;
113 let mut buf: [u8; 0x40] = [0; 0x40];
114 debug!(" Reading");
115 let res = self.device.read(&mut buf);
116 debug!(" res: {:?}", res);
117 debug!(" Read buf: {:X?}", buf);
118 Some(buf[msg_len..msg_len + read_len].to_vec())
119 }
120
121 fn get_battery_status(&self) -> Option<u8> {
122 let mut msg = [0u8; 0x40];

Callers 2

check_fw_versionMethod · 0.45
enable_touchMethod · 0.45

Calls 2

writeMethod · 0.80
readMethod · 0.80

Tested by

no test coverage detected