Skip to content

Commit 26ebe18

Browse files
committed
pybricks.hubs.EV3Brick: Add display attribute.
This provides easy access to the brick display. Refs pybricks/support#2154
1 parent c70d02e commit 26ebe18

File tree

3 files changed

+15
-0
lines changed

3 files changed

+15
-0
lines changed

pybricks/hubs/pb_type_ev3brick.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,13 @@
1212
#include <pybricks/hubs.h>
1313
#include <pybricks/util_mp/pb_obj_helper.h>
1414
#include <pybricks/util_pb/pb_error.h>
15+
#include <pybricks/media.h>
1516

1617
typedef struct _hubs_EV3Brick_obj_t {
1718
mp_obj_base_t base;
1819
mp_obj_t battery;
1920
mp_obj_t buttons;
21+
mp_obj_t display;
2022
mp_obj_t light;
2123
mp_obj_t system;
2224
} hubs_EV3Brick_obj_t;
@@ -49,6 +51,7 @@ static mp_obj_t hubs_EV3Brick_make_new(const mp_obj_type_t *type, size_t n_args,
4951

5052
self->battery = MP_OBJ_FROM_PTR(&pb_module_battery);
5153
self->buttons = pb_type_Keypad_obj_new(pb_type_ev3brick_button_pressed);
54+
self->display = pb_type_Image_display_obj_new();
5255
self->light = common_ColorLight_internal_obj_new(pbsys_status_light_main);
5356
self->system = MP_OBJ_FROM_PTR(&pb_type_System);
5457

@@ -58,6 +61,7 @@ static mp_obj_t hubs_EV3Brick_make_new(const mp_obj_type_t *type, size_t n_args,
5861
static const pb_attr_dict_entry_t hubs_EV3Brick_attr_dict[] = {
5962
PB_DEFINE_CONST_ATTR_RO(MP_QSTR_battery, hubs_EV3Brick_obj_t, battery),
6063
PB_DEFINE_CONST_ATTR_RO(MP_QSTR_buttons, hubs_EV3Brick_obj_t, buttons),
64+
PB_DEFINE_CONST_ATTR_RO(MP_QSTR_display, hubs_EV3Brick_obj_t, display),
6165
PB_DEFINE_CONST_ATTR_RO(MP_QSTR_light, hubs_EV3Brick_obj_t, light),
6266
PB_DEFINE_CONST_ATTR_RO(MP_QSTR_system, hubs_EV3Brick_obj_t, system),
6367
PB_ATTR_DICT_SENTINEL

pybricks/media.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414

1515
extern const mp_obj_type_t pb_type_Image;
1616

17+
mp_obj_t pb_type_Image_display_obj_new(void);
18+
1719
#endif // PYBRICKS_PY_MEDIA_IMAGE
1820

1921
#endif // PYBRICKS_PY_MEDIA

pybricks/media/pb_type_image.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,15 @@ static int get_color(mp_obj_t obj) {
4242
return max - v * max / 100;
4343
}
4444

45+
mp_obj_t pb_type_Image_display_obj_new(void) {
46+
pb_type_Image_obj_t *self = mp_obj_malloc(pb_type_Image_obj_t, &pb_type_Image);
47+
self->buffer = NULL;
48+
self->update = true;
49+
self->image = *pbdrv_display_get_image();
50+
51+
return MP_OBJ_FROM_PTR(self);
52+
}
53+
4554
static mp_obj_t pb_type_Image_make_new(const mp_obj_type_t *type,
4655
size_t n_args, size_t n_kw, const mp_obj_t *args) {
4756
PB_PARSE_ARGS_CLASS(n_args, n_kw, args,

0 commit comments

Comments
 (0)