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
26 changes: 24 additions & 2 deletions meshtastic/supported_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -252,4 +273,5 @@ def __init__(
nano_g1,
seeed_xiao_s3,
tdeck, # T-Deck support added
pico2,
]
14 changes: 14 additions & 0 deletions meshtastic/tests/test_supported_device.py
Original file line number Diff line number Diff line change
@@ -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
11 changes: 11 additions & 0 deletions meshtastic/tests/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -29,6 +30,8 @@
fromStr,
generate_channel_hash,
genPSK256,
get_devices_with_vendor_id,
get_unique_vendor_ids,
hexstr,
ipstr,
is_windows11,
Expand Down Expand Up @@ -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"