extmod/modhubs: add PrimeHub class
[skip ci]
@@ -180,6 +180,50 @@ STATIC const mp_obj_type_t hubs_CPlusHub_type = {
#endif // PYBRICKS_HUB_CPLUSHUB
+#ifdef PBDRV_CONFIG_HUB_PRIMEHUB
+
+// Class structure for PrimeHub
+typedef struct _hubs_PrimeHub_obj_t {
+ mp_obj_base_t base;
+ mp_obj_t light;
+} hubs_PrimeHub_obj_t;
+
+STATIC void hubs_PrimeHub_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
+ mp_printf(print, qstr_str(MP_QSTR_PrimeHub));
+}
+
+STATIC mp_obj_t hubs_PrimeHub_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args ) {
+ hubs_PrimeHub_obj_t *self = m_new_obj(hubs_PrimeHub_obj_t);
+ self->base.type = (mp_obj_type_t*) type;
+
+ // Create an instance of the Light class, representing the hub light
+ self->light = builtins_Light_obj_make_new(NULL, &builtins_ColorLight_type);
+
+ return MP_OBJ_FROM_PTR(self);
+}
+
+/*
+PrimeHub class tables
+*/
+STATIC const mp_rom_map_elem_t hubs_PrimeHub_locals_dict_table[] = {
+ { MP_ROM_QSTR(MP_QSTR_Port), MP_ROM_PTR(&pb_enum_type_Port) },
+ { MP_ROM_QSTR(MP_QSTR_battery), MP_ROM_PTR(&pb_module_battery) },
+ { MP_ROM_QSTR(MP_QSTR_shutdown), MP_ROM_PTR(&hub_shutdown_obj) },
+ { MP_ROM_QSTR(MP_QSTR_reboot), MP_ROM_PTR(&hub_reboot_obj) },
+ { MP_ROM_QSTR(MP_QSTR_light), MP_ROM_ATTRIBUTE_OFFSET(hubs_PrimeHub_obj_t, light) },
+};
+STATIC MP_DEFINE_CONST_DICT(hubs_PrimeHub_locals_dict, hubs_PrimeHub_locals_dict_table);
+
+STATIC const mp_obj_type_t hubs_PrimeHub_type = {
+ { &mp_type_type },
+ .name = MP_QSTR_PrimeHub,
+ .print = hubs_PrimeHub_print,
+ .make_new = hubs_PrimeHub_make_new,
+ .locals_dict = (mp_obj_dict_t*)&hubs_PrimeHub_locals_dict,
+};
+
+#endif // PBDRV_CONFIG_HUB_PRIMEHUB
+
#if PYBRICKS_HUB_NXT
// Class structure for NXTBrick
@@ -223,6 +267,9 @@ STATIC const mp_rom_map_elem_t hubs_globals_table[] = {
#if PYBRICKS_HUB_CPLUSHUB
{ MP_ROM_QSTR(MP_QSTR_CPlusHub), MP_ROM_PTR(&hubs_CPlusHub_type) },
#endif
+#ifdef PBDRV_CONFIG_HUB_PRIMEHUB
+ { MP_ROM_QSTR(MP_QSTR_PrimeHub), MP_ROM_PTR(&hubs_PrimeHub_type) },
+#endif
#if PYBRICKS_HUB_NXT
{ MP_ROM_QSTR(MP_QSTR_NXTBrick), MP_ROM_PTR(&hubs_NXTBrick_type) },
#endif
