| 229 | } |
| 230 | |
| 231 | static bool UartProcessPacket(HardwareSerial& port, uint8_t& buttons_state) |
| 232 | { |
| 233 | // a packet is three bytes: START_BYTE, buttons_state, and checksum |
| 234 | // up, down, left, and right pressed at the same time is impossible on a controller, |
| 235 | // so 0b1111000 (0xF0) makes a good start byte since the buttons state byte can |
| 236 | // never be 0xF0 |
| 237 | const uint8_t START_BYTE = 0xF0; |
| 238 | |
| 239 | if (port.available() < 3) return false; |
| 240 | |
| 241 | if (port.read() != START_BYTE) return false; |
| 242 | |
| 243 | if (!port.available()) return false; |
| 244 | uint8_t buttons_state_new = port.read(); |
| 245 | |
| 246 | if (!port.available()) return false; |
| 247 | uint8_t checksum = port.read(); |
| 248 | |
| 249 | if (checksum != buttons_state_new) return false; |
| 250 | |
| 251 | buttons_state = buttons_state_new; |
| 252 | return true; |
| 253 | } |
| 254 | |
| 255 | static uint8_t UartControllerRead() |
| 256 | { |
no test coverage detected