Reads all possible input from Stream Deck device
(&self, timeout: Option<Duration>)
| 193 | |
| 194 | /// Reads all possible input from Stream Deck device |
| 195 | pub fn read_input(&self, timeout: Option<Duration>) -> Result<StreamDeckInput, StreamDeckError> { |
| 196 | match &self.kind { |
| 197 | Kind::Plus | Kind::PlusXl => { |
| 198 | let data = read_data(&self.device, (6 + self.kind.key_count()).max(5 + self.kind.encoder_count()) as usize, timeout)?; |
| 199 | |
| 200 | if data[0] == 0 { |
| 201 | return Ok(StreamDeckInput::NoData); |
| 202 | } |
| 203 | |
| 204 | match &data[1] { |
| 205 | 0x0 => Ok(StreamDeckInput::ButtonStateChange(read_button_states(&self.kind, &data))), |
| 206 | |
| 207 | 0x2 => Ok(read_lcd_input(&data)?), |
| 208 | |
| 209 | 0x3 => Ok(read_encoder_input(&self.kind, &data)?), |
| 210 | |
| 211 | _ => Err(StreamDeckError::BadData), |
| 212 | } |
| 213 | } |
| 214 | |
| 215 | _ => { |
| 216 | let data = match self.kind { |
| 217 | Kind::Original | Kind::Mini | Kind::MiniMk2 | Kind::MiniDiscord | Kind::MiniMk2Module => read_data(&self.device, 1 + self.kind.key_count() as usize, timeout), |
| 218 | _ => read_data(&self.device, 4 + self.kind.key_count() as usize + self.kind.touchpoint_count() as usize, timeout), |
| 219 | }?; |
| 220 | |
| 221 | if data[0] == 0 { |
| 222 | return Ok(StreamDeckInput::NoData); |
| 223 | } |
| 224 | |
| 225 | Ok(StreamDeckInput::ButtonStateChange(read_button_states(&self.kind, &data))) |
| 226 | } |
| 227 | } |
| 228 | } |
| 229 | |
| 230 | /// Resets the device |
| 231 | pub fn reset(&self) -> Result<(), StreamDeckError> { |
no test coverage detected