51
51
//| Most people should not use this class directly. Use a specific display driver instead that will
52
52
//| contain the startup and shutdown sequences at minimum.
53
53
//|
54
- //| .. class:: EPaperDisplay(display_bus, start_sequence, stop_sequence, *, width, height, ram_width, ram_height, colstart=0, rowstart=0, rotation=0, set_column_window_command=None, set_row_window_command=None, single_byte_bounds=False, write_black_ram_command, black_bits_inverted=False, write_color_ram_command=None, color_bits_inverted=False, refresh_display_command, busy_pin=None, busy_state=True, seconds_per_frame=180, always_toggle_chip_select=False)
54
+ //| .. class:: EPaperDisplay(display_bus, start_sequence, stop_sequence, *, width, height, ram_width, ram_height, colstart=0, rowstart=0, rotation=0, set_column_window_command=None, set_row_window_command=None, single_byte_bounds=False, write_black_ram_command, black_bits_inverted=False, write_color_ram_command=None, color_bits_inverted=False, highlight_color=0x000000, refresh_display_command, busy_pin=None, busy_state=True, seconds_per_frame=180, always_toggle_chip_select=False)
55
55
//|
56
56
//| Create a EPaperDisplay object on the given display bus (`displayio.FourWire` or `displayio.ParallelBus`).
57
57
//|
81
81
//| :param bool black_bits_inverted: True if 0 bits are used to show black pixels. Otherwise, 1 means to show black.
82
82
//| :param int write_color_ram_command: Command used to write pixels values into the update region
83
83
//| :param bool color_bits_inverted: True if 0 bits are used to show the color. Otherwise, 1 means to show color.
84
- //| :param int third_color: Color of third ePaper color in RGB888 .
84
+ //| :param int highlight_color: RGB888 of source color to highlight with third ePaper color.
85
85
//| :param int refresh_display_command: Command used to start a display refresh
86
86
//| :param microcontroller.Pin busy_pin: Pin used to signify the display is busy
87
87
//| :param bool busy_state: State of the busy pin when the display is busy
88
88
//| :param int seconds_per_frame: Minimum number of seconds between screen refreshes
89
89
//| :param bool always_toggle_chip_select: When True, chip select is toggled every byte
90
90
//|
91
91
STATIC mp_obj_t displayio_epaperdisplay_make_new (const mp_obj_type_t * type , size_t n_args , const mp_obj_t * pos_args , mp_map_t * kw_args ) {
92
- enum { ARG_display_bus , ARG_start_sequence , ARG_stop_sequence , ARG_width , ARG_height , ARG_ram_width , ARG_ram_height , ARG_colstart , ARG_rowstart , ARG_rotation , ARG_set_column_window_command , ARG_set_row_window_command , ARG_set_current_column_command , ARG_set_current_row_command , ARG_write_black_ram_command , ARG_black_bits_inverted , ARG_write_color_ram_command , ARG_color_bits_inverted , ARG_third_color , ARG_refresh_display_command , ARG_busy_pin , ARG_busy_state , ARG_seconds_per_frame , ARG_always_toggle_chip_select };
92
+ enum { ARG_display_bus , ARG_start_sequence , ARG_stop_sequence , ARG_width , ARG_height , ARG_ram_width , ARG_ram_height , ARG_colstart , ARG_rowstart , ARG_rotation , ARG_set_column_window_command , ARG_set_row_window_command , ARG_set_current_column_command , ARG_set_current_row_command , ARG_write_black_ram_command , ARG_black_bits_inverted , ARG_write_color_ram_command , ARG_color_bits_inverted , ARG_highlight_color , ARG_refresh_display_command , ARG_busy_pin , ARG_busy_state , ARG_seconds_per_frame , ARG_always_toggle_chip_select };
93
93
static const mp_arg_t allowed_args [] = {
94
94
{ MP_QSTR_display_bus , MP_ARG_REQUIRED | MP_ARG_OBJ },
95
95
{ MP_QSTR_start_sequence , MP_ARG_REQUIRED | MP_ARG_OBJ },
@@ -109,7 +109,7 @@ STATIC mp_obj_t displayio_epaperdisplay_make_new(const mp_obj_type_t *type, size
109
109
{ MP_QSTR_black_bits_inverted , MP_ARG_BOOL | MP_ARG_KW_ONLY , {.u_bool = false} },
110
110
{ MP_QSTR_write_color_ram_command , MP_ARG_OBJ | MP_ARG_KW_ONLY , {.u_obj = mp_const_none } },
111
111
{ MP_QSTR_color_bits_inverted , MP_ARG_BOOL | MP_ARG_KW_ONLY , {.u_bool = false} },
112
- { MP_QSTR_third_color , MP_ARG_INT | MP_ARG_KW_ONLY , {.u_int = 0x000000 } },
112
+ { MP_QSTR_highlight_color , MP_ARG_INT | MP_ARG_KW_ONLY , {.u_int = 0x000000 } },
113
113
{ MP_QSTR_refresh_display_command , MP_ARG_INT | MP_ARG_REQUIRED },
114
114
{ MP_QSTR_busy_pin , MP_ARG_OBJ | MP_ARG_KW_ONLY , {.u_obj = mp_const_none } },
115
115
{ MP_QSTR_busy_state , MP_ARG_BOOL | MP_ARG_KW_ONLY , {.u_bool = true} },
@@ -155,7 +155,7 @@ STATIC mp_obj_t displayio_epaperdisplay_make_new(const mp_obj_type_t *type, size
155
155
mp_float_t seconds_per_frame = mp_obj_get_float (args [ARG_seconds_per_frame ].u_obj );
156
156
157
157
mp_int_t write_color_ram_command = NO_COMMAND ;
158
- mp_int_t third_color = args [ARG_third_color ].u_int ;
158
+ mp_int_t highlight_color = args [ARG_highlight_color ].u_int ;
159
159
if (args [ARG_write_color_ram_command ].u_obj != mp_const_none ) {
160
160
write_color_ram_command = mp_obj_get_int (args [ARG_write_color_ram_command ].u_obj );
161
161
}
@@ -168,7 +168,7 @@ STATIC mp_obj_t displayio_epaperdisplay_make_new(const mp_obj_type_t *type, size
168
168
args [ARG_width ].u_int , args [ARG_height ].u_int , args [ARG_ram_width ].u_int , args [ARG_ram_height ].u_int , args [ARG_colstart ].u_int , args [ARG_rowstart ].u_int , rotation ,
169
169
args [ARG_set_column_window_command ].u_int , args [ARG_set_row_window_command ].u_int ,
170
170
args [ARG_set_current_column_command ].u_int , args [ARG_set_current_row_command ].u_int ,
171
- args [ARG_write_black_ram_command ].u_int , args [ARG_black_bits_inverted ].u_bool , write_color_ram_command , args [ARG_color_bits_inverted ].u_bool , third_color , args [ARG_refresh_display_command ].u_int ,
171
+ args [ARG_write_black_ram_command ].u_int , args [ARG_black_bits_inverted ].u_bool , write_color_ram_command , args [ARG_color_bits_inverted ].u_bool , highlight_color , args [ARG_refresh_display_command ].u_int ,
172
172
busy_pin , args [ARG_busy_state ].u_bool , seconds_per_frame , args [ARG_always_toggle_chip_select ].u_bool
173
173
);
174
174
@@ -203,27 +203,38 @@ STATIC mp_obj_t displayio_epaperdisplay_obj_show(mp_obj_t self_in, mp_obj_t grou
203
203
}
204
204
MP_DEFINE_CONST_FUN_OBJ_2 (displayio_epaperdisplay_show_obj , displayio_epaperdisplay_obj_show );
205
205
206
- //| .. method:: refresh_soon ()
206
+ //| .. method:: refresh ()
207
207
//|
208
- //| Queues up a display refresh that happens in the background.
208
+ //| Refreshes the display immediately or raises an exception if too soon. Use
209
+ //| ``time.sleep(display.time_to_refresh)`` to sleep until a refresh can occur.
209
210
//|
210
211
STATIC mp_obj_t displayio_epaperdisplay_obj_refresh_soon (mp_obj_t self_in ) {
211
212
displayio_epaperdisplay_obj_t * self = native_display (self_in );
212
- common_hal_displayio_epaperdisplay_refresh_soon (self );
213
+ bool ok = common_hal_displayio_epaperdisplay_refresh (self );
214
+ if (!ok ) {
215
+ mp_raise_RuntimeError (translate ("Refresh too soon" ));
216
+ }
213
217
return mp_const_none ;
214
218
}
215
219
MP_DEFINE_CONST_FUN_OBJ_1 (displayio_epaperdisplay_refresh_soon_obj , displayio_epaperdisplay_obj_refresh_soon );
216
220
217
- //| .. method :: wait_for_frame()
221
+ //| .. attribute :: time_to_refresh
218
222
//|
219
- //| Waits until the next frame has been transmitted to the display unless the wait count is
220
- //| behind the rendered frames. In that case, this will return immediately with the wait count.
223
+ //| Time, in fractional seconds, until the ePaper display can be refreshed.
221
224
//|
222
- STATIC mp_obj_t displayio_epaperdisplay_obj_wait_for_frame (mp_obj_t self_in ) {
225
+ //|
226
+ STATIC mp_obj_t displayio_epaperdisplay_obj_get_time_to_refresh (mp_obj_t self_in ) {
223
227
displayio_epaperdisplay_obj_t * self = native_display (self_in );
224
- return MP_OBJ_NEW_SMALL_INT ( common_hal_displayio_epaperdisplay_wait_for_frame (self ));
228
+ return mp_obj_new_float ( common_hal_displayio_epaperdisplay_get_time_to_refresh (self ));
225
229
}
226
- MP_DEFINE_CONST_FUN_OBJ_1 (displayio_epaperdisplay_wait_for_frame_obj , displayio_epaperdisplay_obj_wait_for_frame );
230
+ MP_DEFINE_CONST_FUN_OBJ_1 (displayio_epaperdisplay_get_time_to_refresh_obj , displayio_epaperdisplay_obj_get_time_to_refresh );
231
+
232
+ const mp_obj_property_t displayio_epaperdisplay_time_to_refresh_obj = {
233
+ .base .type = & mp_type_property ,
234
+ .proxy = {(mp_obj_t )& displayio_epaperdisplay_get_time_to_refresh_obj ,
235
+ (mp_obj_t )& mp_const_none_obj ,
236
+ (mp_obj_t )& mp_const_none_obj },
237
+ };
227
238
228
239
//| .. attribute:: width
229
240
//|
@@ -282,12 +293,12 @@ const mp_obj_property_t displayio_epaperdisplay_bus_obj = {
282
293
283
294
STATIC const mp_rom_map_elem_t displayio_epaperdisplay_locals_dict_table [] = {
284
295
{ MP_ROM_QSTR (MP_QSTR_show ), MP_ROM_PTR (& displayio_epaperdisplay_show_obj ) },
285
- { MP_ROM_QSTR (MP_QSTR_refresh_soon ), MP_ROM_PTR (& displayio_epaperdisplay_refresh_soon_obj ) },
286
- { MP_ROM_QSTR (MP_QSTR_wait_for_frame ), MP_ROM_PTR (& displayio_epaperdisplay_wait_for_frame_obj ) },
296
+ { MP_ROM_QSTR (MP_QSTR_refresh_soon ), MP_ROM_PTR (& displayio_epaperdisplay_refresh_obj ) },
287
297
288
298
{ MP_ROM_QSTR (MP_QSTR_width ), MP_ROM_PTR (& displayio_epaperdisplay_width_obj ) },
289
299
{ MP_ROM_QSTR (MP_QSTR_height ), MP_ROM_PTR (& displayio_epaperdisplay_height_obj ) },
290
300
{ MP_ROM_QSTR (MP_QSTR_bus ), MP_ROM_PTR (& displayio_epaperdisplay_bus_obj ) },
301
+ { MP_ROM_QSTR (MP_QSTR_time_to_refresh ), MP_ROM_PTR (& displayio_epaperdisplay_time_to_refresh_obj ) },
291
302
};
292
303
STATIC MP_DEFINE_CONST_DICT (displayio_epaperdisplay_locals_dict , displayio_epaperdisplay_locals_dict_table );
293
304
0 commit comments