modpupdevices: add light to ColorDistanceSensor
#include "pberror.h"
#include "pbkwarg.h"
+#include "modlight.h"
#include "modparameters.h"
#include "modmotor.h"
#include "pbiodevice.h"
// Class structure for ColorAndDistSensor
typedef struct _pupdevices_ColorAndDistSensor_obj_t {
mp_obj_base_t base;
+ mp_obj_t light;
pbio_iodev_t *iodev;
} pupdevices_ColorAndDistSensor_obj_t;
@@ -37,6 +39,14 @@ STATIC mp_obj_t pupdevices_ColorAndDistSensor_make_new(const mp_obj_type_t *type
pb_assert(pbdrv_ioport_get_iodev(port_num, &self->iodev));
pb_iodevice_assert_type_id(self->iodev, PBIO_IODEV_TYPE_ID_COLOR_DIST_SENSOR);
pb_iodevice_set_mode(self->iodev, 8);
+
+ // Create an instance of the Light class
+ pbio_lightdev_t dev = {
+ .id = self->iodev->info->type_id,
+ .pupiodev = self->iodev,
+ };
+ self->light = light_Light_obj_make_new(dev, &light_ColorLight_type);
+
return MP_OBJ_FROM_PTR(self);
}
@@ -118,6 +128,7 @@ STATIC const mp_rom_map_elem_t pupdevices_ColorAndDistSensor_locals_dict_table[]
{ MP_ROM_QSTR(MP_QSTR_ambient), MP_ROM_PTR(&pupdevices_ColorAndDistSensor_ambient_obj) },
{ MP_ROM_QSTR(MP_QSTR_distance), MP_ROM_PTR(&pupdevices_ColorAndDistSensor_distance_obj) },
{ MP_ROM_QSTR(MP_QSTR_rgb), MP_ROM_PTR(&pupdevices_ColorAndDistSensor_rgb_obj) },
+ { MP_ROM_QSTR(MP_QSTR_light), MP_ROM_ATTRIBUTE_OFFSET(pupdevices_ColorAndDistSensor_obj_t, light) },
};
STATIC MP_DEFINE_CONST_DICT(pupdevices_ColorAndDistSensor_locals_dict, pupdevices_ColorAndDistSensor_locals_dict_table);
