src/eric7/MicroPython/Devices/EspDevices.py

branch
eric7
changeset 9765
6378da868bb0
parent 9763
52f982c08301
child 9766
f0e22f3a5878
--- a/src/eric7/MicroPython/Devices/EspDevices.py	Tue Feb 14 11:09:49 2023 +0100
+++ b/src/eric7/MicroPython/Devices/EspDevices.py	Tue Feb 14 18:10:30 2023 +0100
@@ -18,9 +18,9 @@
 from eric7.EricWidgets.EricProcessDialog import EricProcessDialog
 from eric7.SystemUtilities import PythonUtilities
 
+from ..MicroPythonWidget import HAS_QTCHART
 from . import FirmwareGithubUrls
 from .DeviceBase import BaseDevice
-from ..MicroPythonWidget import HAS_QTCHART
 
 
 class EspDevice(BaseDevice):
@@ -306,7 +306,7 @@
         Private slot to backup the currently flashed firmware.
         """
         from .EspDialogs.EspBackupRestoreFirmwareDialog import (
-            EspBackupRestoreFirmwareDialog
+            EspBackupRestoreFirmwareDialog,
         )
 
         dlg = EspBackupRestoreFirmwareDialog(backupMode=True)
@@ -342,7 +342,7 @@
         Private slot to restore a previously saved firmware.
         """
         from .EspDialogs.EspBackupRestoreFirmwareDialog import (
-            EspBackupRestoreFirmwareDialog
+            EspBackupRestoreFirmwareDialog,
         )
 
         dlg = EspBackupRestoreFirmwareDialog(backupMode=False)
@@ -525,7 +525,7 @@
         Private slot to reset the connected device.
         """
         if self.microPython.isConnected():
-            self.microPython.commandsInterface().execute(
+            self.microPython.deviceInterface().execute(
                 [
                     "import machine",
                     "machine.reset()",
@@ -576,6 +576,52 @@
         """
         return Preferences.getMicroPython("MicroPythonFirmwareUrl")
 
+    ##################################################################
+    ## time related methods below
+    ##################################################################
+
+    def _getSetTimeCode(self):
+        """
+        Protected method to get the device code to set the time.
+
+        Note: This method must be implemented in the various device specific
+        subclasses.
+
+        @return code to be executed on the connected device to set the time
+        @rtype str
+        """
+        # rtc_time[0] - year    4 digit
+        # rtc_time[1] - month   1..12
+        # rtc_time[2] - day     1..31
+        # rtc_time[3] - weekday 1..7 1=Monday
+        # rtc_time[4] - hour    0..23
+        # rtc_time[5] - minute  0..59
+        # rtc_time[6] - second  0..59
+        # rtc_time[7] - yearday 1..366
+        # rtc_time[8] - isdst   0, 1, or -1
+
+        # The machine.RTC.init() (ESP32) and machine.rtc.datetime() (ESP8266) functions
+        # take the arguments in the order:
+        # (year, month, day, weekday, hour, minute, second, subseconds)
+        # __IGNORE_WARNING_M891__
+        # https://docs.micropython.org/en/latest/library/machine.RTC.html#machine-rtc
+        #
+        # LoBo variant of MPy deviates.
+        return """
+def set_time(rtc_time):
+    import machine
+    rtc = machine.RTC()
+    try:
+        rtc.datetime(rtc_time[:7] + (0,))
+    except Exception:
+        import os
+        if 'LoBo' in os.uname()[0]:
+            clock_time = rtc_time[:3] + rtc_time[4:7] + (rtc_time[3], rtc_time[7])
+        else:
+            clock_time = rtc_time[:7] + (0,)
+        rtc.init(clock_time)
+"""
+
 
 def createDevice(microPythonWidget, deviceType, vid, pid, boardName, serialNumber):
     """

eric ide

mercurial