Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 22 additions & 3 deletions bricks/ev3/modules/_ev3_port_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,15 @@
ColorSensor as EV3ColorSensor,
TouchSensor as EV3TouchSensor,
GyroSensor,
UltrasonicSensor,
UltrasonicSensor as EV3UltrasonicSensor,
InfraredSensor,
)
from pybricks.nxtdevices import ColorSensor as NXTColorSensor, LightSensor, SoundSensor
from pybricks.nxtdevices import (
ColorSensor as NXTColorSensor,
LightSensor,
SoundSensor,
UltrasonicSensor as NXTUltrasonicSensor,
)
from pybricks.parameters import Button, Port, ImageFile
from pybricks.tools import wait

Expand All @@ -30,6 +35,7 @@
IMG_NXT_LIGHT_AMBIENT = ImageFile._PORT_VIEW_NXT_LIGHT_AMBIENT
IMG_NXT_LIGHT_REFLECTION = ImageFile._PORT_VIEW_NXT_LIGHT_REFLECTION
IMG_NXT_SOUND = ImageFile._PORT_VIEW_NXT_SOUND
IMG_NXT_ULTRASONIC = ImageFile._PORT_VIEW_NXT_ULTRASONIC
PORT_NONE_TOP = ImageFile._PORT_VIEW_P0_TOP
PORT_NONE_BOTTOM = ImageFile._PORT_VIEW_P0_BOTTOM
PORT_IMG = [
Expand Down Expand Up @@ -94,7 +100,7 @@ def port_process(index):

# EV3 Ultrasonic Sensor
try:
sensor = UltrasonicSensor(PORTS[index])
sensor = EV3UltrasonicSensor(PORTS[index])
while True:
try:
distance = sensor.distance()
Expand Down Expand Up @@ -227,6 +233,19 @@ def port_process(index):
except OSError:
pass

# NXT Ultrasonic Sensor
try:
sensor = NXTUltrasonicSensor(PORTS[index])
while True:
try:
distance = sensor.distance()
detail = f"{distance:>4} mm"
yield IMG_NXT_ULTRASONIC, distance, detail
except OSError:
break
except OSError:
pass

# Nothing on this port.
yield None, "---", "No device"

Expand Down
120 changes: 120 additions & 0 deletions lib/pbio/src/image/media/ui/_port_view_nxt_ultrasonic.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading