extmod/ev3devices: check port type
@@ -36,7 +36,9 @@ STATIC mp_obj_t ev3devices_TouchSensor_make_new(const mp_obj_type_t *type, size_
ev3devices_TouchSensor_obj_t *self = m_new_obj(ev3devices_TouchSensor_obj_t);
self->base.type = (mp_obj_type_t*) type;
- pb_assert(ev3device_get_device(&self->iodev, PBIO_IODEV_TYPE_ID_EV3_TOUCH_SENSOR, mp_obj_get_int(port)));
+
+ mp_int_t port_num = enum_get_value_maybe(port, &pb_enum_type_Port);
+ pb_assert(ev3device_get_device(&self->iodev, PBIO_IODEV_TYPE_ID_EV3_TOUCH_SENSOR, port_num));
return MP_OBJ_FROM_PTR(self);
}
@@ -86,7 +88,10 @@ STATIC mp_obj_t ev3devices_InfraredSensor_make_new(const mp_obj_type_t *type, si
ev3devices_InfraredSensor_obj_t *self = m_new_obj(ev3devices_InfraredSensor_obj_t);
self->base.type = (mp_obj_type_t*) type;
- pb_assert(ev3device_get_device(&self->iodev, PBIO_IODEV_TYPE_ID_EV3_IR_SENSOR, mp_obj_get_int(port)));
+
+ mp_int_t port_num = enum_get_value_maybe(port, &pb_enum_type_Port);
+
+ pb_assert(ev3device_get_device(&self->iodev, PBIO_IODEV_TYPE_ID_EV3_IR_SENSOR, port_num));
return MP_OBJ_FROM_PTR(self);
}
@@ -386,7 +391,9 @@ STATIC mp_obj_t ev3devices_UltrasonicSensor_make_new(const mp_obj_type_t *type,
ev3devices_UltrasonicSensor_obj_t *self = m_new_obj(ev3devices_UltrasonicSensor_obj_t);
self->base.type = (mp_obj_type_t*) type;
- pb_assert(ev3device_get_device(&self->iodev, PBIO_IODEV_TYPE_ID_EV3_ULTRASONIC_SENSOR, mp_obj_get_int(port)));
+
+ mp_int_t port_num = enum_get_value_maybe(port, &pb_enum_type_Port);
+ pb_assert(ev3device_get_device(&self->iodev, PBIO_IODEV_TYPE_ID_EV3_ULTRASONIC_SENSOR, port_num));
// Create an instance of the Light class
self->light = ev3devices_Light_obj_make_new(self->iodev);
@@ -487,7 +494,9 @@ STATIC mp_obj_t ev3devices_GyroSensor_make_new(const mp_obj_type_t *type, size_t
ev3devices_GyroSensor_obj_t *self = m_new_obj(ev3devices_GyroSensor_obj_t);
self->base.type = (mp_obj_type_t*) type;
self->direction = mp_obj_get_int(direction);
- pb_assert(ev3device_get_device(&self->iodev, PBIO_IODEV_TYPE_ID_EV3_GYRO_SENSOR, mp_obj_get_int(port)));
+
+ mp_int_t port_num = enum_get_value_maybe(port, &pb_enum_type_Port);
+ pb_assert(ev3device_get_device(&self->iodev, PBIO_IODEV_TYPE_ID_EV3_GYRO_SENSOR, port_num));
self->offset = ev3devices_GyroSensor_get_angle_offset(self->iodev, self->direction, 0);
return MP_OBJ_FROM_PTR(self);
}
