8000 Update refresh to force immediate redraw with display.refresh() or di… · dastels/circuitpython@fc51395 · GitHub
[go: up one dir, main page]

Skip to content

Commit fc51395

Browse files
committed
Update refresh to force immediate redraw with display.refresh() or display.refresh(target_frames_per_second=None), even with auto_refresh=False
1 parent e8a29ec commit fc51395

File tree

2 files changed

+18
-3
lines changed
< 8000 div class="d-flex flex-items-center flex-justify-between gap-2 pt-3 pt-lg-4 pb-2 position-sticky top-0 color-bg-default" style="z-index:2">

2 files changed

+18
-3
lines changed

shared-bindings/displayio/Display.c

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,16 +227,21 @@ MP_DEFINE_CONST_FUN_OBJ_2(displayio_display_show_obj, displayio_display_obj_show
227227
//| When auto refresh is on, updates the display immediately. (The display will also update
228228
//| without calls to this.)
229229
//|
230+
//| When auto refresh is off, refresh() or refresh(target_frames_per_second=None) will update
231+
//| the display immediately.
232+
//|
230233
//| :param int target_frames_per_second: How many times a second `refresh` should be called and the screen updated.
231234
//| :param int minimum_frames_per_second: The minimum number of times the screen should be updated per second."""
232235
//| ...
233236
//|
234237
STATIC mp_obj_t displayio_display_obj_refresh(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
235238
enum { ARG_target_frames_per_second, ARG_minimum_frames_per_second };
236239
static const mp_arg_t allowed_args[] = {
237-
{ MP_QSTR_target_frames_per_second, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 60} },
240+
//{ MP_QSTR_target_frames_per_second, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 60} },
241+
{ MP_QSTR_target_frames_per_second, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = MP_OBJ_NEW_SMALL_INT(60)} },
238242
{ MP_QSTR_minimum_frames_per_second, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 1} },
239243
};
244+
240245
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
241246
mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
242247

@@ -246,8 +251,18 @@ STATIC mp_obj_t displayio_display_obj_refresh(size_t n_args, const mp_obj_t *pos
246251
if (minimum_frames_per_second > 0) {
247252
maximum_ms_per_real_frame = 1000 / minimum_frames_per_second;
248253
}
249-
return mp_obj_new_bool(common_hal_displayio_display_refresh(self, 1000 / args[ARG_target_frames_per_second].u_int, maximum_ms_per_real_frame));
254+
255+
uint32_t target_ms_per_frame;
256+
if ( (args[ARG_target_frames_per_second].u_obj == mp_const_none) || (n_args == 1) ) { // if None or no arguments
257+
target_ms_per_frame = 0xffffffff;
258+
}
259+
else {
260+
target_ms_per_frame = 1000 / mp_obj_get_int(args[ARG_target_frames_per_second].u_obj);
261+
}
262+
263+
return mp_obj_new_bool(common_hal_displayio_display_refresh(self, target_ms_per_frame, maximum_ms_per_real_frame));
250264
}
265+
251266
MP_DEFINE_CONST_FUN_OBJ_KW(displayio_display_refresh_obj, 1, displayio_display_obj_refresh);
252267

253268
//| auto_refresh: bool

shared-module/displayio/Display.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ uint16_t common_hal_displayio_display_get_rotation(displayio_display_obj_t* self
352352

353353

354354
bool common_hal_displayio_display_refresh(displayio_display_obj_t* self, uint32_t target_ms_per_frame, uint32_t maximum_ms_per_real_frame) {
355-
if (!self->auto_refresh && !self->first_manual_refresh) {
355+
if (!self->auto_refresh && !self->first_manual_refresh && (target_ms_per_frame != 0xffffffff) ) {
356356
uint64_t current_time = supervisor_ticks_ms64();
357357
uint32_t current_ms_since_real_refresh = current_time - self->core.last_refresh;
358358
// Test to see if the real frame time is below our minimum.

0 commit comments

Comments
 (0)
2922
0