-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathdebug_print.cpp
More file actions
43 lines (35 loc) · 752 Bytes
/
debug_print.cpp
File metadata and controls
43 lines (35 loc) · 752 Bytes
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
#include "debug_print.h"
#include <Arduino.h>
char gHexCharacter[] = {
'0', '1', '2', '3',
'4', '5', '6', '7',
'8', '9', 'A', 'B',
'C', 'D', 'E', 'F',
};
void printHex(uint8_t value) {
Serial.write(gHexCharacter[value >> 4]);
Serial.write(gHexCharacter[value & 0xF]);
}
void printBinary(uint8_t value) {
for (uint8_t i = 0; i < 8; ++i) {
if (value & 0x80) {
Serial.write('1');
} else {
Serial.write('0');
}
value <<= 1;
}
}
void debugPrintBuffer(uint8_t* data, uint8_t bytes) {
for (uint8_t i = 0; i < bytes; ++i) {
printHex(data[i]);
if ((i & 0x7) == 0x7) {
Serial.write('\n');
} else {
Serial.write(' ');
}
}
if ((bytes & 0x7) != 0) {
Serial.write('\n');
}
}