diff --git a/ports/sh/main.c b/ports/sh/main.c index 0b2543eae..5e6cbb36c 100644 --- a/ports/sh/main.c +++ b/ports/sh/main.c @@ -18,7 +18,6 @@ #include #include #include -#include #include #include @@ -56,14 +55,12 @@ struct pe_globals { // TODO: Put pe_globals in a header for use by the loop hook in mpconfigport.h widget_shell *pe_shell; +/* Whether a delayed dupdate has been scheduled asynchronously. */ +bool pe_dupdate_scheduled; struct pe_globals PE = { 0 }; -// TODO : make this more clean by putting these globals into pe_globals and -// making this accessible to modules -bool is_refreshed_required = false; - //=== Hook for redirecting stdout/stderr to the shell ===// static ssize_t stdouterr_write(void *data, void const *buf, size_t size) @@ -178,13 +175,17 @@ void pe_enter_graphics_mode(void) PE.shell->widget.update = 0; } -void pe_refresh_graphics(void) +void pe_schedule_dupdate(void) +{ + pe_enter_graphics_mode(); + pe_dupdate_scheduled = true; +} + +void pe_dupdate(void) { - /* refresh graphical output on request by setting - is_refresh_graphics to true */ dupdate(); pe_debug_run_videocapture(); - is_refreshed_required = false; + pe_dupdate_scheduled = false; } void pe_draw(void) @@ -205,8 +206,7 @@ void pe_draw(void) dsubimage(377, 207, &img_modifier_states, 16*icon, 0, 15, 14, DIMAGE_NONE); #endif - dupdate(); - pe_debug_run_videocapture(); + pe_dupdate(); } //=== Application control functions ===// diff --git a/ports/sh/modcasioplot.c b/ports/sh/modcasioplot.c index abda99289..b032afa31 100644 --- a/ports/sh/modcasioplot.c +++ b/ports/sh/modcasioplot.c @@ -12,6 +12,9 @@ #include #include +extern void pe_enter_graphics_mode(void); +extern void pe_dupdate(void); + #ifdef FX9860G extern font_t font_4x4; extern font_t font_4x6; @@ -70,10 +73,8 @@ static mp_obj_t init(void) static mp_obj_t show_screen(void) { - void pe_enter_graphics_mode(void); pe_enter_graphics_mode(); - dupdate(); - pe_debug_run_videocapture(); + pe_dupdate(); return mp_const_none; } diff --git a/ports/sh/modgint.c b/ports/sh/modgint.c index 219d1c0ca..62dedd7e0 100644 --- a/ports/sh/modgint.c +++ b/ports/sh/modgint.c @@ -19,7 +19,8 @@ #include #include -void pe_enter_graphics_mode(void); +extern void pe_enter_graphics_mode(void); +extern void pe_dupdate(void); #define FUN_0(NAME) \ MP_DEFINE_CONST_FUN_OBJ_0(modgint_ ## NAME ## _obj, modgint_ ## NAME) @@ -230,8 +231,7 @@ STATIC mp_obj_t modgint_dclear(mp_obj_t arg1) STATIC mp_obj_t modgint_dupdate(void) { pe_enter_graphics_mode(); - dupdate(); - pe_debug_run_videocapture(); + pe_dupdate(); return mp_const_none; } diff --git a/ports/sh/mpconfigport.h b/ports/sh/mpconfigport.h index 5fcda7f5e..bccb1f03e 100644 --- a/ports/sh/mpconfigport.h +++ b/ports/sh/mpconfigport.h @@ -109,11 +109,11 @@ void pe_after_python_exec( /* Command executed regularly during execution */ extern void pe_draw(void); extern widget_shell *pe_shell; -extern void pe_refresh_graphics(void); -extern bool is_refreshed_required; +extern void pe_dupdate(void); +extern bool pe_dupdate_scheduled; #define MICROPY_VM_HOOK_LOOP \ { if(pe_shell->widget.update) pe_draw(); \ - if(is_refreshed_required) pe_refresh_graphics(); } + if(pe_dupdate_scheduled) pe_dupdate(); } /* extra built in names to add to the global namespace #define MICROPY_PORT_BUILTINS \ diff --git a/ports/sh/numworks/modkandinsky.c b/ports/sh/numworks/modkandinsky.c index 7f57bef68..de0f88617 100644 --- a/ports/sh/numworks/modkandinsky.c +++ b/ports/sh/numworks/modkandinsky.c @@ -15,10 +15,11 @@ #include #include +extern void pe_schedule_dupdate(void); + extern font_t numworks; static bool is_dwindowed; -extern bool is_refreshed_required; #define NW_MAX_X 320 #define NW_MAX_Y 222 @@ -57,7 +58,7 @@ extern bool is_refreshed_required; // There are possibly some others to be listed correctly static int callback(void) { - is_refreshed_required = true; + pe_schedule_dupdate(); return TIMER_CONTINUE; }