|
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 | +blacklistVids = dict.fromkeys([0x1366, 0x0483]) |
| 29 | + |
| 30 | +"""Some devices are highly likely to be meshtastic. |
| 31 | +0x239a RAK4631 |
| 32 | +0x303a Heltec tracker""" |
| 33 | +whitelistVids = dict.fromkeys([0x239a, 0x303a]) |
| 34 | + |
29 | 35 |
|
30 | 36 | def quoteBooleans(a_string): |
31 | 37 | """Quote booleans |
@@ -130,19 +136,35 @@ def findPorts(eliminate_duplicates: bool=False) -> List[str]: |
130 | 136 | Returns: |
131 | 137 | list -- a list of device paths |
132 | 138 | """ |
133 | | - l = list( |
| 139 | + all_ports = serial.tools.list_ports.comports() |
| 140 | + |
| 141 | + # look for 'likely' meshtastic devices |
| 142 | + ports = list( |
134 | 143 | map( |
135 | 144 | lambda port: port.device, |
136 | 145 | filter( |
137 | | - lambda port: port.vid is not None and port.vid not in blacklistVids, |
138 | | - serial.tools.list_ports.comports(), |
| 146 | + lambda port: port.vid is not None and port.vid in whitelistVids, |
| 147 | + all_ports, |
139 | 148 | ), |
140 | 149 | ) |
141 | 150 | ) |
142 | | - l.sort() |
| 151 | + |
| 152 | + # if no likely devices, just list everything not blacklisted |
| 153 | + if len(ports) == 0: |
| 154 | + ports = list( |
| 155 | + map( |
| 156 | + lambda port: port.device, |
| 157 | + filter( |
| 158 | + lambda port: port.vid is not None and port.vid not in blacklistVids, |
| 159 | + all_ports, |
| 160 | + ), |
| 161 | + ) |
| 162 | + ) |
| 163 | + |
| 164 | + ports.sort() |
143 | 165 | if eliminate_duplicates: |
144 | | - l = eliminate_duplicate_port(l) |
145 | | - return l |
| 166 | + ports = eliminate_duplicate_port(ports) |
| 167 | + return ports |
146 | 168 |
|
147 | 169 |
|
148 | 170 | class dotdict(dict): |
|
0 commit comments