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 BufferedSerial SX1276GenericLib OLED_SSD1306 HELIOS_Si7021 NVProperty RadioShuttle-STM32L4 USBDeviceHT
Revision 14:d9340be18c3d, committed 2019-01-25
- Comitter:
- Helmut Tschemernjak
- Date:
- Fri Jan 25 17:16:41 2019 +0100
- Parent:
- 13:3c7a52b11316
- Child:
- 15:42e1def661d8
- Commit message:
- Added ConsoleReadline function for the serial and USB console
Changed in this revision
| main.h | Show annotated file Show diff for this revision Revisions of this file |
| utils.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.h Thu Jan 24 16:10:28 2019 +0100 +++ b/main.h Fri Jan 25 17:16:41 2019 +0100 @@ -39,3 +39,4 @@ extern void dprintf(const char *format, ...) __attribute__((format(printf,1,2))); extern void rprintf(const char *format, ...) __attribute__((format(printf,1,2))); extern void VAprintf(bool timstamp, bool newline, bool printEnabled, const char *format, va_list arg); +extern char *ConsoleReadline(char *buf, int buflen, bool echo);
--- a/utils.cpp Thu Jan 24 16:10:28 2019 +0100
+++ b/utils.cpp Fri Jan 25 17:16:41 2019 +0100
@@ -141,10 +141,62 @@
}
}
+char *ConsoleReadline(char *buf, int buflen, bool echo)
+{
+ int count = 0;
+ memset(buf, 0, buflen);
+
+ if (usb ) {
+ usb->flush();
+ while(usb->readable())
+ usb->getc(); // flush old chars
+
+ while(true) {
+ if (usb->readable()) {
+ int c = usb->getc();
+ if (c == 0 || c == -1 || c == '\r' || c == '\n' || c == 3 || c == 4)
+ break;
+ if (echo) {
+ rprintf("%c", c);
+ usb->flush();
+ }
+
+ buf[count] = c;
+ if (count++ >= buflen-2)
+ break;
+ // dprintf("Got char: '%c'(%d)", c, c);
+ }
+ }
+ }
+ if (ser) {
+ while(ser->readable())
+ ser->getc(); // flush old chars
+
+ while(true) {
+ if (ser->readable()) {
+ int c = ser->getc();
+ if (c == 0 || c == -1 || c == '\r' || c == '\n' || c == 3 || c == 4)
+ break;
+ if (echo)
+ rprintf("%c", c);
+ buf[count] = c;
+ if (count++ >= buflen-2)
+ break;
+ // dprintf("Got char: '%c'(%d)", c, c);
+ }
+ }
+ }
+ if (echo)
+ rprintf("\r\n");
+ if (count)
+ return buf;
+ return NULL;
+}
+
void dump(const char *title, const void *data, int len, bool dwords)
{
- dprintf("dump(\"%s\", 0x%x, %d bytes)", title, data, len);
+ dprintf("dump(\"%s\", 0x%x, %d bytes)", title, (unsigned int)data, len);
int i, j, cnt;
unsigned char *u;