Skip to content

Commit 2eaa98a

Browse files
authored
Merge pull request adafruit#1601 from penguindustin/master
added height and width attributes for displayio
2 parents 233cfcd + 4145f87 commit 2eaa98a

File tree

3 files changed

+50
-0
lines changed

3 files changed

+50
-0
lines changed

shared-bindings/displayio/Display.c

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,13 +253,52 @@ const mp_obj_property_t displayio_display_auto_brightness_obj = {
253253
(mp_obj_t)&mp_const_none_obj},
254254
};
255255

256+
//| .. attribute:: width
257+
//|
258+
//| Gets the width of the board
259+
//|
260+
//|
261+
STATIC mp_obj_t displayio_display_obj_get_width(mp_obj_t self_in) {
262+
displayio_display_obj_t *self = MP_OBJ_TO_PTR(self_in);
263+
return MP_OBJ_NEW_SMALL_INT(common_hal_displayio_display_get_width(self));
264+
}
265+
MP_DEFINE_CONST_FUN_OBJ_1(displayio_display_get_width_obj, displayio_display_obj_get_width);
266+
267+
const mp_obj_property_t displayio_display_width_obj = {
268+
.base.type = &mp_type_property,
269+
.proxy = {(mp_obj_t)&displayio_display_get_width_obj,
270+
(mp_obj_t)&mp_const_none_obj,
271+
(mp_obj_t)&mp_const_none_obj},
272+
};
273+
274+
//| .. attribute:: height
275+
//|
276+
//| Gets the height of the board
277+
//|
278+
//|
279+
STATIC mp_obj_t displayio_display_obj_get_height(mp_obj_t self_in) {
280+
displayio_display_obj_t *self = MP_OBJ_TO_PTR(self_in);
281+
return MP_OBJ_NEW_SMALL_INT(common_hal_displayio_display_get_height(self));
282+
}
283+
MP_DEFINE_CONST_FUN_OBJ_1(displayio_display_get_height_obj, displayio_display_obj_get_height);
284+
285+
const mp_obj_property_t displayio_display_height_obj = {
286+
.base.type = &mp_type_property,
287+
.proxy = {(mp_obj_t)&displayio_display_get_height_obj,
288+
(mp_obj_t)&mp_const_none_obj,
289+
(mp_obj_t)&mp_const_none_obj},
290+
};
291+
256292
STATIC const mp_rom_map_elem_t displayio_display_locals_dict_table[] = {
257293
{ MP_ROM_QSTR(MP_QSTR_show), MP_ROM_PTR(&displayio_display_show_obj) },
258294
{ MP_ROM_QSTR(MP_QSTR_refresh_soon), MP_ROM_PTR(&displayio_display_refresh_soon_obj) },
259295
{ MP_ROM_QSTR(MP_QSTR_wait_for_frame), MP_ROM_PTR(&displayio_display_wait_for_frame_obj) },
260296

261297
{ MP_ROM_QSTR(MP_QSTR_brightness), MP_ROM_PTR(&displayio_display_brightness_obj) },
262298
{ MP_ROM_QSTR(MP_QSTR_auto_brightness), MP_ROM_PTR(&displayio_display_auto_brightness_obj) },
299+
300+
{ MP_ROM_QSTR(MP_QSTR_width), MP_ROM_PTR(&displayio_display_width_obj) },
301+
{ MP_ROM_QSTR(MP_QSTR_height), MP_ROM_PTR(&displayio_display_height_obj) },
263302
};
264303
STATIC MP_DEFINE_CONST_DICT(displayio_display_locals_dict, displayio_display_locals_dict_table);
265304

shared-bindings/displayio/Display.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ bool displayio_display_send_pixels(displayio_display_obj_t* self, uint32_t* pixe
5959
bool common_hal_displayio_display_get_auto_brightness(displayio_display_obj_t* self);
6060
void common_hal_displayio_display_set_auto_brightness(displayio_display_obj_t* self, bool auto_brightness);
6161

62+
uint16_t common_hal_displayio_display_get_width(displayio_display_obj_t* self);
63+
uint16_t common_hal_displayio_display_get_height(displayio_display_obj_t* self);
64+
6265
mp_float_t common_hal_displayio_display_get_brightness(displayio_display_obj_t* self);
6366
bool common_hal_displayio_display_set_brightness(displayio_display_obj_t* self, mp_float_t brightness);
6467

shared-module/displayio/Display.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,14 @@ bool common_hal_displayio_display_get_auto_brightness(displayio_display_obj_t* s
158158
return self->auto_brightness;
159159
}
160160

161+
uint16_t common_hal_displayio_display_get_width(displayio_display_obj_t* self){
162+
return self->width;
163+
}
164+
165+
uint16_t common_hal_displayio_display_get_height(displayio_display_obj_t* self){
166+
return self->height;
167+
}
168+
161169
void common_hal_displayio_display_set_auto_brightness(displayio_display_obj_t* self, bool auto_brightness) {
162170
self->auto_brightness = auto_brightness;
163171
}

0 commit comments

Comments
 (0)