Skip to content

Commit 3a4795d

Browse files
authored
Merge pull request #605 from geeksville/pr-whitelist
Add a whitelist of known meshtastic USB VIDs to use a default serial …
2 parents c2a2d5a + 8456f36 commit 3a4795d

1 file changed

Lines changed: 32 additions & 8 deletions

File tree

meshtastic/util.py

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,16 @@
2424
from meshtastic.supported_device import supported_devices
2525
from meshtastic.version import get_active_version
2626

27-
"""Some devices such as a seger jlink we never want to accidentally open"""
28-
blacklistVids = dict.fromkeys([0x1366])
27+
"""Some devices such as a seger jlink or st-link we never want to accidentally open
28+
0x1915 NordicSemi (PPK2)
29+
"""
30+
blacklistVids = dict.fromkeys([0x1366, 0x0483, 0x1915])
31+
32+
"""Some devices are highly likely to be meshtastic.
33+
0x239a RAK4631
34+
0x303a Heltec tracker"""
35+
whitelistVids = dict.fromkeys([0x239a, 0x303a])
36+
2937

3038
def quoteBooleans(a_string):
3139
"""Quote booleans
@@ -130,19 +138,35 @@ def findPorts(eliminate_duplicates: bool=False) -> List[str]:
130138
Returns:
131139
list -- a list of device paths
132140
"""
133-
l = list(
141+
all_ports = serial.tools.list_ports.comports()
142+
143+
# look for 'likely' meshtastic devices
144+
ports = list(
134145
map(
135146
lambda port: port.device,
136147
filter(
137-
lambda port: port.vid is not None and port.vid not in blacklistVids,
138-
serial.tools.list_ports.comports(),
148+
lambda port: port.vid is not None and port.vid in whitelistVids,
149+
all_ports,
139150
),
140151
)
141152
)
142-
l.sort()
153+
154+
# if no likely devices, just list everything not blacklisted
155+
if len(ports) == 0:
156+
ports = list(
157+
map(
158+
lambda port: port.device,
159+
filter(
160+
lambda port: port.vid is not None and port.vid not in blacklistVids,
161+
all_ports,
162+
),
163+
)
164+
)
165+
166+
ports.sort()
143167
if eliminate_duplicates:
144-
l = eliminate_duplicate_port(l)
145-
return l
168+
ports = eliminate_duplicate_port(ports)
169+
return ports
146170

147171

148172
class dotdict(dict):

0 commit comments

Comments
 (0)