-
-
Notifications
You must be signed in to change notification settings - Fork 83
Add touch sensor support for Powered Up platform #454
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
|
Wow, it actually worked on the first try! from pybricks.iodevices import PUPDevice
from pybricks.parameters import Port
from pybricks.tools import wait
device = PUPDevice(Port.B)
# Should print 5 for touch sensor
print(device.info())
while True:
# prints True when pressed, otherwise False
print(device.read(0))
wait(500) |
|
Required wiring:
|
| lego_device_type_id_t type_id = LEGO_DEVICE_TYPE_ID_ANY_DC_MOTOR; | ||
| // Check for touch sensor first. | ||
| lego_device_type_id_t type_id = LEGO_DEVICE_TYPE_ID_LPF2_TOUCH; | ||
| pbio_error_t err = pbio_port_dcm_assert_type_id(pbio_port_dcm_init_instance(port_id - PBIO_PORT_ID_A), &type_id); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ew 😄
Could assert getting an analog value, which will assert the type without resetting the dcm.
pbio_port_get_analog_value(pbio_port_t *port, lego_device_type_id_t type_id, bool active, uint32_t *value)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in c429735. Now using pbio_port_get_analog_value() instead of directly accessing the dcm.
|
Impressive! Heh, I guess we have fairly good abstractions. 🙈 I've been wondering if we should have an |
|
@copilot fix this comment and ignore all other comments. |
|
Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details. Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
|
I'm planning to try this out this week. |
Co-authored-by: Laurens Valk <laurens@pybricks.com>
c429735 to
628d3d2
Compare
|
Fixed a few more cleanups and mistakes. Another caveat that would have introduced a subtle bug is that reading passive devices does not return an awaitable in async mode. I'm kind of inclined to leave it that way and add a comment instead. I don't think this feature will be used much. |
Wouldn't that break using it with block coding? Do we have a |
Touch Sensor Support on Powered Up Platform
Changes Completed:
sensor_datafield tostruct _pbio_port_dcm_tinlib/pbio/src/port_dcm_pup.cpbio_port_dcm_thread()to read touch sensor value and store itpbio_port_dcm_get_analog_value()to returndcm->sensor_datapbio_port_dcm_assert_type_id()to handle touch sensor typepybricks/iodevices/pb_type_iodevices_pupdevice.cmake -C bricks/technichubImplementation Details:
C Library Changes (lib/pbio/src/port_dcm_pup.c):
uint32_t sensor_datafield tostruct _pbio_port_dcm_tto store touch sensor readingspbio_port_dcm_thread()to read touch sensor value from GPIO pin p5 and store it indcm->sensor_datapbio_port_dcm_get_analog_value()to return the storedsensor_datavalueLEGO_DEVICE_TYPE_ID_LPF2_TOUCHcase topbio_port_dcm_assert_type_id()to properly detect touch sensorsPython Bindings (pybricks/iodevices/pb_type_iodevices_pupdevice.c):
passive_portfield toiodevices_PUPDevice_obj_tto store port reference for passive devicesinit_passive_pup_device()to check for touch sensor usingpbio_port_get_analog_value()(proper abstraction)iodevices_PUPDevice_read()to handle touch sensor reads by callingpbio_port_get_analog_value()Build Status:
✅ Successfully builds for technichub platform
Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.