extmod/modnxtdevices: update SoundSensor method
The soundsensor measures approximate sound intensity, not actual dB.
@@ -145,28 +145,25 @@ STATIC mp_obj_t nxtdevices_SoundSensor_make_new(const mp_obj_type_t *type, size_
return MP_OBJ_FROM_PTR(self);
}
-// pybricks.nxtdevices.SoundSensor.db
-STATIC mp_obj_t nxtdevices_SoundSensor_db(mp_obj_t self_in) {
- nxtdevices_SoundSensor_obj_t *self = MP_OBJ_TO_PTR(self_in);
- int32_t analog;
- pbdevice_get_values(self->pbdev, PBIO_IODEV_MODE_NXT_ANALOG__PASSIVE, &analog);
- return mp_obj_new_int(analog_scale(analog, 650, 4860, true));
-}
-STATIC MP_DEFINE_CONST_FUN_OBJ_1(nxtdevices_SoundSensor_db_obj, nxtdevices_SoundSensor_db);
+// pybricks.nxtdevices.SoundSensor.intensity
+STATIC mp_obj_t nxtdevices_SoundSensor_intensity(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
-// pybricks.nxtdevices.SoundSensor.dba
-STATIC mp_obj_t nxtdevices_SoundSensor_dba(mp_obj_t self_in) {
- nxtdevices_SoundSensor_obj_t *self = MP_OBJ_TO_PTR(self_in);
+ PB_PARSE_ARGS_METHOD(n_args, pos_args, kw_args,
+ nxtdevices_SoundSensor_obj_t, self,
+ PB_ARG_DEFAULT_TRUE(audible_only)
+ );
+
+ uint8_t mode = mp_obj_is_true(audible_only) ? PBIO_IODEV_MODE_NXT_ANALOG__ACTIVE : PBIO_IODEV_MODE_NXT_ANALOG__PASSIVE;
int32_t analog;
- pbdevice_get_values(self->pbdev, PBIO_IODEV_MODE_NXT_ANALOG__ACTIVE, &analog);
+ pbdevice_get_values(self->pbdev, mode, &analog);
+
return mp_obj_new_int(analog_scale(analog, 650, 4860, true));
}
-STATIC MP_DEFINE_CONST_FUN_OBJ_1(nxtdevices_SoundSensor_dba_obj, nxtdevices_SoundSensor_dba);
+STATIC MP_DEFINE_CONST_FUN_OBJ_KW(nxtdevices_SoundSensor_intensity_obj, 0, nxtdevices_SoundSensor_intensity);
// dir(pybricks.ev3devices.SoundSensor)
STATIC const mp_rom_map_elem_t nxtdevices_SoundSensor_locals_dict_table[] = {
- { MP_ROM_QSTR(MP_QSTR_db), MP_ROM_PTR(&nxtdevices_SoundSensor_db_obj ) },
- { MP_ROM_QSTR(MP_QSTR_dba), MP_ROM_PTR(&nxtdevices_SoundSensor_dba_obj) },
+ { MP_ROM_QSTR(MP_QSTR_intensity), MP_ROM_PTR(&nxtdevices_SoundSensor_intensity_obj ) },
};
STATIC MP_DEFINE_CONST_DICT(nxtdevices_SoundSensor_locals_dict, nxtdevices_SoundSensor_locals_dict_table);
