Skip to content

Commit 23f99a4

Browse files
committed
add wrapper around badge_eink_display() method
1 parent 98c2d76 commit 23f99a4

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

esp32/modbadge.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,33 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_3(badge_eink_png_obj, badge_eink_png);
339339
/* END OF PNG READER TEST */
340340

341341

342+
/* Raw frame display */
343+
STATIC mp_obj_t badge_eink_display_raw(mp_obj_t obj_img, mp_obj_t obj_flags)
344+
{
345+
bool is_bytes = MP_OBJ_IS_TYPE(obj_img, &mp_type_bytes);
346+
347+
if (!is_bytes) {
348+
mp_raise_msg(&mp_type_AttributeError, "First argument should be a bytestring");
349+
}
350+
351+
// convert the input buffer into a byte array
352+
mp_uint_t len;
353+
uint8_t *buffer = (uint8_t *)mp_obj_str_get_data(obj_img, &len);
354+
355+
int flags = mp_obj_get_int(obj_flags);
356+
int expect_len = (flags & DISPLAY_FLAG_8BITPIXEL) ? BADGE_EINK_WIDTH*BADGE_EINK_HEIGHT : BADGE_EINK_WIDTH*BADGE_EINK_HEIGHT/8;
357+
if (len != expect_len) {
358+
mp_raise_msg(&mp_type_AttributeError, "First argument has wrong length");
359+
}
360+
361+
// display the image directly
362+
badge_eink_display(buffer, flags);
363+
364+
return mp_const_none;
365+
}
366+
STATIC MP_DEFINE_CONST_FUN_OBJ_2(badge_eink_display_raw_obj, badge_eink_display_raw);
367+
368+
342369
// Power (badge_power.h)
343370

344371
STATIC mp_obj_t badge_power_init_() {
@@ -614,6 +641,7 @@ STATIC const mp_rom_map_elem_t badge_module_globals_table[] = {
614641
{MP_ROM_QSTR(MP_QSTR_eink_busy_wait), MP_ROM_PTR(&badge_eink_busy_wait_obj)},
615642

616643
{MP_ROM_QSTR(MP_QSTR_eink_png), MP_ROM_PTR(&badge_eink_png_obj)},
644+
{MP_ROM_QSTR(MP_QSTR_eink_display_raw), MP_ROM_PTR(&badge_eink_display_raw_obj)},
617645

618646
/*
619647
{MP_ROM_QSTR(MP_QSTR_display_picture), MP_ROM_PTR(&badge_display_picture_obj)},

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy