extmod/moduos_dupterm: Make mp_uos_dupterm_tx_strn() function reusable.
Function to actually spool output terminal data to dupterm object.
This commit is contained in:
parent
00ee84e1e1
commit
30b7344eb0
@ -27,6 +27,13 @@
|
||||
|
||||
// This file contains cumulative declarations for extmod/ .
|
||||
|
||||
#include <stddef.h>
|
||||
#include "py/runtime.h"
|
||||
|
||||
MP_DECLARE_CONST_FUN_OBJ(mp_uos_dupterm_obj);
|
||||
|
||||
#if MICROPY_PY_OS_DUPTERM
|
||||
void mp_uos_dupterm_tx_strn(const char *str, size_t len);
|
||||
#else
|
||||
#define mp_uos_dupterm_tx_strn(s, l)
|
||||
#endif
|
||||
|
@ -34,6 +34,15 @@
|
||||
|
||||
#if MICROPY_PY_OS_DUPTERM
|
||||
|
||||
void mp_uos_dupterm_tx_strn(const char *str, size_t len) {
|
||||
if (MP_STATE_PORT(term_obj) != MP_OBJ_NULL) {
|
||||
mp_obj_t write_m[3];
|
||||
mp_load_method(MP_STATE_PORT(term_obj), MP_QSTR_write, write_m);
|
||||
write_m[2] = mp_obj_new_bytearray_by_ref(len, (char*)str);
|
||||
mp_call_method_n_kw(1, 0, write_m);
|
||||
}
|
||||
}
|
||||
|
||||
STATIC mp_obj_t mp_uos_dupterm(mp_uint_t n_args, const mp_obj_t *args) {
|
||||
if (n_args == 0) {
|
||||
if (MP_STATE_PORT(term_obj) == MP_OBJ_NULL) {
|
||||
|
@ -45,6 +45,7 @@
|
||||
#include "py/gc.h"
|
||||
#include "py/stackctrl.h"
|
||||
#include "py/mphal.h"
|
||||
#include "extmod/misc.h"
|
||||
#include "genhdr/mpversion.h"
|
||||
#include "input.h"
|
||||
|
||||
@ -61,7 +62,7 @@ long heap_size = 1024*1024 * (sizeof(mp_uint_t) / 4);
|
||||
STATIC void stderr_print_strn(void *env, const char *str, size_t len) {
|
||||
(void)env;
|
||||
ssize_t dummy = write(STDERR_FILENO, str, len);
|
||||
mp_hal_dupterm_tx_strn(str, len);
|
||||
mp_uos_dupterm_tx_strn(str, len);
|
||||
(void)dummy;
|
||||
}
|
||||
|
||||
|
@ -243,13 +243,6 @@ extern const struct _mp_obj_fun_builtin_t mp_builtin_open_obj;
|
||||
|
||||
#define MP_STATE_PORT MP_STATE_VM
|
||||
|
||||
#if MICROPY_PY_OS_DUPTERM
|
||||
#include <stddef.h>
|
||||
void mp_hal_dupterm_tx_strn(const char *str, size_t len);
|
||||
#else
|
||||
#define mp_hal_dupterm_tx_strn(s, l)
|
||||
#endif
|
||||
|
||||
#define MICROPY_PORT_ROOT_POINTERS \
|
||||
const char *readline_hist[50]; \
|
||||
mp_obj_t keyboard_interrupt_obj; \
|
||||
|
@ -32,6 +32,7 @@
|
||||
#include "py/mpstate.h"
|
||||
#include "py/mphal.h"
|
||||
#include "py/runtime.h"
|
||||
#include "extmod/misc.h"
|
||||
|
||||
#ifndef _WIN32
|
||||
#include <signal.h>
|
||||
@ -107,17 +108,6 @@ void mp_hal_stdio_mode_orig(void) {
|
||||
|
||||
#endif
|
||||
|
||||
#if MICROPY_PY_OS_DUPTERM
|
||||
void mp_hal_dupterm_tx_strn(const char *str, size_t len) {
|
||||
if (MP_STATE_PORT(term_obj) != MP_OBJ_NULL) {
|
||||
mp_obj_t write_m[3];
|
||||
mp_load_method(MP_STATE_PORT(term_obj), MP_QSTR_write, write_m);
|
||||
write_m[2] = mp_obj_new_bytearray_by_ref(len, (char*)str);
|
||||
mp_call_method_n_kw(1, 0, write_m);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
int mp_hal_stdin_rx_chr(void) {
|
||||
unsigned char c;
|
||||
#if MICROPY_PY_OS_DUPTERM
|
||||
@ -152,7 +142,7 @@ int mp_hal_stdin_rx_chr(void) {
|
||||
|
||||
void mp_hal_stdout_tx_strn(const char *str, size_t len) {
|
||||
int ret = write(1, str, len);
|
||||
mp_hal_dupterm_tx_strn(str, len);
|
||||
mp_uos_dupterm_tx_strn(str, len);
|
||||
(void)ret; // to suppress compiler warning
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user