(count: usize, buf: &[u8])
| 253 | } |
| 254 | |
| 255 | pub fn parse_command(count: usize, buf: &[u8]) -> Option<Command> { |
| 256 | if let Some(command) = parse_module_command(count, buf) { |
| 257 | return Some(command); |
| 258 | } |
| 259 | |
| 260 | // Parse the generic commands common to all modules |
| 261 | if count >= 3 && buf[0] == 0x32 && buf[1] == 0xAC { |
| 262 | let command = buf[2]; |
| 263 | let arg = if count <= 3 { None } else { Some(buf[3]) }; |
| 264 | |
| 265 | //let mut text: String<64> = String::new(); |
| 266 | //writeln!(&mut text, "Command: {command}, arg: {arg}").unwrap(); |
| 267 | //let _ = serial.write(text.as_bytes()); |
| 268 | match FromPrimitive::from_u8(command) { |
| 269 | Some(CommandVals::Sleep) => Some(if let Some(go_to_sleep) = arg { |
| 270 | Command::Sleep(go_to_sleep == 1) |
| 271 | } else { |
| 272 | Command::IsSleeping |
| 273 | }), |
| 274 | Some(CommandVals::BootloaderReset) => Some(Command::BootloaderReset), |
| 275 | Some(CommandVals::Panic) => Some(Command::Panic), |
| 276 | Some(CommandVals::Version) => Some(Command::Version), |
| 277 | _ => None, //Some(Command::Unknown), |
| 278 | } |
| 279 | } else { |
| 280 | None |
| 281 | } |
| 282 | } |
| 283 | |
| 284 | #[cfg(feature = "ledmatrix")] |
| 285 | pub fn parse_module_command(count: usize, buf: &[u8]) -> Option<Command> { |
no test coverage detected