Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed CANBuffer Watchdog MODSERIAL mbed-rtos xbeeRelay IAP
Fork of SystemManagement by
SerialDiagnostics/SerialDiagnostics.cpp
- Committer:
- martydd3
- Date:
- 2014-10-25
- Revision:
- 19:3a817d2cef11
- Child:
- 20:3dfa7e9461a0
File content as of revision 19:3a817d2cef11:
#include "SerialDiagnostics.h"
// Macros for working with the string
// Add newlines, add it to the working buffer
#define ADD_LINE len+=sprintf(buff+len,"%s\r\n",line);
#define ADD_SPRINTF_LINE padCenter(line,max_charsPerLine-2,temp,' '); len+=sprintf(buff+len,"%s\r\n",line);
// Print to a string buffer, pad to maxLen chars and center it with char pad, str must be null terminated!
void padCenter(char *buff, int LineLen, char *str, char pad) {
int len = strlen(str);
int padL = (LineLen-len)/2; // -1 to save room for the null terminator
for (int i=0; i<padL; i++) buff[i] = pad; // Fill in the left padding chars
strcpy(buff+padL, str);
for (int i = padL+len; i<LineLen; i++) buff[i] = pad; // Fill remaining with padding chars
buff[LineLen-1] = '\0'; // Add null terminator
}
void SerialDiagnostics::thread_serialOut(void const* args){
const int max_charsPerLine = 81; // Max chars per line
const int max_lines = 30; // Max lines that the layout prints out
pc.printf("\033[2J"); // Clear the screen to get rid of reset message
char buff[max_charsPerLine*max_lines]; // Giant string to store the printout
char line[max_charsPerLine]; // String buffer to work with one line at a time
char temp[max_charsPerLine]; // String buffer to sprintf into
while(1){
int len = 0;
len += sprintf(buff+len, "\033[0;0H"); // Home the cursor
padCenter(line, max_charsPerLine-2, "-", '-'); ADD_LINE // Generate a line full of 80 -'s
padCenter(line, max_charsPerLine-2, " Penn Electric Racing - REV0 System Management Module Serial Dashboard ", '-'); ADD_LINE
padCenter(line, max_charsPerLine-2, "-", '-'); ADD_LINE // Generate a line full of 80 -'s
// Write it all at once to output tx buffer
for (int i = 0; i < strlen(buff); i++) {
pc.putc(buff[i]);
}
Thread::wait(100);
}
}
