src/eric7/MicroPython/MicroPythonDevices.py

branch
eric7
changeset 9496
05017f795c24
parent 9482
a2bc06a54d9d
child 9498
d48061567354
equal deleted inserted replaced
9495:28ab5f487f71 9496:05017f795c24
6 """ 6 """
7 Module implementing some utility functions and the MicroPythonDevice base 7 Module implementing some utility functions and the MicroPythonDevice base
8 class. 8 class.
9 """ 9 """
10 10
11 import contextlib
12 import importlib
11 import logging 13 import logging
12 import os 14 import os
13 15
14 from PyQt6.QtCore import QCoreApplication, QObject, pyqtSlot 16 from PyQt6.QtCore import QCoreApplication, QObject, pyqtSlot
15 from PyQt6.QtSerialPort import QSerialPortInfo 17 from PyQt6.QtSerialPort import QSerialPortInfo
406 @param pid product ID (only used for deviceType 'generic') 408 @param pid product ID (only used for deviceType 'generic')
407 @type int 409 @type int
408 @return instantiated device interface 410 @return instantiated device interface
409 @rtype MicroPythonDevice 411 @rtype MicroPythonDevice
410 """ 412 """
411 if deviceType == "esp": 413 deviceMapping = {
412 from .EspDevices import EspDevice # __IGNORE_WARNING_I101__ 414 "bbc_microbit": ".MicrobitDevices",
413 415 "calliope": ".MicrobitDevices",
414 return EspDevice(microPythonWidget, deviceType) 416 "circuitpython": ".CircuitPythonDevices",
415 elif deviceType == "circuitpython": 417 "esp": ".EspDevices",
416 from .CircuitPythonDevices import CircuitPythonDevice # __IGNORE_WARNING_I101__ 418 "generic": ".GenericMicroPythonDevices",
417 419 "pyboard": ".PyBoardDevices",
418 return CircuitPythonDevice(microPythonWidget, deviceType) 420 "rp2040": ".RP2040Devices",
419 elif deviceType in ("bbc_microbit", "calliope"): 421 }
420 from .MicrobitDevices import MicrobitDevice # __IGNORE_WARNING_I101__ 422
421 423 with contextlib.suppress(KeyError):
422 return MicrobitDevice(microPythonWidget, deviceType) 424 mod = importlib.import_module(deviceMapping[deviceType], __package__)
423 elif deviceType == "pyboard": 425 if mod:
424 from .PyBoardDevices import PyBoardDevice # __IGNORE_WARNING_I101__ 426 return mod.createDevice(microPythonWidget, deviceType, vid, pid)
425 427
426 return PyBoardDevice(microPythonWidget, deviceType) 428 # nothing specific requested or specific one failed or is not supported yet
427 elif deviceType == "rp2040": 429 return MicroPythonDevice(microPythonWidget, deviceType)
428 from .RP2040Devices import RP2040Device # __IGNORE_WARNING_I101__
429
430 return RP2040Device(microPythonWidget, deviceType)
431 elif deviceType == "generic":
432 from .GenericMicroPythonDevices import ( # __IGNORE_WARNING_I101__
433 GenericMicroPythonDevice,
434 )
435
436 return GenericMicroPythonDevice(microPythonWidget, deviceType, vid, pid)
437 else:
438 # nothing specific requested
439 return MicroPythonDevice(microPythonWidget, deviceType)
440 430
441 431
442 class MicroPythonDevice(QObject): 432 class MicroPythonDevice(QObject):
443 """ 433 """
444 Base class for the more specific MicroPython devices. 434 Base class for the more specific MicroPython devices.

eric ide

mercurial