diff --git a/ports/windows/windows_mphal.c b/ports/windows/windows_mphal.c index 8ed087358f567..50db47968d79c 100644 --- a/ports/windows/windows_mphal.c +++ b/ports/windows/windows_mphal.c @@ -44,6 +44,7 @@ STATIC void assure_stdin_handle() { } } +#if !MICROPY_HAL_HAS_VT100 STATIC void assure_conout_handle() { if (!con_out) { con_out = CreateFile("CONOUT$", GENERIC_READ | GENERIC_WRITE, @@ -52,6 +53,7 @@ STATIC void assure_conout_handle() { assert(con_out != INVALID_HANDLE_VALUE); } } +#endif void mp_hal_stdio_mode_raw(void) { assure_stdin_handle(); @@ -60,6 +62,9 @@ void mp_hal_stdio_mode_raw(void) { mode &= ~ENABLE_ECHO_INPUT; mode &= ~ENABLE_LINE_INPUT; mode &= ~ENABLE_PROCESSED_INPUT; + #if MICROPY_HAL_HAS_VT100 + mode |= ENABLE_VIRTUAL_TERMINAL_INPUT; + #endif SetConsoleMode(std_in, mode); } @@ -105,6 +110,7 @@ void mp_hal_set_interrupt_char(char c) { } } +#if !MICROPY_HAL_HAS_VT100 void mp_hal_move_cursor_back(uint pos) { if (!pos) { return; @@ -184,8 +190,24 @@ STATIC int esc_seq_chr() { } return 0; } +#endif int mp_hal_stdin_rx_chr(void) { + #if MICROPY_HAL_HAS_VT100 + assure_stdin_handle(); + BOOL read_ok; + DWORD num_read; + char inchar; + LPVOID buf = &inchar; + for (;;) { + read_ok = ReadFile(std_in, buf, 1, &num_read, NULL); + if (!read_ok || !num_read) { + continue; + } else { + return inchar; + } + } + #else // currently processing escape seq? const int ret = esc_seq_chr(); if (ret) { @@ -218,6 +240,7 @@ int mp_hal_stdin_rx_chr(void) { return c; } } + #endif } void mp_hal_stdout_tx_strn(const char *str, size_t len) { diff --git a/ports/windows/windows_mphal.h b/ports/windows/windows_mphal.h index 2b7aab44a0fd4..846d624615108 100644 --- a/ports/windows/windows_mphal.h +++ b/ports/windows/windows_mphal.h @@ -29,8 +29,10 @@ #define MICROPY_HAL_HAS_VT100 (0) +#if !MICROPY_HAL_HAS_VT100 void mp_hal_move_cursor_back(unsigned int pos); void mp_hal_erase_line_from_cursor(unsigned int n_chars_to_erase); +#endif #undef mp_hal_ticks_cpu mp_uint_t mp_hal_ticks_cpu(void);
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies: