MCPcopy Create free account
hub / github.com/Shim06/Anemoia-ESP32 / UartProcessPacket

Function UartProcessPacket

src/controller.cpp:231–253  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

229}
230
231static 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
255static uint8_t UartControllerRead()
256{

Callers 1

UartControllerReadFunction · 0.85

Calls 1

readMethod · 0.45

Tested by

no test coverage detected