Always clear RX buffer on CTRL-C

Some serial sources clear their RX buffers and others didn't. This
cause CP to skip into the REPL based on characters typed before the
CTRL-C. The serial file transfer code looks for "press any key"
which is skipped in this case.

Fixes https://github.com/circuitpython/web-editor/issues/238
This commit is contained in:
Scott Shawcroft 2024-09-12 13:18:12 -07:00
parent 30d57b1ade
commit b5517cb04b
No known key found for this signature in database
5 changed files with 6 additions and 1 deletions

View file

@ -26,6 +26,7 @@ void bleio_characteristic_buffer_extend(bleio_characteristic_buffer_obj_t *self,
for (uint16_t i = 0; i < len; i++) { for (uint16_t i = 0; i < len; i++) {
if (data[i] == mp_interrupt_char) { if (data[i] == mp_interrupt_char) {
mp_sched_keyboard_interrupt(); mp_sched_keyboard_interrupt();
ringbuf_clear(&self->ringbuf);
} else { } else {
ringbuf_put(&self->ringbuf, data[i]); ringbuf_put(&self->ringbuf, data[i]);
} }

View file

@ -46,6 +46,7 @@ static void _copy_out_of_fifo(void) {
for (size_t i = 0; i < len; ++i) { for (size_t i = 0; i < len; ++i) {
if (rx_buf[i] == mp_interrupt_char) { if (rx_buf[i] == mp_interrupt_char) {
mp_sched_keyboard_interrupt(); mp_sched_keyboard_interrupt();
ringbuf_clear(&ringbuf);
} else { } else {
ringbuf_put(&ringbuf, rx_buf[i]); ringbuf_put(&ringbuf, rx_buf[i]);
} }

View file

@ -29,6 +29,7 @@ static void write_to_ringbuf(bleio_characteristic_buffer_obj_t *self, uint8_t *d
for (uint16_t i = 0; i < len; i++) { for (uint16_t i = 0; i < len; i++) {
if (data[i] == mp_interrupt_char) { if (data[i] == mp_interrupt_char) {
mp_sched_keyboard_interrupt(); mp_sched_keyboard_interrupt();
ringbuf_clear(&self->ringbuf);
} else { } else {
ringbuf_put(&self->ringbuf, data[i]); ringbuf_put(&self->ringbuf, data[i]);
} }

View file

@ -155,8 +155,9 @@ static void send_bufn_core(const char *buf, size_t n) {
for (; n--; buf++) { for (; n--; buf++) {
int code = *buf; int code = *buf;
if (code == mp_interrupt_char) { if (code == mp_interrupt_char) {
ringbuf_clear(&_incoming_ringbuf);
mp_sched_keyboard_interrupt(); mp_sched_keyboard_interrupt();
return; continue;
} }
if (ringbuf_num_empty(&_incoming_ringbuf) == 0) { if (ringbuf_num_empty(&_incoming_ringbuf) == 0) {
// Drop on the floor // Drop on the floor

View file

@ -227,6 +227,7 @@ void websocket_background(void) {
while (ringbuf_num_empty(&_incoming_ringbuf) > 0 && while (ringbuf_num_empty(&_incoming_ringbuf) > 0 &&
_read_next_payload_byte(&c)) { _read_next_payload_byte(&c)) {
if (c == mp_interrupt_char) { if (c == mp_interrupt_char) {
ringbuf_clear(&_incoming_ringbuf);
mp_sched_keyboard_interrupt(); mp_sched_keyboard_interrupt();
continue; continue;
} }