eric6/MicroPython/MicroPythonDevices.py

changeset 8082
2242a6a1d786
parent 8079
331e717c458e
child 8084
7742e0b96629
equal deleted inserted replaced
8081:e0087e542717 8082:2242a6a1d786
58 (0x1209, 0xBAB6), # Electronic Cats Escornabot Makech 58 (0x1209, 0xBAB6), # Electronic Cats Escornabot Makech
59 (0x16C0, 0x0486), # PJRC Teensy 4.1 59 (0x16C0, 0x0486), # PJRC Teensy 4.1
60 (0x1B4F, 0x0016), # Sparkfun Thing Plus - SAMD51 60 (0x1B4F, 0x0016), # Sparkfun Thing Plus - SAMD51
61 (0x1B4F, 0x8D22), # SparkFun SAMD21 Mini Breakout 61 (0x1B4F, 0x8D22), # SparkFun SAMD21 Mini Breakout
62 (0x1B4F, 0x8D23), # SparkFun SAMD21 Dev Breakout 62 (0x1B4F, 0x8D23), # SparkFun SAMD21 Dev Breakout
63 # TODO: re-enable after testing is done 63 (0x1B4F, 0x8D24), # SparkFun Qwiic Micro
64 # (0x1B4F, 0x8D24), # SparkFun Qwiic Micro
65 (0x1D50, 0x60E8), # PewPew Game Console 64 (0x1D50, 0x60E8), # PewPew Game Console
66 (0x2341, 0x8057), # Arduino Nano 33 IoT board 65 (0x2341, 0x8057), # Arduino Nano 33 IoT board
67 (0x2886, 0x002F), # Seeed XIAO 66 (0x2886, 0x002F), # Seeed XIAO
68 (0x2886, 0x802D), # Seeed Wio Terminal 67 (0x2886, 0x802D), # Seeed Wio Terminal
69 (0x2886, 0x802F), # Seeed XIAO 68 (0x2886, 0x802F), # Seeed XIAO
170 if ( 169 if (
171 port.description().strip() != 170 port.description().strip() !=
172 SupportedBoards[board]["port_description"] 171 SupportedBoards[board]["port_description"]
173 ): 172 ):
174 continue 173 continue
175 foundDevices.append( 174 foundDevices.append((
176 (board, 175 board,
177 port.description(), 176 port.description(),
178 SupportedBoards[board]["description"], 177 SupportedBoards[board]["description"],
179 port.portName())) 178 port.portName(),
179 vid,
180 pid,
181 ))
180 supported = True 182 supported = True
181 if not supported: 183 if not supported:
182 # check the locally added ones next 184 # check the locally added ones next
183 if (vid, pid) in manualDevices: 185 if (vid, pid) in manualDevices:
184 board = manualDevices[(vid, pid)]["type"] 186 board = manualDevices[(vid, pid)]["type"]
185 foundDevices.append( 187 foundDevices.append((
186 (board, 188 board,
187 port.description(), 189 port.description(),
188 SupportedBoards[board]["description"], 190 SupportedBoards[board]["description"],
189 port.portName())) 191 port.portName(),
192 vid,
193 pid,
194 ))
190 supported = True 195 supported = True
191 if not supported: 196 if not supported:
192 if vid and pid and (vid, pid) not in IgnoredBoards: 197 if vid and pid and (vid, pid) not in IgnoredBoards:
193 unknownDevices.append((vid, pid, port.description())) 198 unknownDevices.append((vid, pid, port.description()))
194 logging.debug("Unknown device: (0x%04x:0x%04x %s)", 199 logging.debug("Unknown device: (0x%04x:0x%04x %s)",
219 return UI.PixmapCache.getIcon(iconName) 224 return UI.PixmapCache.getIcon(iconName)
220 else: 225 else:
221 return UI.PixmapCache.getPixmap(iconName) 226 return UI.PixmapCache.getPixmap(iconName)
222 227
223 228
224 def getDevice(deviceType, microPythonWidget): 229 def getDevice(deviceType, microPythonWidget, vid, pid):
225 """ 230 """
226 Public method to instantiate a specific MicroPython device interface. 231 Public method to instantiate a specific MicroPython device interface.
227 232
228 @param deviceType type of the device interface 233 @param deviceType type of the device interface
229 @type str 234 @type str
230 @param microPythonWidget reference to the main MicroPython widget 235 @param microPythonWidget reference to the main MicroPython widget
231 @type MicroPythonWidget 236 @type MicroPythonWidget
237 @param vid vendor ID (only used for deviceType 'generic')
238 @type int
239 @param pid product ID (only used for deviceType 'generic')
240 @type int
232 @return instantiated device interface 241 @return instantiated device interface
233 @rtype MicroPythonDevice 242 @rtype MicroPythonDevice
234 """ 243 """
235 # TODO: use vid, pid for 'generic' type
236 if deviceType == "esp": 244 if deviceType == "esp":
237 from .EspDevices import EspDevice 245 from .EspDevices import EspDevice
238 return EspDevice(microPythonWidget) 246 return EspDevice(microPythonWidget)
239 elif deviceType == "circuitpython": 247 elif deviceType == "circuitpython":
240 from .CircuitPythonDevices import CircuitPythonDevice 248 from .CircuitPythonDevices import CircuitPythonDevice
243 from .MicrobitDevices import MicrobitDevice 251 from .MicrobitDevices import MicrobitDevice
244 return MicrobitDevice(microPythonWidget, deviceType) 252 return MicrobitDevice(microPythonWidget, deviceType)
245 elif deviceType == "pyboard": 253 elif deviceType == "pyboard":
246 from .PyBoardDevices import PyBoardDevice 254 from .PyBoardDevices import PyBoardDevice
247 return PyBoardDevice(microPythonWidget) 255 return PyBoardDevice(microPythonWidget)
256 elif deviceType == "generic":
257 from .GenericMicroPythonDevices import GenericMicroPythonDevice
258 return GenericMicroPythonDevice(microPythonWidget, vid, pid)
248 else: 259 else:
249 # nothing specific requested 260 # nothing specific requested
250 return MicroPythonDevice(microPythonWidget) 261 return MicroPythonDevice(microPythonWidget)
251 262
252 263
253 class MicroPythonDevice(QObject): 264 class MicroPythonDevice(QObject):
254 """ 265 """
255 Base class for the more specific MicroPython devices. 266 Base class for the more specific MicroPython devices.
256 """ 267 """
257 # TODO: use vid, pid for 'generic' type
258 # TODO: check, if this is a direct access device
259 def __init__(self, microPythonWidget, parent=None): 268 def __init__(self, microPythonWidget, parent=None):
260 """ 269 """
261 Constructor 270 Constructor
262 271
263 @param microPythonWidget reference to the main MicroPython widget 272 @param microPythonWidget reference to the main MicroPython widget
378 Public method to indicate file access via a local directory. 387 Public method to indicate file access via a local directory.
379 388
380 @return flag indicating file access via local directory 389 @return flag indicating file access via local directory
381 @rtype bool 390 @rtype bool
382 """ 391 """
383 # TODO: check 'unknown devices' with type 'generic'
384 return False # default 392 return False # default
385 393
386 def getWorkspace(self): 394 def getWorkspace(self):
387 """ 395 """
388 Public method to get the workspace directory. 396 Public method to get the workspace directory.
389 397
390 @return workspace directory used for saving files 398 @return workspace directory used for saving files
391 @rtype str 399 @rtype str
392 """ 400 """
393 # TODO: check 'unknown devices' with type 'generic'
394 return ( 401 return (
395 Preferences.getMicroPython("MpyWorkspace") or 402 Preferences.getMicroPython("MpyWorkspace") or
396 Preferences.getMultiProject("Workspace") or 403 Preferences.getMultiProject("Workspace") or
397 os.path.expanduser("~") 404 os.path.expanduser("~")
398 ) 405 )

eric ide

mercurial