Skip to content

Commit

Permalink
Filter out unprintables in USB debug example
Browse files Browse the repository at this point in the history
  • Loading branch information
ReservedField committed Oct 24, 2016
1 parent 01ca042 commit e7644c7
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions example/usbdebug/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/

#include <string.h>
#include <ctype.h>
#include <M451Series.h>
#include <Display.h>
#include <Font.h>
Expand All @@ -34,7 +35,7 @@

int main() {
char tmpBuf[9];
uint8_t recvBuf[64], bufPos, i;
uint8_t recvBuf[64], bufPos, i, tmp;
uint16_t readSize;

// The virtual COM port is not initialized by default.
Expand Down Expand Up @@ -67,8 +68,12 @@ int main() {
// Data is available
// We read 1 byte at a time because I'm too lazy
// to write a real ring buffer for this example
readSize = USB_VirtualCOM_Read(recvBuf + bufPos, 1);
bufPos = (bufPos + readSize) % 64;
readSize = USB_VirtualCOM_Read(&tmp, 1);
// Filter out control characters for display
if(readSize && isprint(tmp)) {
recvBuf[bufPos] = tmp;
bufPos = (bufPos + readSize) % 64;
}
}

// Display the received data
Expand Down

0 comments on commit e7644c7

Please sign in to comment.