Replace uartPrintf() with uartPutInteger() and ...HexByte() because WTF everything is broken

This commit is contained in:
Lexi / Zoe 2021-04-17 02:32:28 +02:00
parent 201b1db6a6
commit 07e5b74e83
Signed by: binaryDiv
GPG Key ID: F8D4956E224DA232
3 changed files with 28 additions and 17 deletions

View File

@ -21,7 +21,7 @@ void executeCommand(CommandLine cmdLine) {
} }
else if (strcmp(cmdLine.command, "HELP") == 0) { else if (strcmp(cmdLine.command, "HELP") == 0) {
// HELP command: Print a list of supported commands. // HELP command: Print a list of supported commands.
commandHelp(cmdLine.arg); commandHelp();
} }
else if (strcmp(cmdLine.command, "READ") == 0) { else if (strcmp(cmdLine.command, "READ") == 0) {
// READ command: Takes a hex address range (or single address) as argument, // READ command: Takes a hex address range (or single address) as argument,
@ -123,10 +123,13 @@ void commandRead(char* arg) {
} }
} else { } else {
// Fancy ASCII output // Fancy ASCII output
uartPrintf("<%d>", buffer.bytes); uartPutChar('<');
uartPutInteger(buffer.bytes);
uartPutChar('>');
for (int i = 0; i < buffer.bytes; i++) { for (int i = 0; i < buffer.bytes; i++) {
uartPrintf(" %02X", buffer.data[i]); uartPutChar(' ');
uartPutHexByte(buffer.data[i]);
} }
uartPutLine(NULL); uartPutLine(NULL);
} }
@ -163,8 +166,10 @@ void commandErase() {
void commandTestRead() { void commandTestRead() {
eepromSetReadMode(); eepromSetReadMode();
for (int i = 0x00; i < 0x20; i++) { for (uint8_t i = 0x00; i < 0x20; i++) {
uartPrintf("TESTREAD 0x%02X: ", i); uartPutString("TESTREAD 0x");
uartPutHexByte(i);
uartPutString(": ");
uint8_t byte = eepromReadByte(i); uint8_t byte = eepromReadByte(i);
@ -174,7 +179,9 @@ void commandTestRead() {
uartPutChar('?'); uartPutChar('?');
} }
uartPrintf(" (0x%02X)\n"); uartPutString(" (0x");
uartPutHexByte(byte);
uartPutLine(")");
} }
} }

View File

@ -56,17 +56,18 @@ void uartPutLine(char* data) {
uartPutChar('\n'); uartPutChar('\n');
} }
// Transmit a sprintf formatted string (maximum buffer: 256 bytes!) // Convert an integer to decimal ASCII and transmit
void uartPrintf(const char* format, ...) { void uartPutInteger(int value) {
char outBuffer[256]; char outBuffer[32];
snprintf(outBuffer, 32, "%d", value);
va_list args;
va_start(args, format);
vsprintf(outBuffer, format, args);
uartPutString(outBuffer); uartPutString(outBuffer);
}
va_end(args); // Convert a byte to hexadecimal ASCII and transmit
void uartPutHexByte(uint8_t byte) {
char outBuffer[8];
snprintf(outBuffer, 8, "%02hhX", byte);
uartPutString(outBuffer);
} }
// Receive a single character (blocking) // Receive a single character (blocking)

View File

@ -16,8 +16,11 @@ void uartPutString(char* data);
// Transmit a string followed by a line break // Transmit a string followed by a line break
void uartPutLine(char* data); void uartPutLine(char* data);
// Transmit a sprintf formatted string (maximum buffer: 256 bytes!) // Convert an integer to decimal ASCII and transmit
void uartPrintf(const char* format, ...); void uartPutInteger(int value);
// Convert a byte to hexadecimal ASCII and transmit
void uartPutHexByte(uint8_t byte);
// Read a single character (blocking) // Read a single character (blocking)
unsigned char uartGetChar(); unsigned char uartGetChar();