16 from eric7.EricWidgets import EricMessageBox |
16 from eric7.EricWidgets import EricMessageBox |
17 from eric7.EricWidgets.EricApplication import ericApp |
17 from eric7.EricWidgets.EricApplication import ericApp |
18 from eric7.EricWidgets.EricProcessDialog import EricProcessDialog |
18 from eric7.EricWidgets.EricProcessDialog import EricProcessDialog |
19 from eric7.SystemUtilities import PythonUtilities |
19 from eric7.SystemUtilities import PythonUtilities |
20 |
20 |
|
21 from ..MicroPythonWidget import HAS_QTCHART |
21 from . import FirmwareGithubUrls |
22 from . import FirmwareGithubUrls |
22 from .DeviceBase import BaseDevice |
23 from .DeviceBase import BaseDevice |
23 from ..MicroPythonWidget import HAS_QTCHART |
|
24 |
24 |
25 |
25 |
26 class EspDevice(BaseDevice): |
26 class EspDevice(BaseDevice): |
27 """ |
27 """ |
28 Class implementing the device for ESP32 and ESP8266 based boards. |
28 Class implementing the device for ESP32 and ESP8266 based boards. |
304 def __backupFlash(self): |
304 def __backupFlash(self): |
305 """ |
305 """ |
306 Private slot to backup the currently flashed firmware. |
306 Private slot to backup the currently flashed firmware. |
307 """ |
307 """ |
308 from .EspDialogs.EspBackupRestoreFirmwareDialog import ( |
308 from .EspDialogs.EspBackupRestoreFirmwareDialog import ( |
309 EspBackupRestoreFirmwareDialog |
309 EspBackupRestoreFirmwareDialog, |
310 ) |
310 ) |
311 |
311 |
312 dlg = EspBackupRestoreFirmwareDialog(backupMode=True) |
312 dlg = EspBackupRestoreFirmwareDialog(backupMode=True) |
313 if dlg.exec() == QDialog.DialogCode.Accepted: |
313 if dlg.exec() == QDialog.DialogCode.Accepted: |
314 chip, flashSize, baudRate, flashMode, firmware = dlg.getData() |
314 chip, flashSize, baudRate, flashMode, firmware = dlg.getData() |
340 def __restoreFlash(self): |
340 def __restoreFlash(self): |
341 """ |
341 """ |
342 Private slot to restore a previously saved firmware. |
342 Private slot to restore a previously saved firmware. |
343 """ |
343 """ |
344 from .EspDialogs.EspBackupRestoreFirmwareDialog import ( |
344 from .EspDialogs.EspBackupRestoreFirmwareDialog import ( |
345 EspBackupRestoreFirmwareDialog |
345 EspBackupRestoreFirmwareDialog, |
346 ) |
346 ) |
347 |
347 |
348 dlg = EspBackupRestoreFirmwareDialog(backupMode=False) |
348 dlg = EspBackupRestoreFirmwareDialog(backupMode=False) |
349 if dlg.exec() == QDialog.DialogCode.Accepted: |
349 if dlg.exec() == QDialog.DialogCode.Accepted: |
350 chip, flashSize, baudRate, flashMode, firmware = dlg.getData() |
350 chip, flashSize, baudRate, flashMode, firmware = dlg.getData() |
573 |
573 |
574 @return firmware download URL of the device |
574 @return firmware download URL of the device |
575 @rtype str |
575 @rtype str |
576 """ |
576 """ |
577 return Preferences.getMicroPython("MicroPythonFirmwareUrl") |
577 return Preferences.getMicroPython("MicroPythonFirmwareUrl") |
|
578 |
|
579 ################################################################## |
|
580 ## time related methods below |
|
581 ################################################################## |
|
582 |
|
583 def _getSetTimeCode(self): |
|
584 """ |
|
585 Protected method to get the device code to set the time. |
|
586 |
|
587 Note: This method must be implemented in the various device specific |
|
588 subclasses. |
|
589 |
|
590 @return code to be executed on the connected device to set the time |
|
591 @rtype str |
|
592 """ |
|
593 # rtc_time[0] - year 4 digit |
|
594 # rtc_time[1] - month 1..12 |
|
595 # rtc_time[2] - day 1..31 |
|
596 # rtc_time[3] - weekday 1..7 1=Monday |
|
597 # rtc_time[4] - hour 0..23 |
|
598 # rtc_time[5] - minute 0..59 |
|
599 # rtc_time[6] - second 0..59 |
|
600 # rtc_time[7] - yearday 1..366 |
|
601 # rtc_time[8] - isdst 0, 1, or -1 |
|
602 |
|
603 # The machine.RTC.init() (ESP32) and machine.rtc.datetime() (ESP8266) functions |
|
604 # take the arguments in the order: |
|
605 # (year, month, day, weekday, hour, minute, second, subseconds) |
|
606 # __IGNORE_WARNING_M891__ |
|
607 # https://docs.micropython.org/en/latest/library/machine.RTC.html#machine-rtc |
|
608 # |
|
609 # LoBo variant of MPy deviates. |
|
610 return """ |
|
611 def set_time(rtc_time): |
|
612 import machine |
|
613 rtc = machine.RTC() |
|
614 try: |
|
615 rtc.datetime(rtc_time[:7] + (0,)) |
|
616 except Exception: |
|
617 import os |
|
618 if 'LoBo' in os.uname()[0]: |
|
619 clock_time = rtc_time[:3] + rtc_time[4:7] + (rtc_time[3], rtc_time[7]) |
|
620 else: |
|
621 clock_time = rtc_time[:7] + (0,) |
|
622 rtc.init(clock_time) |
|
623 """ |
578 |
624 |
579 |
625 |
580 def createDevice(microPythonWidget, deviceType, vid, pid, boardName, serialNumber): |
626 def createDevice(microPythonWidget, deviceType, vid, pid, boardName, serialNumber): |
581 """ |
627 """ |
582 Function to instantiate a MicroPython device object. |
628 Function to instantiate a MicroPython device object. |