Update refresh to force immediate redraw with display.refresh() or display.refresh(target_frames_per_second=None), even with auto_refresh=False
This commit is contained in:
parent
e8a29ece23
commit
fc513956be
@ -227,6 +227,9 @@ MP_DEFINE_CONST_FUN_OBJ_2(displayio_display_show_obj, displayio_display_obj_show
|
|||||||
//| When auto refresh is on, updates the display immediately. (The display will also update
|
//| When auto refresh is on, updates the display immediately. (The display will also update
|
||||||
//| without calls to this.)
|
//| without calls to this.)
|
||||||
//|
|
//|
|
||||||
|
//| When auto refresh is off, refresh() or refresh(target_frames_per_second=None) will update
|
||||||
|
//| the display immediately.
|
||||||
|
//|
|
||||||
//| :param int target_frames_per_second: How many times a second `refresh` should be called and the screen updated.
|
//| :param int target_frames_per_second: How many times a second `refresh` should be called and the screen updated.
|
||||||
//| :param int minimum_frames_per_second: The minimum number of times the screen should be updated per second."""
|
//| :param int minimum_frames_per_second: The minimum number of times the screen should be updated per second."""
|
||||||
//| ...
|
//| ...
|
||||||
@ -234,9 +237,11 @@ MP_DEFINE_CONST_FUN_OBJ_2(displayio_display_show_obj, displayio_display_obj_show
|
|||||||
STATIC mp_obj_t displayio_display_obj_refresh(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
STATIC mp_obj_t displayio_display_obj_refresh(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||||
enum { ARG_target_frames_per_second, ARG_minimum_frames_per_second };
|
enum { ARG_target_frames_per_second, ARG_minimum_frames_per_second };
|
||||||
static const mp_arg_t allowed_args[] = {
|
static const mp_arg_t allowed_args[] = {
|
||||||
{ MP_QSTR_target_frames_per_second, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 60} },
|
//{ MP_QSTR_target_frames_per_second, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 60} },
|
||||||
|
{ MP_QSTR_target_frames_per_second, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = MP_OBJ_NEW_SMALL_INT(60)} },
|
||||||
{ MP_QSTR_minimum_frames_per_second, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 1} },
|
{ MP_QSTR_minimum_frames_per_second, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 1} },
|
||||||
};
|
};
|
||||||
|
|
||||||
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
|
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
|
||||||
mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
|
mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
|
||||||
|
|
||||||
@ -246,8 +251,18 @@ STATIC mp_obj_t displayio_display_obj_refresh(size_t n_args, const mp_obj_t *pos
|
|||||||
if (minimum_frames_per_second > 0) {
|
if (minimum_frames_per_second > 0) {
|
||||||
maximum_ms_per_real_frame = 1000 / minimum_frames_per_second;
|
maximum_ms_per_real_frame = 1000 / minimum_frames_per_second;
|
||||||
}
|
}
|
||||||
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));
|
|
||||||
|
uint32_t target_ms_per_frame;
|
||||||
|
if ( (args[ARG_target_frames_per_second].u_obj == mp_const_none) || (n_args == 1) ) { // if None or no arguments
|
||||||
|
target_ms_per_frame = 0xffffffff;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
target_ms_per_frame = 1000 / mp_obj_get_int(args[ARG_target_frames_per_second].u_obj);
|
||||||
|
}
|
||||||
|
|
||||||
|
return mp_obj_new_bool(common_hal_displayio_display_refresh(self, target_ms_per_frame, maximum_ms_per_real_frame));
|
||||||
}
|
}
|
||||||
|
|
||||||
MP_DEFINE_CONST_FUN_OBJ_KW(displayio_display_refresh_obj, 1, displayio_display_obj_refresh);
|
MP_DEFINE_CONST_FUN_OBJ_KW(displayio_display_refresh_obj, 1, displayio_display_obj_refresh);
|
||||||
|
|
||||||
//| auto_refresh: bool
|
//| auto_refresh: bool
|
||||||
|
@ -352,7 +352,7 @@ uint16_t common_hal_displayio_display_get_rotation(displayio_display_obj_t* self
|
|||||||
|
|
||||||
|
|
||||||
bool common_hal_displayio_display_refresh(displayio_display_obj_t* self, uint32_t target_ms_per_frame, uint32_t maximum_ms_per_real_frame) {
|
bool common_hal_displayio_display_refresh(displayio_display_obj_t* self, uint32_t target_ms_per_frame, uint32_t maximum_ms_per_real_frame) {
|
||||||
if (!self->auto_refresh && !self->first_manual_refresh) {
|
if (!self->auto_refresh && !self->first_manual_refresh && (target_ms_per_frame != 0xffffffff) ) {
|
||||||
uint64_t current_time = supervisor_ticks_ms64();
|
uint64_t current_time = supervisor_ticks_ms64();
|
||||||
uint32_t current_ms_since_real_refresh = current_time - self->core.last_refresh;
|
uint32_t current_ms_since_real_refresh = current_time - self->core.last_refresh;
|
||||||
// Test to see if the real frame time is below our minimum.
|
// Test to see if the real frame time is below our minimum.
|
||||||
|
Loading…
Reference in New Issue
Block a user