|
24 | 24 | from meshtastic.supported_device import supported_devices |
25 | 25 | from meshtastic.version import get_active_version |
26 | 26 |
|
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 | + |
29 | 37 |
|
30 | 38 | def quoteBooleans(a_string): |
31 | 39 | """Quote booleans |
@@ -130,19 +138,35 @@ def findPorts(eliminate_duplicates: bool=False) -> List[str]: |
130 | 138 | Returns: |
131 | 139 | list -- a list of device paths |
132 | 140 | """ |
133 | | - l = list( |
| 141 | + all_ports = serial.tools.list_ports.comports() |
| 142 | + |
| 143 | + # look for 'likely' meshtastic devices |
| 144 | + ports = list( |
134 | 145 | map( |
135 | 146 | lambda port: port.device, |
136 | 147 | 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, |
139 | 150 | ), |
140 | 151 | ) |
141 | 152 | ) |
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() |
143 | 167 | if eliminate_duplicates: |
144 | | - l = eliminate_duplicate_port(l) |
145 | | - return l |
| 168 | + ports = eliminate_duplicate_port(ports) |
| 169 | + return ports |
146 | 170 |
|
147 | 171 |
|
148 | 172 | class dotdict(dict): |
|
0 commit comments