eric6/MicroPython/CircuitPythonDevices.py

changeset 8072
58491f4c99d6
parent 8067
a467ab075be0
child 8096
5425a9072300
--- a/eric6/MicroPython/CircuitPythonDevices.py	Thu Feb 04 15:18:40 2021 +0100
+++ b/eric6/MicroPython/CircuitPythonDevices.py	Thu Feb 04 20:15:06 2021 +0100
@@ -40,6 +40,10 @@
         super(CircuitPythonDevice, self).__init__(microPythonWidget, parent)
         
         self.__workspace = self.__findWorkspace()
+        
+        self.__nonUF2devices = {
+            "teensy": self.__flashTeensy,
+        }
     
     def setButtons(self):
         """
@@ -137,7 +141,9 @@
         @return flag indicated a mounted device
         @rtype bool
         """
-        self.__workspace = ""       # reset before checking
+        if self.__workspace and not os.path.exists(self.__workspace):
+            self.__workspace = ""       # reset
+        
         return self.DeviceVolumeName in self.getWorkspace(silent=True)
     
     def getWorkspace(self, silent=False):
@@ -213,21 +219,44 @@
         """
         Private slot to flash a CircuitPython firmware to the device.
         """
-        button = E5MessageBox.information(
+        lBoardName = self.microPython.getCurrentBoard().lower()
+        if lBoardName:
+            for name in self.__nonUF2devices:
+                if name in lBoardName:
+                    self.__nonUF2devices[name]()
+                    break
+            else:
+                button = E5MessageBox.information(
+                    self.microPython,
+                    self.tr("Flash CircuitPython Firmware"),
+                    self.tr("Please reset the device to bootloader mode and"
+                            " confirm when ready."),
+                    E5MessageBox.StandardButtons(
+                        E5MessageBox.Abort |
+                        E5MessageBox.Ok))
+                if button == E5MessageBox.Ok:
+                    from .CircuitPythonFirmwareSelectionDialog import (
+                        CircuitPythonFirmwareSelectionDialog)
+                    dlg = CircuitPythonFirmwareSelectionDialog()
+                    if dlg.exec() == QDialog.Accepted:
+                        cpyPath, devicePath = dlg.getData()
+                        shutil.copy2(cpyPath, devicePath)
+    
+    def __flashTeensy(self):
+        """
+        Private method to show a message box because Teens does not support
+        the UF2 bootloader yet.
+        """
+        E5MessageBox.information(
             self.microPython,
             self.tr("Flash CircuitPython Firmware"),
-            self.tr("Please reset the device to bootloader mode and confirm"
-                    " when ready."),
-            E5MessageBox.StandardButtons(
-                E5MessageBox.Abort |
-                E5MessageBox.Ok))
-        if button == E5MessageBox.Ok:
-            from .CircuitPythonFirmwareSelectionDialog import (
-                CircuitPythonFirmwareSelectionDialog)
-            dlg = CircuitPythonFirmwareSelectionDialog()
-            if dlg.exec() == QDialog.Accepted:
-                cpyPath, devicePath = dlg.getData()
-                shutil.copy2(cpyPath, devicePath)
+            self.tr("""<p>Teensy 4.0 and Teensy 4.1 do not support the UF2"""
+                    """ bootloader. Please use the 'Teensy Loader'"""
+                    """ application to flash CircuitPython. Make sure you"""
+                    """ downloaded the CircuitPython .hex file.</p>"""
+                    """<p>See <a href="{0}">the PJRC Teensy web site</a>"""
+                    """ for details.</p>""")
+            .format("https://www.pjrc.com/teensy/loader.html"))
     
     @pyqtSlot()
     def __installLibraryFiles(self):

eric ide

mercurial