diff -r bdd583f96e96 -r a8fad276cbd5 eric6/MicroPython/MicroPythonDevices.py --- a/eric6/MicroPython/MicroPythonDevices.py Tue Jul 09 19:49:41 2019 +0200 +++ b/eric6/MicroPython/MicroPythonDevices.py Wed Jul 10 20:21:57 2019 +0200 @@ -11,11 +11,12 @@ from __future__ import unicode_literals import logging +import os from PyQt5.QtCore import QObject -import Globals import UI.PixmapCache +import Preferences SupportedBoards = { @@ -44,7 +45,7 @@ (0x1209, 0x7102), # Mini SAM M0 ], "description": "CircuitPython Boards", - "icon": "adafruitDevice", + "icon": "circuitPythonDevice", }, "bbc_microbit": { @@ -135,8 +136,18 @@ @return instantiated device interface @rtype MicroPythonDevice """ - # TODO: not implemented yet - return MicroPythonDevice(microPythonWidget) + if deviceType == "esp": + from .EspDevices import EspDevice + return EspDevice(microPythonWidget) + elif deviceType == "circuitpython": + from .CircuitPythonDevices import CircuitPythonDevice + return CircuitPythonDevice(microPythonWidget) + elif deviceType == "bbc_microbit": + from .MicrobitDevices import MicrobitDevice + return MicrobitDevice(microPythonWidget) + else: + # nothing specific requested + return MicroPythonDevice(microPythonWidget) class MicroPythonDevice(QObject): @@ -154,13 +165,14 @@ """ super(MicroPythonDevice, self).__init__(parent) - self.__microPython = microPythonWidget + self.microPython = microPythonWidget def setButtons(self): """ Public method to enable the supported action buttons. """ - self.__microPython.setActionButtons( + self.microPython.setActionButtons( + open=False, save=False, run=False, repl=False, files=False, chart=False) def forceInterrupt(self): @@ -179,8 +191,9 @@ @return tuple containing a flag indicating it is safe to start a REPL and a reason why it cannot. + @rtype tuple of (bool, str) """ - return False, self.tr("Not implemented") + return False, self.tr("REPL is not supported by this device.") def setRepl(self, on): """ @@ -189,7 +202,65 @@ @param on flag indicating the active status @type bool """ - return + pass + + def canStartPlotter(self): + """ + Public method to determine, if a Plotter can be started. + + @return tuple containing a flag indicating it is safe to start a + Plotter and a reason why it cannot. + @rtype tuple of (bool, str) + """ + return False, self.tr("Plotter is not supported by this device.") + + def setPlotter(self, on): + """ + Public method to set the Plotter status and dependent status. + + @param on flag indicating the active status + @type bool + """ + pass + + def canRunScript(self): + """ + Public method to determine, if a Plotter can be started. + + @return tuple containing a flag indicating it is safe to start a + Plotter and a reason why it cannot. + @rtype tuple of (bool, str) + """ + return False, self.tr("Running scripts is not supported by this" + " device.") + + def runScript(self, script): + """ + Public method to run the given Python script. + + @param script script to be executed + @type str + """ + pass + + def canStartFileManager(self): + """ + Public method to determine, if a File Manager can be started. + + @return tuple containing a flag indicating it is safe to start a + File Manager and a reason why it cannot. + @rtype tuple of (bool, str) + """ + return False, self.tr("File Manager is not supported by this device.") + + def setFileManager(self, on): + """ + Public method to set the File Manager status and dependent status. + + @param on flag indicating the active status + @type bool + """ + pass def getWorkspace(self): """ @@ -198,46 +269,27 @@ @return workspace directory used for saving files @rtype str """ - return "" + return (Preferences.getMultiProject("Workspace") or + os.path.expanduser("~")) - # TODO: are these needed? -## def findDevice(self, deviceType): -## """ -## Public method to find the first device of a specific type. -## -## @param deviceType device type -## @type str -## @return tuple containing the port the device is connected to and its -## serial number -## @rtype tuple of (str, str) -## """ -## from PyQt5.QtSerialPort import QSerialPortInfo -## -## availablePorts = QSerialPortInfo.availablePorts() -## for port in availablePorts: -## vid = port.vendorIdentifier() -## pid = port.productIdentifier() -## for board in SupportedBoards: -## if ((vid, pid) in SupportedBoards[board] or -## (vid, None) in SupportedBoards[board]): -## portName = port.portName() -## serialNumber = port.serialNumber() -## return (self.__portPath(portName), serialNumber) -## -## return (None, None) -## -## def __portPath(self, portName): -## """ -## Private method to get the full path of a given port. -## -## @param portName name of the port the path shall be determined for -## @type str -## @return full port path -## @rtype str -## """ -## if Globals.isWindowsPlatform(): -## # return name unchanged -## return portName -## else: -## # assume Posix system (Linux or macOS) -## return "/dev/{0}".format(portName) + def sendCommands(self, commandsList): + """ + Public method to send a list of commands to the device. + + @param commandsList list of commands to be sent to the device + @type list of str + """ + rawOn = [ # sequence of commands to enter raw mode + b'\x02', + b'\r\x03', + b'\r\x03', + b'\r\x03', + b'\r\x01', + ] + newLine = [b'print("\\n")\r',] + commands = [c.encode("utf-8)") + b'\r' for c in commandsList] + commands.append(b'\r') + commands.append(b'\x04') + rawOff = [b'\x02'] + commandSequence = rawOn + newLine + commands + rawOff + self.microPython.execute(commandSequence)