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
Revision 22:9cca40fcb25e, committed 2019-02-06
- Comitter:
- Helmut Tschemernjak
- Date:
- Wed Feb 06 15:52:20 2019 +0100
- Parent:
- 21:7919e6a7e639
- Child:
- 23:7e647d2a7a25
- Commit message:
- Added a ConsoleReadline timeout feature
Added a little cmd line option for main
Changed in this revision
--- a/main.cpp Mon Feb 04 10:23:01 2019 +0100
+++ b/main.cpp Wed Feb 06 15:52:20 2019 +0100
@@ -49,9 +49,35 @@
dprintf("Welcome to RadioShuttle v%d.%d", RS_MAJOR, RS_MINOR);
dprintf("Voltage: %.2f (%s powered)", BatteryVoltage(), BatterySource());
+ char buf[32];
+
+ bool cmdLoop = true;
+ while(cmdLoop) {
+ rprintf("\r\nAvailable commands (p = Property Editor, r = Reset, q = Quit)\r\nwaiting 10 secs ...\r\n");
+ rprintf("\r\n$ ");
+ if (ConsoleReadline(buf, sizeof(buf), true, 10000) == NULL) {
+ cmdLoop = false;
+ break;
+ }
+ switch(buf[0]) {
+ case 'p':
+ case 'P':
#ifdef FEATURE_NVPROPERTYEDITOR
- // NVPropertyEditor();
+ NVPropertyEditor();
#endif
+ break;
+ case 'q':
+ case 'Q':
+ cmdLoop = false;
+ break;
+ case 'r':
+ case 'R':
+ MCUReset();
+ break;
+ default:
+ break;
+ }
+ }
#ifdef FEATURE_LORA
InitRadio();
--- a/main.h Mon Feb 04 10:23:01 2019 +0100 +++ b/main.h Wed Feb 06 15:52:20 2019 +0100 @@ -39,6 +39,7 @@ 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); +extern char *ConsoleReadline(char *buf, int buflen, bool echo, int timeout_ms = 0); extern void NVPropertyEditor(void); +extern void MCUReset(void);
--- 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();
+}
+
Helmut Tschemernjak