summaryrefslogtreecommitdiff
path: root/shared-bindings/displayio/Display.c
diff options
context:
space:
mode:
authorScott Shawcroft <scott@tannewt.org>2019-08-23 15:27:21 -0700
committerScott Shawcroft <scott@tannewt.org>2019-08-23 15:27:21 -0700
commit7324b70a7c231a20be971ed81050c8359b87aaab (patch)
tree2c301a419a247aa64c8d3fafab6b4b3bfacf7af0 /shared-bindings/displayio/Display.c
parentb992ca80e77ccd95397ed0f12063c30f6161e08f (diff)
Rework based on Dan's review
Diffstat (limited to 'shared-bindings/displayio/Display.c')
-rw-r--r--shared-bindings/displayio/Display.c24
1 files changed, 17 insertions, 7 deletions
diff --git a/shared-bindings/displayio/Display.c b/shared-bindings/displayio/Display.c
index ded4119ca..1eb1943b8 100644
--- a/shared-bindings/displayio/Display.c
+++ b/shared-bindings/displayio/Display.c
@@ -218,16 +218,22 @@ STATIC mp_obj_t displayio_display_obj_show(mp_obj_t self_in, mp_obj_t group_in)
}
MP_DEFINE_CONST_FUN_OBJ_2(displayio_display_show_obj, displayio_display_obj_show);
-//| .. method:: refresh(*, target_frames_per_second=None, minimum_frames_per_second=1)
+//| .. method:: refresh(*, target_frames_per_second=60, minimum_frames_per_second=1)
//|
-//| When auto refresh is off, waits for the target frame rate and then refreshes the display. If
-//| the call is too late for the given target frame rate, then the refresh returns immediately
-//| without updating the screen to hopefully help getting caught up. If the current frame rate
-//| is below the minimum frame rate, then an exception will be raised.
+//| When auto refresh is off, waits for the target frame rate and then refreshes the display,
+//| returning True. If the call has taken too long since the last refresh call for the given
+//| target frame rate, then the refresh returns False immediately without updating the screen to
+//| hopefully help getting caught up.
+//|
+//| If the time since the last successful refresh is below the minimum frame rate, then an
+//| exception will be raised. Set minimum_frames_per_second to 0 to disable.
//|
//| When auto refresh is on, updates the display immediately. (The display will also update
//| without calls to this.)
//|
+//| :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.
+//|
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 };
static const mp_arg_t allowed_args[] = {
@@ -238,8 +244,12 @@ STATIC mp_obj_t displayio_display_obj_refresh(size_t n_args, const mp_obj_t *pos
mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
displayio_display_obj_t *self = native_display(pos_args[0]);
- common_hal_displayio_display_refresh(self, 1000 / args[ARG_target_frames_per_second].u_int, 1000 / args[ARG_minimum_frames_per_second].u_int);
- return mp_const_none;
+ uint32_t maximum_ms_per_real_frame = 0xffffffff;
+ mp_int_t minimum_frames_per_second = args[ARG_minimum_frames_per_second].u_int;
+ if (minimum_frames_per_second > 0) {
+ 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));
}
MP_DEFINE_CONST_FUN_OBJ_KW(displayio_display_refresh_obj, 1, displayio_display_obj_refresh);