8000 Merge pull request #3366 from kmatch98/refresh_now · dastels/circuitpython@5d17d64 · GitHub
[go: up one dir, main page]

Skip to content

Commit 5d17d64

Browse files
authored
Merge pull request adafruit#3366 from kmatch98/refresh_now
Update refresh to force immediate redraw with `display.refresh()`
2 parents 786f4ed + d224183 commit 5d17d64

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

shared-bindings/displayio/Display.c

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -215,28 +215,33 @@ STATIC mp_obj_t displayio_display_obj_show(mp_obj_t self_in, mp_obj_t group_in)
215215
}
216216
MP_DEFINE_CONST_FUN_OBJ_2(displayio_display_show_obj, displayio_display_obj_show);
217217

218-
//| def refresh(self, *, target_frames_per_second: int = 60, minimum_frames_per_second: int = 1) -> bool:
218+
//| def refresh(self, *, target_frames_per_second: Optional[int] = None, minimum_frames_per_second: int = 1) -> bool:
219219
//| """When auto refresh is off, waits for the target frame rate and then refreshes the display,
220220
//| returning True. If the call has taken too long since the last refresh call for the given
221221
//| target frame rate, then the refresh returns False immediately without updating the screen to
222222
//| hopefully help getting caught up.
223223
//|
224224
//| If the time since the last successful refresh is 10000 below the minimum frame rate, then an
225-
//| exception will be raised. Set minimum_frames_per_second to 0 to disable.
225+
//| exception will be raised. Set ``minimum_frames_per_second`` to 0 to disable.
226+
//|
227+
//| When auto refresh is off, ``display.refresh()`` or ``display.refresh(target_frames_per_second=None)``
228+
//| will update the display immediately.
226229
//|
227230
//| When auto refresh is on, updates the display immediately. (The display will also update
228231
//| without calls to this.)
229232
//|
230233
//| :param int target_frames_per_second: How many times a second `refresh` should be called and the screen updated.
234+
//| Set to `None` for immediate refresh.
231235
//| :param int minimum_frames_per_second: The minimum number of times the screen should be updated per second."""
232236
//| ...
233237
//|
234238
STATIC mp_obj_t displayio_display_obj_refresh(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
235239
enum { ARG_target_frames_per_second, ARG_minimum_frames_per_second };
236240
static const mp_arg_t allowed_args[] = {
237-
{ 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_const_none} },
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) {
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)
0