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. |