src/eric7/MicroPython/Devices/TeensyDevices.py

branch
eric7
changeset 9765
6378da868bb0
parent 9763
52f982c08301
child 9820
67597e003373
--- a/src/eric7/MicroPython/Devices/TeensyDevices.py	Tue Feb 14 11:09:49 2023 +0100
+++ b/src/eric7/MicroPython/Devices/TeensyDevices.py	Tue Feb 14 18:10:30 2023 +0100
@@ -15,9 +15,9 @@
 from eric7.EricWidgets import EricMessageBox
 from eric7.EricWidgets.EricApplication import ericApp
 
+from ..MicroPythonWidget import HAS_QTCHART
 from . import FirmwareGithubUrls
 from .DeviceBase import BaseDevice
-from ..MicroPythonWidget import HAS_QTCHART
 
 
 class TeensyDevice(BaseDevice):
@@ -266,6 +266,41 @@
                 ),
             )
 
+    ##################################################################
+    ## 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() function takes the arguments in the
+        # order: (year, month, day, weekday, hour, minute, second,
+        # subseconds)
+        # https://docs.micropython.org/en/latest/library/machine.RTC.html#machine-rtc
+        return """
+def set_time(rtc_time):
+    import machine
+    rtc = machine.RTC()
+    rtc.init(rtc_time[:7] + (0,))
+"""
+
 
 def createDevice(microPythonWidget, deviceType, vid, pid, boardName, serialNumber):
     """

eric ide

mercurial