-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathdebug_helpers.cpp
More file actions
57 lines (53 loc) · 1.55 KB
/
debug_helpers.cpp
File metadata and controls
57 lines (53 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include "debug_helpers.h"
#ifdef SERIAL_DEBUG
#include "adapter_structs.h"
#include "HardwareSerial.h"
const char *getCommandName(int cmd) {
switch (cmd) {
case CMD_ACKNOWLEDGE:
return "ACK";
case CMD_ANNOUNCE:
return "ANNOUNCE";
case CMD_STATUS:
return "CMD_STATUS";
case CMD_IDENTIFY:
return "CMD_IDENTIFY";
case CMD_POWER_MODE:
return "CMD_POWER_MODE";
case CMD_AUTHENTICATE:
return "CMD_AUTHENTICATE";
case CMD_GUIDE_BTN:
return "CMD_GUIDE_BTN";
case CMD_AUDIO_CONFIG:
return "CMD_AUDIO_CONFIG";
case CMD_RUMBLE:
return "CMD_RUMBLE";
case CMD_LED_MODE:
return "CMD_LED_MODE";
case CMD_SERIAL_NUM:
return "CMD_SERIAL_NUM";
case CMD_INPUT:
return "CMD_INPUT";
case CMD_AUDIO_SAMPLES:
return "CMD_AUDIO_SAMPLES";
default:
return "Unknown CMD";
}
}
void serialPrintHex(const uint8_t *val, const uint8_t &nval) {
SERIAL_DEBUG.print(" [ ");
for (int i = 0; i < nval; i++) {
char buf[8];
snprintf(buf, 8, "%02x, ", val[i]);
SERIAL_DEBUG.print(buf);
}
SERIAL_DEBUG.print(" ] ");
}
void printPacket(const XBPACKET &packet, const char *descriptor) {
SERIAL_DEBUG.print(descriptor);
SERIAL_DEBUG.print(getCommandName(packet.buf.frame.command));
serialPrintHex(packet.buf.buffer, packet.header.length);
SERIAL_DEBUG.print("\r\n");
return;
}
#endif