src/eric7/MicroPython/MicroPythonCommandsInterface.py

branch
eric7
changeset 9751
606ac0e26533
parent 9749
5d409223cf3f
child 9755
1a09700229e7
diff -r 4958dd72c937 -r 606ac0e26533 src/eric7/MicroPython/MicroPythonCommandsInterface.py
--- a/src/eric7/MicroPython/MicroPythonCommandsInterface.py	Thu Feb 09 09:55:57 2023 +0100
+++ b/src/eric7/MicroPython/MicroPythonCommandsInterface.py	Sat Feb 11 16:59:50 2023 +0100
@@ -746,74 +746,55 @@
     ## non-filesystem related methods below
     ##################################################################
 
-    def version(self):
+    def getDeviceData(self):
         """
-        Public method to get the MicroPython version information of the
-        connected device.
+        Public method to get some essential data for the connected board.
 
-        @return dictionary containing the version information
+        @return dictionary containing the determined data
         @rtype dict
         @exception OSError raised to indicate an issue with the device
         """
         commands = [
+            "res = {}",  # __IGNORE_WARNING_M613__
             "import os as __os_",
-            "print(__os_.uname())",
-            "del __os_",
-        ]
-        out, err = self.execute(commands)
-        if err:
-            raise OSError(self.__shortError(err))
-
-        rawOutput = out.decode("utf-8").strip()
-        rawOutput = rawOutput[1:-1]
-        items = rawOutput.split(",")
-        result = {}
-        for item in items:
-            key, value = item.strip().split("=")
-            result[key.strip()] = value.strip()[1:-1]
-        return result
-
-    def getImplementation(self):
-        """
-        Public method to get some implementation information of the connected
-        device.
-
-        @return dictionary containing the implementation information
-        @rtype dict
-        @exception OSError raised to indicate an issue with the device
-        """
-        commands = [
+            "uname = __os_.uname()",
+            "res['sysname'] = uname.sysname",
+            "res['nodename'] = uname.nodename",
+            "res['release'] = uname.release",
+            "res['version'] = uname.version",
+            "res['machine'] = uname.machine",
             "import sys as __sys_",
-            "res = {}",  # __IGNORE_WARNING_M613__
+            "res['py_platform'] = __sys_.platform",
+            "res['py_version'] = __sys_.version",
             "\n".join(
                 [
                     "try:",
-                    "    res['name'] = __sys_.implementation.name",
+                    "    res['mpy_name'] = __sys_.implementation.name",
                     "except AttributeError:",
-                    "    res['name'] = 'unknown'",
+                    "    res['mpy_name'] = 'unknown'",
                 ]
             ),
             "\n".join(
                 [
                     "try:",
-                    "    res['version'] = '.'.join((str(i) for i in"
+                    "    res['mpy_version'] = '.'.join((str(i) for i in"
                     " __sys_.implementation.version))",
                     "except AttributeError:",
-                    "    res['version'] = 'unknown'",
+                    "    res['mpy_version'] = 'unknown'",
                 ]
             ),
             "\n".join(
                 [
                     "try:",
-                    "    import pimoroni",
-                    "    res['variant'] = 'Pimoroni'",
-                    "    del pimoroni",
+                    "    import pimoroni as __pimoroni_",
+                    "    res['mpy_variant'] = 'Pimoroni'",
+                    "    del __pimoroni_",
                     "except ImportError:",
-                    "    res['variant'] = ''",
+                    "    res['mpy_variant'] = ''",
                 ]
             ),
             "print(res)",
-            "del res, __sys_",
+            "del res, __os_, __sys_",
         ]
         out, err = self.execute(commands)
         if err:
@@ -872,9 +853,9 @@
             "\n".join(
                 [
                     "try:",
-                    "    import pimoroni",
+                    "    import pimoroni as __pimoroni_",
                     "    res['mpy_variant'] = 'Pimoroni'",
-                    "    del pimoroni",
+                    "    del __pimoroni_",
                     "except ImportError:",
                     "    res['mpy_variant'] = ''",
                 ]
@@ -944,13 +925,16 @@
             raise OSError(self.__shortError(err))
         return ast.literal_eval(out.decode("utf-8"))
 
-    def syncTime(self, deviceType):
+    def syncTime(self, deviceType, hasCPy=False):
         """
         Public method to set the time of the connected device to the local
         computer's time.
 
         @param deviceType type of board to sync time to
         @type str
+        @param hasCPy flag indicating that the device has CircuitPython loadede
+            (defaults to False)
+        @type bool
         @exception OSError raised to indicate an issue with the device
         """
         # rtc_time[0] - year    4 digit
@@ -962,7 +946,19 @@
         # rtc_time[6] - second  0..59
         # rtc_time[7] - yearday 1..366
         # rtc_time[8] - isdst   0, 1, or -1
-        if deviceType == "pyboard":
+        if deviceType == "circuitpython" or hasCPy:
+            set_time = "\n".join(
+                [
+                    "def set_time(rtc_time):",
+                    "    import rtc",
+                    "    import time",
+                    "    clock = rtc.RTC()",
+                    "    clock_time = rtc_time[:3] + rtc_time[4:7] + (rtc_time[3],"
+                    " rtc_time[7], rtc_time[8])",
+                    "    clock.datetime = time.struct_time(clock_time)",
+                ]
+            )
+        elif deviceType == "pyboard":
             # Pyboard (pyboard doesn't have machine.RTC()).
             # The pyb.RTC.datetime function takes the arguments in the
             # order: (year, month, day, weekday, hour, minute, second,
@@ -998,20 +994,9 @@
                     "        rtc.init(clock_time)",
                 ]
             )
-        elif deviceType == "circuitpython":
-            set_time = "\n".join(
-                [
-                    "def set_time(rtc_time):",
-                    "    import rtc",
-                    "    import time",
-                    "    clock = rtc.RTC()",
-                    "    clock_time = rtc_time[:3] + rtc_time[4:7] + (rtc_time[3],"
-                    " rtc_time[7], rtc_time[8])",
-                    "    clock.datetime = time.struct_time(clock_time)",
-                ]
-            )
         elif deviceType in ("bbc_microbit", "calliope"):
-            # BBC micro:bit and Calliope mini don't support time commands
+            # BBC micro:bit and Calliope mini with MicroPython don't support
+            # time commands.
             return
         elif deviceType == "rp2040":
             # Raspberry Pi Pico (RP2040) - machine.RTC doesn't exist

eric ide

mercurial