extmod/modiodevices: enable power for known device
In the long run, power requirements can be read from the
sensor. Until then, we do this manually to ensure we only
activate power on sensors that are known to support it.
@@ -41,6 +41,16 @@ STATIC mp_obj_t iodevices_LUMPDevice_make_new(const mp_obj_type_t *type, size_t
self->pbdev = pbdevice_get_device(port_num, PBIO_IODEV_TYPE_ID_LUMP_UART);
+ // FIXME: Read sensor capability flag to see which sensor uses power. As
+ // a precaution, only enable power for selected known sensors for now.
+ pbio_port_t _port;
+ pbio_iodev_type_id_t id;
+ uint8_t curr_mode;
+ uint8_t num_values;
+ pbdevice_get_info(self->pbdev, &_port, &id, &curr_mode, &num_values);
+ bool power = (id == PBIO_IODEV_TYPE_ID_SPIKE_COLOR_SENSOR || id == PBIO_IODEV_TYPE_ID_SPIKE_ULTRASONIC_SENSOR);
+ pbdevice_set_power_supply(self->pbdev, power);
+
return MP_OBJ_FROM_PTR(self);
}
