@@ -100,29 +100,38 @@ static framebufferio_framebufferdisplay_obj_t *native_display(mp_obj_t display_o
100
100
}
101
101
102
102
//| def refresh(
103
- //| self, *, target_frames_per_second: int = 60, minimum_frames_per_second: int = 1
103
+ //| self,
104
+ //| *,
105
+ //| target_frames_per_second: Optional[int] = None,
106
+ //| minimum_frames_per_second: int = 0
104
107
//| ) -> bool:
105
- //| """When auto refresh is off, waits for the target frame rate and then refreshes the display,
106
- //| returning True. If the call has taken too long since the last refresh call for the given
107
- //| target frame rate, then the refresh returns False immediately without updating the screen to
108
+ //| """When auto_refresh is off, and :py:attr:`target_frames_per_second` is not `None` this waits
109
+ //| for the target frame rate and then refreshes the display,
110
+ //| returning `True`. If the call has taken too long since the last refresh call for the given
111
+ //| target frame rate, then the refresh returns `False` immediately without updating the screen to
108
112
//| hopefully help getting caught up.
109
113
//|
110
114
//| If the time since the last successful refresh is below the minimum frame rate, then an
111
- //| exception will be raised. Set minimum_frames_per_second to 0 to disable .
115
+ //| exception will be raised. The default :py:attr:` minimum_frames_per_second` of 0 disables this behavior .
112
116
//|
113
- //| When auto refresh is on, updates the display immediately. (The display will also update
117
+ //| When auto_refresh is off, and :py:attr:`target_frames_per_second` is `None` this
118
+ //| will update the display immediately.
119
+ //|
120
+ //| When auto_refresh is on, updates the display immediately. (The display will also update
114
121
//| without calls to this.)
115
122
//|
116
- //| :param int target_frames_per_second: How many times a second `refresh` should be called and the screen updated.
123
+ //| :param Optional[int] target_frames_per_second: The target frame rate that :py:func:`refresh` should try to
124
+ //| achieve. Set to `None` for immediate refresh.
117
125
//| :param int minimum_frames_per_second: The minimum number of times the screen should be updated per second.
118
126
//| """
119
127
//| ...
120
128
STATIC mp_obj_t framebufferio_framebufferdisplay_obj_refresh (size_t n_args , const mp_obj_t * pos_args , mp_map_t * kw_args ) {
121
129
enum { ARG_target_frames_per_second , ARG_minimum_frames_per_second };
122
130
static const mp_arg_t allowed_args [] = {
123
- { MP_QSTR_target_frames_per_second , MP_ARG_KW_ONLY | MP_ARG_INT , {.u_int = 60 } },
124
- { MP_QSTR_minimum_frames_per_second , MP_ARG_KW_ONLY | MP_ARG_INT , {.u_int = 1 } },
131
+ { MP_QSTR_target_frames_per_second , MP_ARG_OBJ | MP_ARG_KW_ONLY , {.u_obj = mp_const_none } },
132
+ { MP_QSTR_minimum_frames_per_second , MP_ARG_KW_ONLY | MP_ARG_INT , {.u_int = 0 } },
125
133
};
134
+
126
135
mp_arg_val_t args [MP_ARRAY_SIZE (allowed_args )];
127
136
mp_arg_parse_all (n_args - 1 , pos_args + 1 , kw_args , MP_ARRAY_SIZE (allowed_args ), allowed_args , args );
128
137
@@ -132,7 +141,14 @@ STATIC mp_obj_t framebufferio_framebufferdisplay_obj_refresh(size_t n_args, cons
132
141
if (minimum_frames_per_second > 0 ) {
133
142
maximum_ms_per_real_frame = 1000 / minimum_frames_per_second ;
134
143
}
135
- return mp_obj_new_bool (common_hal_framebufferio_framebufferdisplay_refresh (self , 1000 / args [ARG_target_frames_per_second ].u_int , maximum_ms_per_real_frame ));
144
+
145
+ uint32_t target_ms_per_frame ;
146
+ if (args [ARG_target_frames_per_second ].u_obj == mp_const_none ) {
147
+ target_ms_per_frame = 0xffffffff ;
148
+ } else {
149
+ target_ms_per_frame = 1000 / mp_obj_get_int (args [ARG_target_frames_per_second ].u_obj );
150
+ }
151
+ return mp_obj_new_bool (common_hal_framebufferio_framebufferdisplay_refresh (self , target_ms_per_frame , maximum_ms_per_real_frame ));
136
152
}
137
153
MP_DEFINE_CONST_FUN_OBJ_KW (framebufferio_framebufferdisplay_refresh_obj , 1 , framebufferio_framebufferdisplay_obj_refresh );
138
154
0 commit comments