diff --git a/meshtastic/supported_device.py b/meshtastic/supported_device.py index 80356941e..a42a95cd1 100755 --- a/meshtastic/supported_device.py +++ b/meshtastic/supported_device.py @@ -28,9 +28,18 @@ def __init__( self.for_firmware = for_firmware self.device_class = device_class # could be "nrf52" + def _norm_usb_id(usb_id): + """lower case, no "0x" prefix, zero-padded to 4 hex digits""" + if not usb_id: + return usb_id + usb_id = usb_id.strip().lower() + if usb_id.startswith("0x"): + usb_id = usb_id[2:] + return usb_id.zfill(4) + # when you run "lsusb -d xxxx:" in linux - self.usb_vendor_id_in_hex = usb_vendor_id_in_hex # store in lower case - self.usb_product_id_in_hex = usb_product_id_in_hex # store in lower case + self.usb_vendor_id_in_hex = _norm_usb_id(usb_vendor_id_in_hex) + self.usb_product_id_in_hex = _norm_usb_id(usb_product_id_in_hex) self.baseport_on_linux = baseport_on_linux # ex: ttyUSB or ttyACM self.baseport_on_mac = baseport_on_mac @@ -231,6 +240,18 @@ def __init__( +pico2 = SupportedDevice( + name="Raspberry Pi Pico 2", + version="", + for_firmware="pico2", + device_class="rp2350", + baseport_on_linux="ttyACM", + baseport_on_mac="cu.usbmodem", + baseport_on_windows="COM", + usb_vendor_id_in_hex="2e8a", + usb_product_id_in_hex="000f", +) + supported_devices = [ tbeam_v0_7, tbeam_v1_1, @@ -252,4 +273,5 @@ def __init__( nano_g1, seeed_xiao_s3, tdeck, # T-Deck support added + pico2, ] diff --git a/meshtastic/tests/test_supported_device.py b/meshtastic/tests/test_supported_device.py new file mode 100644 index 000000000..a07cadf3e --- /dev/null +++ b/meshtastic/tests/test_supported_device.py @@ -0,0 +1,14 @@ +"""Meshtastic unit tests for supported_device.py""" + +import pytest + +from meshtastic.supported_device import SupportedDevice + + +@pytest.mark.unit +def test_usb_ids_are_normalized(): + """VID/PID are stored lower case, without 0x, padded to 4 digits""" + sd = SupportedDevice(name="x", usb_vendor_id_in_hex="0x2E8A", usb_product_id_in_hex="F") + assert sd.usb_vendor_id_in_hex == "2e8a" + assert sd.usb_product_id_in_hex == "000f" + assert SupportedDevice(name="y").usb_vendor_id_in_hex is None diff --git a/meshtastic/tests/test_util.py b/meshtastic/tests/test_util.py index 830311a2e..b2aa4575c 100644 --- a/meshtastic/tests/test_util.py +++ b/meshtastic/tests/test_util.py @@ -10,6 +10,7 @@ import pytest from hypothesis import given, strategies as st +from meshtastic import supported_device from meshtastic.supported_device import SupportedDevice from meshtastic.protobuf import mesh_pb2, config_pb2 from meshtastic.util import ( @@ -29,6 +30,8 @@ fromStr, generate_channel_hash, genPSK256, + get_devices_with_vendor_id, + get_unique_vendor_ids, hexstr, ipstr, is_windows11, @@ -974,3 +977,11 @@ def test_flags_from_list_roundtrip(flags): # but for combinations of known non-zero flags it should return the same set of names. nonzero_flags = {f for f in flags if _POSITION_FLAGS.Value(f)} assert set(decoded) == nonzero_flags + + +@pytest.mark.unit +def test_pico2_supported_device(): + """Test that the Raspberry Pi Pico 2 is detected by its vendor id""" + assert supported_device.pico2 in get_devices_with_vendor_id("2e8a") + assert "2e8a" in get_unique_vendor_ids() + assert supported_device.pico2.for_firmware == "pico2"