An example project for the Heltec Turtle LoRa board (STM32L4 and SX1276 chips). The projects is only supported for the Nucleo-L432KC board platform in the mbed online and offline compiler environment. Visit www.radioshuttle.de (choose Turtle board) for instructions. Note that most source files and libraries are open source, however some files especially the RadioShuttle core protocol is copyrighted work. Check header for details.
Dependencies: mbed BufferedSerial SX1276GenericLib OLED_SSD1306 HELIOS_Si7021 NVProperty RadioShuttle-STM32L4 USBDeviceHT
Diff: utils.cpp
- Revision:
- 22:9cca40fcb25e
- Parent:
- 16:c12c85fdfa60
- Child:
- 30:8bc655c9b224
--- a/utils.cpp Mon Feb 04 10:23:01 2019 +0100 +++ b/utils.cpp Wed Feb 06 15:52:20 2019 +0100 @@ -141,68 +141,66 @@ } } -char *ConsoleReadline(char *buf, int buflen, bool echo) +char *ConsoleReadline(char *buf, int buflen, bool echo, int timeout_ms) { int count = 0; memset(buf, 0, buflen); - if (usb ) { + if (usb == NULL && ser == NULL) + return NULL; + + Timer t; + int start = 0; + if (timeout_ms) { + t.start(); + start = t.read_ms(); + } + + 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 (c == '\b' || c == 0x7f) { // backspace - if (count < 1) - continue; - buf[--count] = 0; - if (echo) - rprintf("\b \b"); - usb->flush(); - continue; - } - 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 (c == '\b' || c == 0x7f) { // backspace - if (count < 1) - continue; - buf[--count] = 0; - if (echo) - rprintf("\b \b"); - continue; - } - if (echo) - rprintf("%c", c); - buf[count] = c; - if (count++ >= buflen-2) - break; - // dprintf("Got char: '%c'(%d)", c, c); - } + while(true) { + if (timeout_ms && t.read_ms() - start > timeout_ms) + return NULL; + int c = -2; + if (usb && usb->readable()) + c = usb->getc(); + if (ser && ser->readable()) + c = ser->getc(); + if (c == -2) + continue; + + if (c == 0 || c == -1 || c == '\r' || c == '\n' || c == 3 || c == 4) + break; + if (c == '\b' || c == 0x7f) { // backspace + if (count < 1) + continue; + buf[--count] = 0; + if (echo) + rprintf("\b \b"); + if (usb) + usb->flush(); + continue; } + if (echo) { + rprintf("%c", c); + if (usb) + usb->flush(); + } + + buf[count] = c; + if (count++ >= buflen-2) + break; + // dprintf("Got char: '%c'(%d)", c, c); } + if (echo) rprintf("\r\n"); if (count) @@ -260,6 +258,8 @@ len -= width; u += width; rprintf("\r\n"); + if (ser) + wait_ms(5); // give the serial some time. } rprintf("--\r\n"); } @@ -311,3 +311,10 @@ return pwrSource; } + +void MCUReset(void) +{ + #define AIRCR_VECTKEY_MASK 0x05FA0000 + SCB->AIRCR = AIRCR_VECTKEY_MASK | 0x04; // NVIC_GenerateSystemReset(); +} +