Skip to content

Commit c429735

Browse files
Copilotdlech
andcommitted
Use pbio_port_get_analog_value for touch sensor detection
Replaced direct dcm access with proper abstraction layer as suggested in code review. This avoids resetting the dcm and uses the intended API. Co-authored-by: dlech <963645+dlech@users.noreply.github.com>
1 parent 65f689e commit c429735

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

pybricks/iodevices/pb_type_iodevices_pupdevice.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,16 +53,16 @@ static bool init_passive_pup_device(iodevices_PUPDevice_obj_t *self, mp_obj_t po
5353
pb_assert(pbio_port_get_port(port_id, &port));
5454

5555
// Check for touch sensor first.
56-
lego_device_type_id_t type_id = LEGO_DEVICE_TYPE_ID_LPF2_TOUCH;
57-
pbio_error_t err = pbio_port_dcm_assert_type_id(pbio_port_dcm_init_instance(port_id - PBIO_PORT_ID_A), &type_id);
56+
uint32_t value;
57+
pbio_error_t err = pbio_port_get_analog_value(port, LEGO_DEVICE_TYPE_ID_LPF2_TOUCH, false, &value);
5858
if (err == PBIO_SUCCESS) {
59-
self->passive_id = type_id;
59+
self->passive_id = LEGO_DEVICE_TYPE_ID_LPF2_TOUCH;
6060
self->passive_port = port;
6161
return true;
6262
}
6363

6464
// Check for DC motor.
65-
type_id = LEGO_DEVICE_TYPE_ID_ANY_DC_MOTOR;
65+
lego_device_type_id_t type_id = LEGO_DEVICE_TYPE_ID_ANY_DC_MOTOR;
6666
pbio_dcmotor_t *dcmotor;
6767
err = pbio_port_get_dcmotor(port, &type_id, &dcmotor);
6868

0 commit comments

Comments
 (0)