Skip to content

Commit d1c4971

Browse files
committed
TEENSY: Improve interactive mode
1 parent ab07355 commit d1c4971

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

src/platform/teensy/src/device.cpp

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
#include "lib/maapi.h"
1818
#include "serial.h"
1919

20+
uint32_t serialDataTimer = 0;
21+
2022
//
2123
// setup the Serial device
2224
// Teensy 4.x uses USB serial. Setup is done at startup. Communication
@@ -63,16 +65,26 @@ void dev_trace_line(int lineNo) {
6365
// process events
6466
//
6567
int dev_events(int wait_flag) {
66-
int result;
68+
int result = 0;
69+
6770
if (wait_flag) {
6871
delay(10);
6972
}
70-
// #if INTERACTIVE
71-
// break when new code available
72-
result = Serial.available() > 0 ? -2 : 0;
73-
// #else
74-
// result = 0;
75-
//#endif
73+
74+
if (Serial) {
75+
if (Serial.available()) {
76+
if (serialDataTimer == 0) {
77+
serialDataTimer = millis();
78+
}
79+
if (millis() - serialDataTimer > 1000) {
80+
serialDataTimer = 0;
81+
result = -2; // end program
82+
}
83+
} else {
84+
serialDataTimer = 0;
85+
}
86+
}
87+
7688
yield();
7789
return result;
7890
}

src/platform/teensy/src/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ void interactive_main() {
176176
delay(250);
177177
}
178178

179-
dev_print("Interactive mode - waiting for data...\r\n");
179+
dev_print("\r\n\033[30;47mInteractive mode - waiting for data...\033[0m\r\n");
180180

181181
serial_read();
182182
if (!sbasic_main(SERIAL_SD_BAS)) {

0 commit comments

Comments
 (0)