extmod/modnxtdevices/LightSensor: no compensation
This reverts
This is not working well enough due to the low analog sampling time.
To get this kind of functionality, users may use the NXT Color Sensor, which does now compensate for ambient light.
@@ -185,15 +185,13 @@ STATIC const mp_obj_type_t nxtdevices_SoundSensor_type = {
// pybricks.nxtdevices.LightSensor class object
typedef struct _nxtdevices_LightSensor_obj_t {
mp_obj_base_t base;
- bool compensate_ambient;
pbio_ev3iodev_t *iodev;
} nxtdevices_LightSensor_obj_t;
// pybricks.nxtdevices.LightSensor.__init__
STATIC mp_obj_t nxtdevices_LightSensor_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args ) {
PB_PARSE_ARGS_CLASS(n_args, n_kw, args,
- PB_ARG_REQUIRED(port),
- PB_ARG_DEFAULT_FALSE(compensation)
+ PB_ARG_REQUIRED(port)
);
nxtdevices_LightSensor_obj_t *self = m_new_obj(nxtdevices_LightSensor_obj_t);
@@ -201,8 +199,6 @@ STATIC mp_obj_t nxtdevices_LightSensor_make_new(const mp_obj_type_t *type, size_
mp_int_t port_num = enum_get_value_maybe(port, &pb_enum_type_Port);
- self->compensate_ambient = mp_obj_is_true(compensation);
-
// Get the device and assert that it is of the right type
pb_assert(ev3device_get_device(&self->iodev, PBIO_IODEV_TYPE_ID_NXT_LIGHT_SENSOR, port_num));
return MP_OBJ_FROM_PTR(self);
@@ -229,24 +225,8 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(nxtdevices_LightSensor_ambient_obj, nxtdevices_
STATIC mp_obj_t nxtdevices_LightSensor_reflection(mp_obj_t self_in) {
nxtdevices_LightSensor_obj_t *self = MP_OBJ_TO_PTR(self_in);
int32_t analog;
- int32_t ambient = 0;
- int32_t reflection;
- if (self->compensate_ambient) {
- pb_assert(ev3device_get_values_at_mode(self->iodev, PBIO_IODEV_MODE_NXT_LIGHT_SENSOR__AMBIENT, &analog));
- mp_hal_delay_ms(30);
- pb_assert(ev3device_get_values_at_mode(self->iodev, PBIO_IODEV_MODE_NXT_LIGHT_SENSOR__AMBIENT, &analog));
- ambient = analog_light(analog);
- pb_assert(ev3device_get_values_at_mode(self->iodev, PBIO_IODEV_MODE_NXT_LIGHT_SENSOR__REFLECT, &analog));
- mp_hal_delay_ms(30);
pb_assert(ev3device_get_values_at_mode(self->iodev, PBIO_IODEV_MODE_NXT_LIGHT_SENSOR__REFLECT, &analog));
- reflection = analog_light(analog);
- }
- else {
- pb_assert(ev3device_get_values_at_mode(self->iodev, PBIO_IODEV_MODE_NXT_LIGHT_SENSOR__REFLECT, &analog));
- reflection = analog_light(analog);
- ambient = 0;
- }
- return mp_obj_new_int(max(reflection-ambient, 0));
+ return mp_obj_new_int(analog_light(analog));
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(nxtdevices_LightSensor_reflection_obj, nxtdevices_LightSensor_reflection);
