Sun, 03 Nov 2024 17:50:34 +0100
Extended the EricMessageBox module to determine a parent widget if none was given and extended the EricApplication class to store a reference to the main widget.
7059
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
1 | # -*- coding: utf-8 -*- |
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
2 | |
10439
21c28b0f9e41
Updated copyright for 2024.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10329
diff
changeset
|
3 | # Copyright (c) 2019 - 2024 Detlev Offenbach <detlev@die-offenbachs.de> |
7059
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
4 | # |
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
5 | |
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
6 | """ |
8119
1653972f2de5
EspDevices: fixed a typo and a little issue.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8117
diff
changeset
|
7 | Module implementing the device interface class for ESP32 and ESP8266 based |
1653972f2de5
EspDevices: fixed a typo and a little issue.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8117
diff
changeset
|
8 | boards. |
7059
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
9 | """ |
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
10 | |
9795 | 11 | import ast |
12 | import binascii | |
13 | import json | |
14 | import os | |
15 | ||
9820 | 16 | from PyQt6.QtCore import QCoreApplication, QProcess, QUrl, pyqtSlot |
17 | from PyQt6.QtNetwork import QNetworkReply, QNetworkRequest | |
9752
2b9546c0cbd9
Moved the MicroPython board specific functions to a separate submenu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9751
diff
changeset
|
18 | from PyQt6.QtWidgets import QDialog, QMenu |
7108
4f6133a01c6a
Started rearranging menu structure and testing and fixing on CircuitPython.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7100
diff
changeset
|
19 | |
10806
2f6df822e3b9
Moved some functions to the EricUtilities package for consistency and adapted the code base accordingly.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10683
diff
changeset
|
20 | from eric7 import EricUtilities, Preferences |
9795 | 21 | from eric7.EricGui.EricOverrideCursor import EricOverrideCursor |
9413
80c06d472826
Changed the eric7 import statements to include the package name (i.e. eric7) in order to not fiddle with sys.path.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9221
diff
changeset
|
22 | from eric7.EricWidgets import EricMessageBox |
9473
3f23dbf37dbe
Resorted the import statements using isort.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9413
diff
changeset
|
23 | from eric7.EricWidgets.EricApplication import ericApp |
9413
80c06d472826
Changed the eric7 import statements to include the package name (i.e. eric7) in order to not fiddle with sys.path.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9221
diff
changeset
|
24 | from eric7.EricWidgets.EricProcessDialog import EricProcessDialog |
9624
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9576
diff
changeset
|
25 | from eric7.SystemUtilities import PythonUtilities |
7065
e3d04faced34
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7059
diff
changeset
|
26 | |
9765
6378da868bb0
Reorganized the MicroPython code even more.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
27 | from ..MicroPythonWidget import HAS_QTCHART |
9756
9854647c8c5c
Reorganized the MicroPython package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9752
diff
changeset
|
28 | from . import FirmwareGithubUrls |
9870
0399d3607829
Fixed a few code formatting and style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9868
diff
changeset
|
29 | from .CircuitPythonDevices import CircuitPythonDevice |
9756
9854647c8c5c
Reorganized the MicroPython package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9752
diff
changeset
|
30 | from .DeviceBase import BaseDevice |
7059
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
31 | |
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
32 | |
9756
9854647c8c5c
Reorganized the MicroPython package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9752
diff
changeset
|
33 | class EspDevice(BaseDevice): |
7059
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
34 | """ |
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
35 | Class implementing the device for ESP32 and ESP8266 based boards. |
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
36 | """ |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
37 | |
8117
aaa5e0eacd4e
MicroPython: changed the logic to synchronize the time because some devices don't implement long integer and failed defining the 'set_time()' function.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8096
diff
changeset
|
38 | def __init__(self, microPythonWidget, deviceType, parent=None): |
7059
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
39 | """ |
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
40 | Constructor |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
41 | |
7059
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
42 | @param microPythonWidget reference to the main MicroPython widget |
7134
21d23ca51680
Renamed "MicroPythonReplWidget" to "MicroPythonWidget".
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7125
diff
changeset
|
43 | @type MicroPythonWidget |
8117
aaa5e0eacd4e
MicroPython: changed the logic to synchronize the time because some devices don't implement long integer and failed defining the 'set_time()' function.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8096
diff
changeset
|
44 | @param deviceType device type assigned to this device interface |
aaa5e0eacd4e
MicroPython: changed the logic to synchronize the time because some devices don't implement long integer and failed defining the 'set_time()' function.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8096
diff
changeset
|
45 | @type str |
7059
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
46 | @param parent reference to the parent object |
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
47 | @type QObject |
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
48 | """ |
8218
7c09585bd960
Applied some more code simplifications suggested by the new Simplify checker (super(Foo, self) => super()).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8205
diff
changeset
|
49 | super().__init__(microPythonWidget, deviceType, parent) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
50 | |
9752
2b9546c0cbd9
Moved the MicroPython board specific functions to a separate submenu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9751
diff
changeset
|
51 | self.__createEsp32Submenu() |
2b9546c0cbd9
Moved the MicroPython board specific functions to a separate submenu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9751
diff
changeset
|
52 | |
9866 | 53 | self.__cpyDevice = None |
54 | # needed to delegate some methods to a CircuitPython variant | |
55 | ||
9795 | 56 | self.__statusTranslations = { |
57 | 200: self.tr("beacon timeout"), | |
58 | 201: self.tr("no matching access point found"), | |
59 | 202: self.tr("authentication failed"), | |
60 | 203: self.tr("association failed"), | |
61 | 204: self.tr("handshake timeout"), | |
62 | 1000: self.tr("idle"), | |
63 | 1001: self.tr("connecting"), | |
64 | 1010: self.tr("connected"), | |
65 | } | |
66 | self.__securityTranslations = { | |
67 | 0: self.tr("open", "open WiFi network"), | |
68 | 1: "WEP", | |
69 | 2: "WPA", | |
70 | 3: "WPA2", | |
71 | 4: "WPA/WPA2", | |
72 | 5: "WPA2 (CCMP)", | |
73 | 6: "WPA3", | |
74 | 7: "WPA2/WPA3", | |
75 | } | |
76 | ||
9866 | 77 | def __createCpyDevice(self): |
78 | """ | |
79 | Private method to create a CircuitPython device interface. | |
80 | """ | |
81 | if self.hasCircuitPython() and self.__cpyDevice is None: | |
82 | self.__cpyDevice = CircuitPythonDevice( | |
83 | self.microPython, | |
84 | "esp32_circuitpython", | |
85 | "esp32", | |
86 | hasWorkspace=False, | |
87 | parent=self.parent(), | |
88 | ) | |
10329 | 89 | self.__cpyDevice.setConnected(True) |
9866 | 90 | |
91 | def setConnected(self, connected): | |
92 | """ | |
93 | Public method to set the connection state. | |
94 | ||
95 | Note: This method can be overwritten to perform actions upon connect | |
96 | or disconnect of the device. | |
97 | ||
98 | @param connected connection state | |
99 | @type bool | |
100 | """ | |
101 | super().setConnected(connected) | |
102 | ||
103 | if self.hasCircuitPython(): | |
104 | self._submitMode = "paste" | |
105 | self.__createCpyDevice() | |
106 | ||
7059
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
107 | def setButtons(self): |
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
108 | """ |
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
109 | Public method to enable the supported action buttons. |
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
110 | """ |
8218
7c09585bd960
Applied some more code simplifications suggested by the new Simplify checker (super(Foo, self) => super()).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8205
diff
changeset
|
111 | super().setButtons() |
9763
52f982c08301
Removed the 'Open' and 'Save' buttons from the MicroPython widget and made the repl and file manager start automatically upon connecting to the selected device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9756
diff
changeset
|
112 | |
7059
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
113 | self.microPython.setActionButtons( |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
114 | run=True, repl=True, files=True, chart=HAS_QTCHART |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
115 | ) |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
116 | |
7059
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
117 | def forceInterrupt(self): |
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
118 | """ |
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
119 | Public method to determine the need for an interrupt when opening the |
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
120 | serial connection. |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
121 | |
7059
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
122 | @return flag indicating an interrupt is needed |
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
123 | @rtype bool |
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
124 | """ |
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
125 | return True |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
126 | |
7125
2028553ee58c
CircuitPythonDevices, EspDevices, MicroPythonDevices: added a method to get the device name.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7115
diff
changeset
|
127 | def deviceName(self): |
2028553ee58c
CircuitPythonDevices, EspDevices, MicroPythonDevices: added a method to get the device name.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7115
diff
changeset
|
128 | """ |
2028553ee58c
CircuitPythonDevices, EspDevices, MicroPythonDevices: added a method to get the device name.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7115
diff
changeset
|
129 | Public method to get the name of the device. |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
130 | |
7125
2028553ee58c
CircuitPythonDevices, EspDevices, MicroPythonDevices: added a method to get the device name.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7115
diff
changeset
|
131 | @return name of the device |
2028553ee58c
CircuitPythonDevices, EspDevices, MicroPythonDevices: added a method to get the device name.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7115
diff
changeset
|
132 | @rtype str |
2028553ee58c
CircuitPythonDevices, EspDevices, MicroPythonDevices: added a method to get the device name.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7115
diff
changeset
|
133 | """ |
2028553ee58c
CircuitPythonDevices, EspDevices, MicroPythonDevices: added a method to get the device name.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7115
diff
changeset
|
134 | return self.tr("ESP8266, ESP32") |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
135 | |
7059
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
136 | def canStartRepl(self): |
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
137 | """ |
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
138 | Public method to determine, if a REPL can be started. |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
139 | |
7059
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
140 | @return tuple containing a flag indicating it is safe to start a REPL |
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
141 | and a reason why it cannot. |
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
142 | @rtype tuple of (bool, str) |
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
143 | """ |
7095
8e10acb1cd85
Refactored and improved the MicroPython code to be able to show the file manager and the REPL simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7091
diff
changeset
|
144 | return True, "" |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
145 | |
7059
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
146 | def canStartPlotter(self): |
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
147 | """ |
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
148 | Public method to determine, if a Plotter can be started. |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
149 | |
7059
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
150 | @return tuple containing a flag indicating it is safe to start a |
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
151 | Plotter and a reason why it cannot. |
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
152 | @rtype tuple of (bool, str) |
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
153 | """ |
7095
8e10acb1cd85
Refactored and improved the MicroPython code to be able to show the file manager and the REPL simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7091
diff
changeset
|
154 | return True, "" |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
155 | |
7059
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
156 | def canRunScript(self): |
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
157 | """ |
7091
84d2a73b448a
EspDevices, MicroPythonDevices: fixed a wrong source docu string.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7077
diff
changeset
|
158 | Public method to determine, if a script can be executed. |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
159 | |
7059
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
160 | @return tuple containing a flag indicating it is safe to start a |
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
161 | Plotter and a reason why it cannot. |
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
162 | @rtype tuple of (bool, str) |
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
163 | """ |
8119
1653972f2de5
EspDevices: fixed a typo and a little issue.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8117
diff
changeset
|
164 | return True, "" |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
165 | |
7059
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
166 | def runScript(self, script): |
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
167 | """ |
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
168 | Public method to run the given Python script. |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
169 | |
7059
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
170 | @param script script to be executed |
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
171 | @type str |
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
172 | """ |
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
173 | pythonScript = script.split("\n") |
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
174 | self.sendCommands(pythonScript) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
175 | |
7059
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
176 | def canStartFileManager(self): |
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
177 | """ |
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
178 | Public method to determine, if a File Manager can be started. |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
179 | |
7059
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
180 | @return tuple containing a flag indicating it is safe to start a |
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
181 | File Manager and a reason why it cannot. |
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
182 | @rtype tuple of (bool, str) |
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
183 | """ |
7095
8e10acb1cd85
Refactored and improved the MicroPython code to be able to show the file manager and the REPL simultaneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7091
diff
changeset
|
184 | return True, "" |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
185 | |
9752
2b9546c0cbd9
Moved the MicroPython board specific functions to a separate submenu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9751
diff
changeset
|
186 | def __createEsp32Submenu(self): |
2b9546c0cbd9
Moved the MicroPython board specific functions to a separate submenu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9751
diff
changeset
|
187 | """ |
2b9546c0cbd9
Moved the MicroPython board specific functions to a separate submenu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9751
diff
changeset
|
188 | Private method to create the ESP32 submenu. |
2b9546c0cbd9
Moved the MicroPython board specific functions to a separate submenu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9751
diff
changeset
|
189 | """ |
2b9546c0cbd9
Moved the MicroPython board specific functions to a separate submenu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9751
diff
changeset
|
190 | self.__espMenu = QMenu(self.tr("ESP32 Functions")) |
2b9546c0cbd9
Moved the MicroPython board specific functions to a separate submenu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9751
diff
changeset
|
191 | |
2b9546c0cbd9
Moved the MicroPython board specific functions to a separate submenu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9751
diff
changeset
|
192 | self.__showMpyAct = self.__espMenu.addAction( |
2b9546c0cbd9
Moved the MicroPython board specific functions to a separate submenu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9751
diff
changeset
|
193 | self.tr("Show MicroPython Versions"), self.__showFirmwareVersions |
2b9546c0cbd9
Moved the MicroPython board specific functions to a separate submenu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9751
diff
changeset
|
194 | ) |
2b9546c0cbd9
Moved the MicroPython board specific functions to a separate submenu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9751
diff
changeset
|
195 | self.__espMenu.addSeparator() |
2b9546c0cbd9
Moved the MicroPython board specific functions to a separate submenu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9751
diff
changeset
|
196 | self.__eraseFlashAct = self.__espMenu.addAction( |
2b9546c0cbd9
Moved the MicroPython board specific functions to a separate submenu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9751
diff
changeset
|
197 | self.tr("Erase Flash"), self.__eraseFlash |
2b9546c0cbd9
Moved the MicroPython board specific functions to a separate submenu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9751
diff
changeset
|
198 | ) |
2b9546c0cbd9
Moved the MicroPython board specific functions to a separate submenu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9751
diff
changeset
|
199 | self.__flashMpyAct = self.__espMenu.addAction( |
2b9546c0cbd9
Moved the MicroPython board specific functions to a separate submenu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9751
diff
changeset
|
200 | self.tr("Flash MicroPython Firmware"), self.__flashMicroPython |
2b9546c0cbd9
Moved the MicroPython board specific functions to a separate submenu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9751
diff
changeset
|
201 | ) |
2b9546c0cbd9
Moved the MicroPython board specific functions to a separate submenu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9751
diff
changeset
|
202 | self.__espMenu.addSeparator() |
2b9546c0cbd9
Moved the MicroPython board specific functions to a separate submenu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9751
diff
changeset
|
203 | self.__flashAdditionalAct = self.__espMenu.addAction( |
2b9546c0cbd9
Moved the MicroPython board specific functions to a separate submenu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9751
diff
changeset
|
204 | self.tr("Flash Additional Firmware"), self.__flashAddons |
2b9546c0cbd9
Moved the MicroPython board specific functions to a separate submenu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9751
diff
changeset
|
205 | ) |
2b9546c0cbd9
Moved the MicroPython board specific functions to a separate submenu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9751
diff
changeset
|
206 | self.__espMenu.addSeparator() |
2b9546c0cbd9
Moved the MicroPython board specific functions to a separate submenu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9751
diff
changeset
|
207 | self.__backupAct = self.__espMenu.addAction( |
2b9546c0cbd9
Moved the MicroPython board specific functions to a separate submenu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9751
diff
changeset
|
208 | self.tr("Backup Firmware"), self.__backupFlash |
2b9546c0cbd9
Moved the MicroPython board specific functions to a separate submenu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9751
diff
changeset
|
209 | ) |
2b9546c0cbd9
Moved the MicroPython board specific functions to a separate submenu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9751
diff
changeset
|
210 | self.__restoreAct = self.__espMenu.addAction( |
2b9546c0cbd9
Moved the MicroPython board specific functions to a separate submenu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9751
diff
changeset
|
211 | self.tr("Restore Firmware"), self.__restoreFlash |
2b9546c0cbd9
Moved the MicroPython board specific functions to a separate submenu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9751
diff
changeset
|
212 | ) |
2b9546c0cbd9
Moved the MicroPython board specific functions to a separate submenu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9751
diff
changeset
|
213 | self.__espMenu.addSeparator() |
2b9546c0cbd9
Moved the MicroPython board specific functions to a separate submenu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9751
diff
changeset
|
214 | self.__chipIdAct = self.__espMenu.addAction( |
2b9546c0cbd9
Moved the MicroPython board specific functions to a separate submenu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9751
diff
changeset
|
215 | self.tr("Show Chip ID"), self.__showChipID |
2b9546c0cbd9
Moved the MicroPython board specific functions to a separate submenu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9751
diff
changeset
|
216 | ) |
2b9546c0cbd9
Moved the MicroPython board specific functions to a separate submenu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9751
diff
changeset
|
217 | self.__flashIdAct = self.__espMenu.addAction( |
2b9546c0cbd9
Moved the MicroPython board specific functions to a separate submenu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9751
diff
changeset
|
218 | self.tr("Show Flash ID"), self.__showFlashID |
2b9546c0cbd9
Moved the MicroPython board specific functions to a separate submenu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9751
diff
changeset
|
219 | ) |
2b9546c0cbd9
Moved the MicroPython board specific functions to a separate submenu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9751
diff
changeset
|
220 | self.__macAddressAct = self.__espMenu.addAction( |
2b9546c0cbd9
Moved the MicroPython board specific functions to a separate submenu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9751
diff
changeset
|
221 | self.tr("Show MAC Address"), self.__showMACAddress |
2b9546c0cbd9
Moved the MicroPython board specific functions to a separate submenu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9751
diff
changeset
|
222 | ) |
2b9546c0cbd9
Moved the MicroPython board specific functions to a separate submenu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9751
diff
changeset
|
223 | self.__espMenu.addSeparator() |
2b9546c0cbd9
Moved the MicroPython board specific functions to a separate submenu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9751
diff
changeset
|
224 | self.__resetAct = self.__espMenu.addAction( |
2b9546c0cbd9
Moved the MicroPython board specific functions to a separate submenu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9751
diff
changeset
|
225 | self.tr("Reset Device"), self.__resetDevice |
2b9546c0cbd9
Moved the MicroPython board specific functions to a separate submenu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9751
diff
changeset
|
226 | ) |
2b9546c0cbd9
Moved the MicroPython board specific functions to a separate submenu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9751
diff
changeset
|
227 | self.__espMenu.addSeparator() |
2b9546c0cbd9
Moved the MicroPython board specific functions to a separate submenu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9751
diff
changeset
|
228 | self.__espMenu.addAction(self.tr("Install 'esptool.py'"), self.__installEspTool) |
2b9546c0cbd9
Moved the MicroPython board specific functions to a separate submenu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9751
diff
changeset
|
229 | |
7108
4f6133a01c6a
Started rearranging menu structure and testing and fixing on CircuitPython.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7100
diff
changeset
|
230 | def addDeviceMenuEntries(self, menu): |
4f6133a01c6a
Started rearranging menu structure and testing and fixing on CircuitPython.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7100
diff
changeset
|
231 | """ |
4f6133a01c6a
Started rearranging menu structure and testing and fixing on CircuitPython.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7100
diff
changeset
|
232 | Public method to add device specific entries to the given menu. |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
233 | |
7108
4f6133a01c6a
Started rearranging menu structure and testing and fixing on CircuitPython.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7100
diff
changeset
|
234 | @param menu reference to the context menu |
4f6133a01c6a
Started rearranging menu structure and testing and fixing on CircuitPython.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7100
diff
changeset
|
235 | @type QMenu |
4f6133a01c6a
Started rearranging menu structure and testing and fixing on CircuitPython.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7100
diff
changeset
|
236 | """ |
4f6133a01c6a
Started rearranging menu structure and testing and fixing on CircuitPython.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7100
diff
changeset
|
237 | connected = self.microPython.isConnected() |
9749 | 238 | linkConnected = self.microPython.isLinkConnected() |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
239 | |
9752
2b9546c0cbd9
Moved the MicroPython board specific functions to a separate submenu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9751
diff
changeset
|
240 | self.__showMpyAct.setEnabled(connected) |
2b9546c0cbd9
Moved the MicroPython board specific functions to a separate submenu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9751
diff
changeset
|
241 | self.__eraseFlashAct.setEnabled(not linkConnected) |
2b9546c0cbd9
Moved the MicroPython board specific functions to a separate submenu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9751
diff
changeset
|
242 | self.__flashMpyAct.setEnabled(not linkConnected) |
2b9546c0cbd9
Moved the MicroPython board specific functions to a separate submenu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9751
diff
changeset
|
243 | self.__flashAdditionalAct.setEnabled(not linkConnected) |
2b9546c0cbd9
Moved the MicroPython board specific functions to a separate submenu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9751
diff
changeset
|
244 | self.__backupAct.setEnabled(not linkConnected) |
2b9546c0cbd9
Moved the MicroPython board specific functions to a separate submenu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9751
diff
changeset
|
245 | self.__restoreAct.setEnabled(not linkConnected) |
2b9546c0cbd9
Moved the MicroPython board specific functions to a separate submenu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9751
diff
changeset
|
246 | self.__chipIdAct.setEnabled(not linkConnected) |
2b9546c0cbd9
Moved the MicroPython board specific functions to a separate submenu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9751
diff
changeset
|
247 | self.__flashIdAct.setEnabled(not linkConnected) |
2b9546c0cbd9
Moved the MicroPython board specific functions to a separate submenu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9751
diff
changeset
|
248 | self.__macAddressAct.setEnabled(not linkConnected) |
2b9546c0cbd9
Moved the MicroPython board specific functions to a separate submenu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9751
diff
changeset
|
249 | self.__resetAct.setEnabled(connected or not linkConnected) |
2b9546c0cbd9
Moved the MicroPython board specific functions to a separate submenu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9751
diff
changeset
|
250 | |
2b9546c0cbd9
Moved the MicroPython board specific functions to a separate submenu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9751
diff
changeset
|
251 | menu.addMenu(self.__espMenu) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
252 | |
8096 | 253 | def hasFlashMenuEntry(self): |
254 | """ | |
255 | Public method to check, if the device has its own flash menu entry. | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
256 | |
8096 | 257 | @return flag indicating a specific flash menu entry |
258 | @rtype bool | |
259 | """ | |
260 | return True | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
261 | |
7108
4f6133a01c6a
Started rearranging menu structure and testing and fixing on CircuitPython.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7100
diff
changeset
|
262 | @pyqtSlot() |
4f6133a01c6a
Started rearranging menu structure and testing and fixing on CircuitPython.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7100
diff
changeset
|
263 | def __eraseFlash(self): |
4f6133a01c6a
Started rearranging menu structure and testing and fixing on CircuitPython.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7100
diff
changeset
|
264 | """ |
4f6133a01c6a
Started rearranging menu structure and testing and fixing on CircuitPython.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7100
diff
changeset
|
265 | Private slot to erase the device flash memory. |
4f6133a01c6a
Started rearranging menu structure and testing and fixing on CircuitPython.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7100
diff
changeset
|
266 | """ |
11006
a671918232f3
Modified modal dialog usage to always include a valid parent (needed for Wayland).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11005
diff
changeset
|
267 | eraseFlash(self.microPython.getCurrentPort(), parent=self.microPython) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
268 | |
7108
4f6133a01c6a
Started rearranging menu structure and testing and fixing on CircuitPython.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7100
diff
changeset
|
269 | @pyqtSlot() |
4f6133a01c6a
Started rearranging menu structure and testing and fixing on CircuitPython.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7100
diff
changeset
|
270 | def __flashMicroPython(self): |
4f6133a01c6a
Started rearranging menu structure and testing and fixing on CircuitPython.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7100
diff
changeset
|
271 | """ |
4f6133a01c6a
Started rearranging menu structure and testing and fixing on CircuitPython.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7100
diff
changeset
|
272 | Private slot to flash a MicroPython firmware to the device. |
4f6133a01c6a
Started rearranging menu structure and testing and fixing on CircuitPython.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7100
diff
changeset
|
273 | """ |
11005
b918c6c2736b
MicroPython Interface
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10933
diff
changeset
|
274 | flashPythonFirmware(self.microPython.getCurrentPort(), parent=self.microPython) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
275 | |
7108
4f6133a01c6a
Started rearranging menu structure and testing and fixing on CircuitPython.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7100
diff
changeset
|
276 | @pyqtSlot() |
4f6133a01c6a
Started rearranging menu structure and testing and fixing on CircuitPython.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7100
diff
changeset
|
277 | def __flashAddons(self): |
4f6133a01c6a
Started rearranging menu structure and testing and fixing on CircuitPython.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7100
diff
changeset
|
278 | """ |
4f6133a01c6a
Started rearranging menu structure and testing and fixing on CircuitPython.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7100
diff
changeset
|
279 | Private slot to flash some additional firmware images. |
4f6133a01c6a
Started rearranging menu structure and testing and fixing on CircuitPython.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7100
diff
changeset
|
280 | """ |
11005
b918c6c2736b
MicroPython Interface
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10933
diff
changeset
|
281 | flashAddonFirmware(self.microPython.getCurrentPort(), parent=self.microPython) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
282 | |
7108
4f6133a01c6a
Started rearranging menu structure and testing and fixing on CircuitPython.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7100
diff
changeset
|
283 | @pyqtSlot() |
7352 | 284 | def __backupFlash(self): |
285 | """ | |
286 | Private slot to backup the currently flashed firmware. | |
287 | """ | |
9756
9854647c8c5c
Reorganized the MicroPython package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9752
diff
changeset
|
288 | from .EspDialogs.EspBackupRestoreFirmwareDialog import ( |
9765
6378da868bb0
Reorganized the MicroPython code even more.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
289 | EspBackupRestoreFirmwareDialog, |
9756
9854647c8c5c
Reorganized the MicroPython package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9752
diff
changeset
|
290 | ) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
291 | |
11005
b918c6c2736b
MicroPython Interface
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10933
diff
changeset
|
292 | dlg = EspBackupRestoreFirmwareDialog(backupMode=True, parent=self.microPython) |
8143
2c730d5fd177
Changed the use of PyQt enums because the way they were used previously is deprecated since two years and replaced some deprecated Qt stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8119
diff
changeset
|
293 | if dlg.exec() == QDialog.DialogCode.Accepted: |
8945 | 294 | chip, flashSize, baudRate, flashMode, firmware = dlg.getData() |
7352 | 295 | flashArgs = [ |
296 | "-u", | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
297 | "-m", |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
298 | "esptool", |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
299 | "--chip", |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
300 | chip, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
301 | "--port", |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
302 | self.microPython.getCurrentPort(), |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
303 | "--baud", |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
304 | baudRate, |
7352 | 305 | "read_flash", |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
306 | "0x0", |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
307 | flashSize, |
7352 | 308 | firmware, |
309 | ] | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
310 | dlg = EricProcessDialog( |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
311 | self.tr("'esptool read_flash' Output"), |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
312 | self.tr("Backup Firmware"), |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
313 | showProgress=True, |
10933
95a15b70f7bb
Refactored some packages, modules and code to allow extracting the 'EricXxx' packages into a library project.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10806
diff
changeset
|
314 | monospacedFont=Preferences.getEditorOtherFonts("MonospacedFont"), |
95a15b70f7bb
Refactored some packages, modules and code to allow extracting the 'EricXxx' packages into a library project.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10806
diff
changeset
|
315 | encoding=Preferences.getSystem("IOEncoding"), |
11006
a671918232f3
Modified modal dialog usage to always include a valid parent (needed for Wayland).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11005
diff
changeset
|
316 | parent=self.microPython, |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
317 | ) |
9624
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9576
diff
changeset
|
318 | res = dlg.startProcess(PythonUtilities.getPythonExecutable(), flashArgs) |
7352 | 319 | if res: |
7759
51aa6c6b66f7
Changed calls to exec_() into exec() (remainder of Python2 elimination).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7595
diff
changeset
|
320 | dlg.exec() |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
321 | |
7352 | 322 | @pyqtSlot() |
323 | def __restoreFlash(self): | |
324 | """ | |
325 | Private slot to restore a previously saved firmware. | |
326 | """ | |
9756
9854647c8c5c
Reorganized the MicroPython package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9752
diff
changeset
|
327 | from .EspDialogs.EspBackupRestoreFirmwareDialog import ( |
9765
6378da868bb0
Reorganized the MicroPython code even more.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
328 | EspBackupRestoreFirmwareDialog, |
9756
9854647c8c5c
Reorganized the MicroPython package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9752
diff
changeset
|
329 | ) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
330 | |
11005
b918c6c2736b
MicroPython Interface
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10933
diff
changeset
|
331 | dlg = EspBackupRestoreFirmwareDialog(backupMode=False, parent=self.microPython) |
8143
2c730d5fd177
Changed the use of PyQt enums because the way they were used previously is deprecated since two years and replaced some deprecated Qt stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8119
diff
changeset
|
332 | if dlg.exec() == QDialog.DialogCode.Accepted: |
8945 | 333 | chip, flashSize, baudRate, flashMode, firmware = dlg.getData() |
7352 | 334 | flashArgs = [ |
335 | "-u", | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
336 | "-m", |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
337 | "esptool", |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
338 | "--chip", |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
339 | chip, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
340 | "--port", |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
341 | self.microPython.getCurrentPort(), |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
342 | "--baud", |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
343 | baudRate, |
7352 | 344 | "write_flash", |
345 | ] | |
8945 | 346 | if flashMode: |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
347 | flashArgs.extend( |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
348 | [ |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
349 | "--flash_mode", |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
350 | flashMode, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
351 | ] |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
352 | ) |
7352 | 353 | if bool(flashSize): |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
354 | flashArgs.extend( |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
355 | [ |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
356 | "--flash_size", |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
357 | flashSize, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
358 | ] |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
359 | ) |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
360 | flashArgs.extend( |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
361 | [ |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
362 | "0x0", |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
363 | firmware, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
364 | ] |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
365 | ) |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
366 | dlg = EricProcessDialog( |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
367 | self.tr("'esptool write_flash' Output"), |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
368 | self.tr("Restore Firmware"), |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
369 | showProgress=True, |
10933
95a15b70f7bb
Refactored some packages, modules and code to allow extracting the 'EricXxx' packages into a library project.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10806
diff
changeset
|
370 | monospacedFont=Preferences.getEditorOtherFonts("MonospacedFont"), |
95a15b70f7bb
Refactored some packages, modules and code to allow extracting the 'EricXxx' packages into a library project.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10806
diff
changeset
|
371 | encoding=Preferences.getSystem("IOEncoding"), |
11006
a671918232f3
Modified modal dialog usage to always include a valid parent (needed for Wayland).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11005
diff
changeset
|
372 | parent=self.microPython, |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
373 | ) |
9624
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9576
diff
changeset
|
374 | res = dlg.startProcess(PythonUtilities.getPythonExecutable(), flashArgs) |
7352 | 375 | if res: |
7759
51aa6c6b66f7
Changed calls to exec_() into exec() (remainder of Python2 elimination).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7595
diff
changeset
|
376 | dlg.exec() |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
377 | |
7352 | 378 | @pyqtSlot() |
9749 | 379 | def __showFirmwareVersions(self): |
380 | """ | |
381 | Private slot to show the firmware version of the connected device and the | |
382 | available firmware version. | |
383 | """ | |
9866 | 384 | if self.hasCircuitPython(): |
9870
0399d3607829
Fixed a few code formatting and style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9868
diff
changeset
|
385 | self.__cpyDevice.showCircuitPythonVersions() |
9866 | 386 | |
10329 | 387 | elif self.microPython.isConnected(): |
9751
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9749
diff
changeset
|
388 | if self._deviceData["mpy_name"] == "micropython": |
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9749
diff
changeset
|
389 | url = QUrl(FirmwareGithubUrls["micropython"]) |
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9749
diff
changeset
|
390 | elif self._deviceData["mpy_name"] == "circuitpython": |
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9749
diff
changeset
|
391 | url = QUrl(FirmwareGithubUrls["circuitpython"]) |
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9749
diff
changeset
|
392 | else: |
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9749
diff
changeset
|
393 | EricMessageBox.critical( |
11034
7b8a21fd2d58
Extended the EricMessageBox module to determine a parent widget if none was given and extended the EricApplication class to store a reference to the main widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11006
diff
changeset
|
394 | self.microPython, |
9751
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9749
diff
changeset
|
395 | self.tr("Show MicroPython Versions"), |
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9749
diff
changeset
|
396 | self.tr( |
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9749
diff
changeset
|
397 | """The firmware of the connected device cannot be""" |
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9749
diff
changeset
|
398 | """ determined or the board does not run MicroPython""" |
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9749
diff
changeset
|
399 | """ or CircuitPython. Aborting...""" |
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9749
diff
changeset
|
400 | ), |
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9749
diff
changeset
|
401 | ) |
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9749
diff
changeset
|
402 | return |
9749 | 403 | |
9751
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9749
diff
changeset
|
404 | ui = ericApp().getObject("UserInterface") |
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9749
diff
changeset
|
405 | request = QNetworkRequest(url) |
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9749
diff
changeset
|
406 | reply = ui.networkAccessManager().head(request) |
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9749
diff
changeset
|
407 | reply.finished.connect(lambda: self.__firmwareVersionResponse(reply)) |
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9749
diff
changeset
|
408 | |
9820 | 409 | @pyqtSlot(QNetworkReply) |
9751
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9749
diff
changeset
|
410 | def __firmwareVersionResponse(self, reply): |
9749 | 411 | """ |
9820 | 412 | Private slot handling the response of the latest version request. |
9749 | 413 | |
414 | @param reply reference to the reply object | |
415 | @type QNetworkReply | |
416 | """ | |
417 | latestUrl = reply.url().toString() | |
418 | tag = latestUrl.rsplit("/", 1)[-1] | |
419 | while tag and not tag[0].isdecimal(): | |
420 | # get rid of leading non-decimal characters | |
421 | tag = tag[1:] | |
10806
2f6df822e3b9
Moved some functions to the EricUtilities package for consistency and adapted the code base accordingly.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10683
diff
changeset
|
422 | latestVersion = EricUtilities.versionToTuple(tag) |
9749 | 423 | |
9751
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9749
diff
changeset
|
424 | if self._deviceData["mpy_version"] == "unknown": |
9749 | 425 | currentVersionStr = self.tr("unknown") |
426 | currentVersion = (0, 0, 0) | |
427 | else: | |
9751
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9749
diff
changeset
|
428 | currentVersionStr = self._deviceData["mpy_version"] |
10806
2f6df822e3b9
Moved some functions to the EricUtilities package for consistency and adapted the code base accordingly.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10683
diff
changeset
|
429 | currentVersion = EricUtilities.versionToTuple(currentVersionStr) |
9749 | 430 | |
9751
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9749
diff
changeset
|
431 | if self._deviceData["mpy_name"] == "circuitpython": |
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9749
diff
changeset
|
432 | kind = "CircuitPython" |
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9749
diff
changeset
|
433 | elif self._deviceData["mpy_name"] == "micropython": |
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9749
diff
changeset
|
434 | kind = "MicroPython" |
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9749
diff
changeset
|
435 | |
9749 | 436 | msg = self.tr( |
9751
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9749
diff
changeset
|
437 | "<h4>{0} Version Information</h4>" |
9749 | 438 | "<table>" |
9751
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9749
diff
changeset
|
439 | "<tr><td>Installed:</td><td>{1}</td></tr>" |
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9749
diff
changeset
|
440 | "<tr><td>Available:</td><td>{2}</td></tr>" |
9749 | 441 | "</table>" |
9751
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9749
diff
changeset
|
442 | ).format(kind, currentVersionStr, tag) |
9749 | 443 | if currentVersion < latestVersion: |
444 | msg += self.tr("<p><b>Update available!</b></p>") | |
445 | ||
446 | EricMessageBox.information( | |
11034
7b8a21fd2d58
Extended the EricMessageBox module to determine a parent widget if none was given and extended the EricApplication class to store a reference to the main widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11006
diff
changeset
|
447 | self.microPython, |
9751
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9749
diff
changeset
|
448 | self.tr("{0} Version").format(kind), |
9749 | 449 | msg, |
450 | ) | |
451 | ||
452 | @pyqtSlot() | |
7346 | 453 | def __showChipID(self): |
454 | """ | |
455 | Private slot to show the ID of the ESP chip. | |
456 | """ | |
457 | args = [ | |
458 | "-u", | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
459 | "-m", |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
460 | "esptool", |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
461 | "--port", |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
462 | self.microPython.getCurrentPort(), |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
463 | "chip_id", |
7346 | 464 | ] |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
465 | dlg = EricProcessDialog( |
10933
95a15b70f7bb
Refactored some packages, modules and code to allow extracting the 'EricXxx' packages into a library project.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10806
diff
changeset
|
466 | self.tr("'esptool chip_id' Output"), |
95a15b70f7bb
Refactored some packages, modules and code to allow extracting the 'EricXxx' packages into a library project.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10806
diff
changeset
|
467 | self.tr("Show Chip ID"), |
95a15b70f7bb
Refactored some packages, modules and code to allow extracting the 'EricXxx' packages into a library project.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10806
diff
changeset
|
468 | monospacedFont=Preferences.getEditorOtherFonts("MonospacedFont"), |
95a15b70f7bb
Refactored some packages, modules and code to allow extracting the 'EricXxx' packages into a library project.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10806
diff
changeset
|
469 | encoding=Preferences.getSystem("IOEncoding"), |
11006
a671918232f3
Modified modal dialog usage to always include a valid parent (needed for Wayland).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11005
diff
changeset
|
470 | parent=self.microPython, |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
471 | ) |
9624
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9576
diff
changeset
|
472 | res = dlg.startProcess(PythonUtilities.getPythonExecutable(), args) |
7346 | 473 | if res: |
7759
51aa6c6b66f7
Changed calls to exec_() into exec() (remainder of Python2 elimination).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7595
diff
changeset
|
474 | dlg.exec() |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
475 | |
7346 | 476 | @pyqtSlot() |
477 | def __showFlashID(self): | |
478 | """ | |
479 | Private slot to show the ID of the ESP flash chip. | |
480 | """ | |
481 | args = [ | |
482 | "-u", | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
483 | "-m", |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
484 | "esptool", |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
485 | "--port", |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
486 | self.microPython.getCurrentPort(), |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
487 | "flash_id", |
7346 | 488 | ] |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
489 | dlg = EricProcessDialog( |
10933
95a15b70f7bb
Refactored some packages, modules and code to allow extracting the 'EricXxx' packages into a library project.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10806
diff
changeset
|
490 | self.tr("'esptool flash_id' Output"), |
95a15b70f7bb
Refactored some packages, modules and code to allow extracting the 'EricXxx' packages into a library project.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10806
diff
changeset
|
491 | self.tr("Show Flash ID"), |
95a15b70f7bb
Refactored some packages, modules and code to allow extracting the 'EricXxx' packages into a library project.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10806
diff
changeset
|
492 | monospacedFont=Preferences.getEditorOtherFonts("MonospacedFont"), |
95a15b70f7bb
Refactored some packages, modules and code to allow extracting the 'EricXxx' packages into a library project.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10806
diff
changeset
|
493 | encoding=Preferences.getSystem("IOEncoding"), |
11006
a671918232f3
Modified modal dialog usage to always include a valid parent (needed for Wayland).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11005
diff
changeset
|
494 | parent=self.microPython, |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
495 | ) |
9624
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9576
diff
changeset
|
496 | res = dlg.startProcess(PythonUtilities.getPythonExecutable(), args) |
7346 | 497 | if res: |
7759
51aa6c6b66f7
Changed calls to exec_() into exec() (remainder of Python2 elimination).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7595
diff
changeset
|
498 | dlg.exec() |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
499 | |
7346 | 500 | @pyqtSlot() |
501 | def __showMACAddress(self): | |
502 | """ | |
503 | Private slot to show the MAC address of the ESP chip. | |
504 | """ | |
505 | args = [ | |
506 | "-u", | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
507 | "-m", |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
508 | "esptool", |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
509 | "--port", |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
510 | self.microPython.getCurrentPort(), |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
511 | "read_mac", |
7346 | 512 | ] |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
513 | dlg = EricProcessDialog( |
10933
95a15b70f7bb
Refactored some packages, modules and code to allow extracting the 'EricXxx' packages into a library project.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10806
diff
changeset
|
514 | self.tr("'esptool read_mac' Output"), |
95a15b70f7bb
Refactored some packages, modules and code to allow extracting the 'EricXxx' packages into a library project.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10806
diff
changeset
|
515 | self.tr("Show MAC Address"), |
95a15b70f7bb
Refactored some packages, modules and code to allow extracting the 'EricXxx' packages into a library project.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10806
diff
changeset
|
516 | monospacedFont=Preferences.getEditorOtherFonts("MonospacedFont"), |
95a15b70f7bb
Refactored some packages, modules and code to allow extracting the 'EricXxx' packages into a library project.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10806
diff
changeset
|
517 | encoding=Preferences.getSystem("IOEncoding"), |
11006
a671918232f3
Modified modal dialog usage to always include a valid parent (needed for Wayland).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11005
diff
changeset
|
518 | parent=self.microPython, |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
519 | ) |
9624
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9576
diff
changeset
|
520 | res = dlg.startProcess(PythonUtilities.getPythonExecutable(), args) |
7346 | 521 | if res: |
7759
51aa6c6b66f7
Changed calls to exec_() into exec() (remainder of Python2 elimination).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7595
diff
changeset
|
522 | dlg.exec() |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
523 | |
7346 | 524 | @pyqtSlot() |
7174
de8175253dfc
MicroPython: did some fine tuning of the MicroPython interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7173
diff
changeset
|
525 | def __resetDevice(self): |
de8175253dfc
MicroPython: did some fine tuning of the MicroPython interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7173
diff
changeset
|
526 | """ |
de8175253dfc
MicroPython: did some fine tuning of the MicroPython interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7173
diff
changeset
|
527 | Private slot to reset the connected device. |
de8175253dfc
MicroPython: did some fine tuning of the MicroPython interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7173
diff
changeset
|
528 | """ |
9866 | 529 | if self.microPython.isConnected() and not self.hasCircuitPython(): |
9989 | 530 | self.executeCommands( |
9834 | 531 | "import machine\nmachine.reset()\n", mode=self._submitMode |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
532 | ) |
7353
caa2ccd5677c
EspDevices: fixed an issue resetting the attached device when not connected.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7352
diff
changeset
|
533 | else: |
caa2ccd5677c
EspDevices: fixed an issue resetting the attached device when not connected.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7352
diff
changeset
|
534 | # perform a reset via esptool using flash_id command ignoring |
caa2ccd5677c
EspDevices: fixed an issue resetting the attached device when not connected.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7352
diff
changeset
|
535 | # the output |
caa2ccd5677c
EspDevices: fixed an issue resetting the attached device when not connected.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7352
diff
changeset
|
536 | args = [ |
caa2ccd5677c
EspDevices: fixed an issue resetting the attached device when not connected.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7352
diff
changeset
|
537 | "-u", |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
538 | "-m", |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
539 | "esptool", |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
540 | "--port", |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
541 | self.microPython.getCurrentPort(), |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
542 | "flash_id", |
7353
caa2ccd5677c
EspDevices: fixed an issue resetting the attached device when not connected.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7352
diff
changeset
|
543 | ] |
caa2ccd5677c
EspDevices: fixed an issue resetting the attached device when not connected.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7352
diff
changeset
|
544 | proc = QProcess() |
9624
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9576
diff
changeset
|
545 | proc.start(PythonUtilities.getPythonExecutable(), args) |
7353
caa2ccd5677c
EspDevices: fixed an issue resetting the attached device when not connected.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7352
diff
changeset
|
546 | procStarted = proc.waitForStarted(10000) |
caa2ccd5677c
EspDevices: fixed an issue resetting the attached device when not connected.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7352
diff
changeset
|
547 | if procStarted: |
caa2ccd5677c
EspDevices: fixed an issue resetting the attached device when not connected.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7352
diff
changeset
|
548 | proc.waitForFinished(10000) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
549 | |
7174
de8175253dfc
MicroPython: did some fine tuning of the MicroPython interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7173
diff
changeset
|
550 | @pyqtSlot() |
7108
4f6133a01c6a
Started rearranging menu structure and testing and fixing on CircuitPython.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7100
diff
changeset
|
551 | def __installEspTool(self): |
4f6133a01c6a
Started rearranging menu structure and testing and fixing on CircuitPython.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7100
diff
changeset
|
552 | """ |
4f6133a01c6a
Started rearranging menu structure and testing and fixing on CircuitPython.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7100
diff
changeset
|
553 | Private slot to install the esptool package via pip. |
4f6133a01c6a
Started rearranging menu structure and testing and fixing on CircuitPython.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7100
diff
changeset
|
554 | """ |
8356
68ec9c3d4de5
Renamed the modules and classes of the E5Gui package to have the prefix 'Eric' instead of 'E5'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8318
diff
changeset
|
555 | pip = ericApp().getObject("Pip") |
9624
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9576
diff
changeset
|
556 | pip.installPackages( |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9576
diff
changeset
|
557 | ["esptool"], interpreter=PythonUtilities.getPythonExecutable() |
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9576
diff
changeset
|
558 | ) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
559 | |
7161
728018c32b09
MicroPythonWidget: added actions to show the device documentation and to open the configuration page to the hamburger menu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7134
diff
changeset
|
560 | def getDocumentationUrl(self): |
728018c32b09
MicroPythonWidget: added actions to show the device documentation and to open the configuration page to the hamburger menu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7134
diff
changeset
|
561 | """ |
728018c32b09
MicroPythonWidget: added actions to show the device documentation and to open the configuration page to the hamburger menu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7134
diff
changeset
|
562 | Public method to get the device documentation URL. |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
563 | |
7161
728018c32b09
MicroPythonWidget: added actions to show the device documentation and to open the configuration page to the hamburger menu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7134
diff
changeset
|
564 | @return documentation URL of the device |
728018c32b09
MicroPythonWidget: added actions to show the device documentation and to open the configuration page to the hamburger menu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7134
diff
changeset
|
565 | @rtype str |
728018c32b09
MicroPythonWidget: added actions to show the device documentation and to open the configuration page to the hamburger menu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7134
diff
changeset
|
566 | """ |
9866 | 567 | if self.hasCircuitPython(): |
568 | return self.__cpyDevice.getDocumentationUrl() | |
569 | ||
7161
728018c32b09
MicroPythonWidget: added actions to show the device documentation and to open the configuration page to the hamburger menu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7134
diff
changeset
|
570 | return Preferences.getMicroPython("MicroPythonDocuUrl") |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
571 | |
7328 | 572 | def getFirmwareUrl(self): |
573 | """ | |
574 | Public method to get the device firmware download URL. | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
575 | |
7328 | 576 | @return firmware download URL of the device |
577 | @rtype str | |
578 | """ | |
9866 | 579 | if self.hasCircuitPython(): |
580 | return self.__cpyDevice.getFirmwareUrl() | |
581 | ||
7328 | 582 | return Preferences.getMicroPython("MicroPythonFirmwareUrl") |
9496
05017f795c24
Changed MicroPython device imports to use importlib.import_module().
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9473
diff
changeset
|
583 | |
9765
6378da868bb0
Reorganized the MicroPython code even more.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
584 | ################################################################## |
6378da868bb0
Reorganized the MicroPython code even more.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
585 | ## time related methods below |
6378da868bb0
Reorganized the MicroPython code even more.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
586 | ################################################################## |
6378da868bb0
Reorganized the MicroPython code even more.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
587 | |
6378da868bb0
Reorganized the MicroPython code even more.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
588 | def _getSetTimeCode(self): |
6378da868bb0
Reorganized the MicroPython code even more.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
589 | """ |
6378da868bb0
Reorganized the MicroPython code even more.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
590 | Protected method to get the device code to set the time. |
6378da868bb0
Reorganized the MicroPython code even more.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
591 | |
6378da868bb0
Reorganized the MicroPython code even more.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
592 | Note: This method must be implemented in the various device specific |
6378da868bb0
Reorganized the MicroPython code even more.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
593 | subclasses. |
6378da868bb0
Reorganized the MicroPython code even more.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
594 | |
6378da868bb0
Reorganized the MicroPython code even more.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
595 | @return code to be executed on the connected device to set the time |
6378da868bb0
Reorganized the MicroPython code even more.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
596 | @rtype str |
6378da868bb0
Reorganized the MicroPython code even more.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
597 | """ |
6378da868bb0
Reorganized the MicroPython code even more.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
598 | # rtc_time[0] - year 4 digit |
6378da868bb0
Reorganized the MicroPython code even more.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
599 | # rtc_time[1] - month 1..12 |
6378da868bb0
Reorganized the MicroPython code even more.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
600 | # rtc_time[2] - day 1..31 |
6378da868bb0
Reorganized the MicroPython code even more.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
601 | # rtc_time[3] - weekday 1..7 1=Monday |
6378da868bb0
Reorganized the MicroPython code even more.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
602 | # rtc_time[4] - hour 0..23 |
6378da868bb0
Reorganized the MicroPython code even more.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
603 | # rtc_time[5] - minute 0..59 |
6378da868bb0
Reorganized the MicroPython code even more.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
604 | # rtc_time[6] - second 0..59 |
6378da868bb0
Reorganized the MicroPython code even more.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
605 | # rtc_time[7] - yearday 1..366 |
6378da868bb0
Reorganized the MicroPython code even more.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
606 | # rtc_time[8] - isdst 0, 1, or -1 |
6378da868bb0
Reorganized the MicroPython code even more.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
607 | |
6378da868bb0
Reorganized the MicroPython code even more.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
608 | # The machine.RTC.init() (ESP32) and machine.rtc.datetime() (ESP8266) functions |
6378da868bb0
Reorganized the MicroPython code even more.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
609 | # take the arguments in the order: |
6378da868bb0
Reorganized the MicroPython code even more.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
610 | # (year, month, day, weekday, hour, minute, second, subseconds) |
6378da868bb0
Reorganized the MicroPython code even more.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
611 | # __IGNORE_WARNING_M891__ |
6378da868bb0
Reorganized the MicroPython code even more.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
612 | # https://docs.micropython.org/en/latest/library/machine.RTC.html#machine-rtc |
6378da868bb0
Reorganized the MicroPython code even more.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
613 | # |
6378da868bb0
Reorganized the MicroPython code even more.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
614 | # LoBo variant of MPy deviates. |
9866 | 615 | if self.hasCircuitPython(): |
616 | return super()._getSetTimeCode() | |
617 | ||
9765
6378da868bb0
Reorganized the MicroPython code even more.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
618 | return """ |
6378da868bb0
Reorganized the MicroPython code even more.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
619 | def set_time(rtc_time): |
6378da868bb0
Reorganized the MicroPython code even more.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
620 | import machine |
6378da868bb0
Reorganized the MicroPython code even more.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
621 | rtc = machine.RTC() |
6378da868bb0
Reorganized the MicroPython code even more.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
622 | try: |
6378da868bb0
Reorganized the MicroPython code even more.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
623 | rtc.datetime(rtc_time[:7] + (0,)) |
6378da868bb0
Reorganized the MicroPython code even more.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
624 | except Exception: |
6378da868bb0
Reorganized the MicroPython code even more.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
625 | import os |
6378da868bb0
Reorganized the MicroPython code even more.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
626 | if 'LoBo' in os.uname()[0]: |
6378da868bb0
Reorganized the MicroPython code even more.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
627 | clock_time = rtc_time[:3] + rtc_time[4:7] + (rtc_time[3], rtc_time[7]) |
6378da868bb0
Reorganized the MicroPython code even more.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
628 | else: |
6378da868bb0
Reorganized the MicroPython code even more.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
629 | clock_time = rtc_time[:7] + (0,) |
6378da868bb0
Reorganized the MicroPython code even more.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
630 | rtc.init(clock_time) |
6378da868bb0
Reorganized the MicroPython code even more.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
631 | """ |
6378da868bb0
Reorganized the MicroPython code even more.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
632 | |
9795 | 633 | ################################################################## |
634 | ## Methods below implement WiFi related methods | |
635 | ################################################################## | |
636 | ||
10153 | 637 | def addDeviceWifiEntries(self, menu): |
638 | """ | |
639 | Public method to add device specific entries to the given menu. | |
640 | ||
641 | @param menu reference to the context menu | |
642 | @type QMenu | |
643 | """ | |
644 | if not self.hasCircuitPython(): | |
645 | menu.addSeparator() | |
646 | menu.addAction(self.tr("Set Country"), self.__setCountry) | |
647 | menu.addAction(self.tr("Reset Country"), self.__resetCountry) | |
648 | ||
9795 | 649 | def hasWifi(self): |
650 | """ | |
651 | Public method to check the availability of WiFi. | |
652 | ||
653 | @return tuple containing a flag indicating the availability of WiFi | |
654 | and the WiFi type (esp32) | |
655 | @rtype tuple of (bool, str) | |
656 | """ | |
9866 | 657 | if self.hasCircuitPython(): |
658 | self.__createCpyDevice() | |
659 | return self.__cpyDevice.hasWifi() | |
660 | ||
9795 | 661 | return True, "esp32" |
662 | ||
10153 | 663 | def hasWifiCountry(self): |
664 | """ | |
665 | Public method to check, if the device has support to set the WiFi country. | |
666 | ||
667 | @return flag indicating the support of WiFi country | |
668 | @rtype bool | |
669 | """ | |
670 | return True | |
671 | ||
9795 | 672 | def getWifiData(self): |
673 | """ | |
674 | Public method to get data related to the current WiFi status. | |
675 | ||
9798 | 676 | @return tuple of three dictionaries containing the WiFi status data |
677 | for the WiFi client, access point and overall data | |
678 | @rtype tuple of (dict, dict, dict) | |
9795 | 679 | @exception OSError raised to indicate an issue with the device |
680 | """ | |
9866 | 681 | if self.hasCircuitPython(): |
682 | return self.__cpyDevice.getWifiData() | |
683 | ||
9795 | 684 | command = """ |
685 | def wifi_status(): | |
686 | import ubinascii | |
687 | import ujson | |
688 | import network | |
689 | ||
690 | wifi = network.WLAN(network.STA_IF) | |
691 | station = { | |
692 | 'active': wifi.active(), | |
693 | 'connected': wifi.isconnected(), | |
694 | 'status': wifi.status(), | |
695 | 'ifconfig': wifi.ifconfig(), | |
696 | 'mac': ubinascii.hexlify(wifi.config('mac'), ':').decode(), | |
697 | } | |
698 | if wifi.active(): | |
9797 | 699 | try: |
700 | station['txpower'] = wifi.config('txpower') | |
701 | except ValueError: | |
702 | pass | |
9795 | 703 | print(ujson.dumps(station)) |
704 | ||
705 | wifi = network.WLAN(network.AP_IF) | |
706 | ap = { | |
707 | 'active': wifi.active(), | |
708 | 'connected': wifi.isconnected(), | |
709 | 'status': wifi.status(), | |
710 | 'ifconfig': wifi.ifconfig(), | |
711 | 'mac': ubinascii.hexlify(wifi.config('mac'), ':').decode(), | |
712 | 'channel': wifi.config('channel'), | |
713 | 'essid': wifi.config('essid'), | |
714 | } | |
715 | if wifi.active(): | |
9797 | 716 | try: |
717 | ap['txpower'] = wifi.config('txpower') | |
718 | except ValueError: | |
719 | pass | |
9795 | 720 | print(ujson.dumps(ap)) |
721 | ||
9798 | 722 | overall = { |
723 | 'active': station['active'] or ap['active'] | |
724 | } | |
10153 | 725 | try: |
726 | overall['hostname'] = network.hostname() | |
727 | except AttributeError: | |
728 | pass | |
729 | try: | |
730 | overall['country'] = network.country() | |
731 | except AttributeError: | |
732 | pass | |
9798 | 733 | print(ujson.dumps(overall)) |
734 | ||
9795 | 735 | wifi_status() |
736 | del wifi_status | |
737 | """ | |
738 | ||
9989 | 739 | out, err = self.executeCommands(command, mode=self._submitMode) |
9795 | 740 | if err: |
741 | raise OSError(self._shortError(err)) | |
742 | ||
9798 | 743 | stationStr, apStr, overallStr = out.decode("utf-8").splitlines() |
9795 | 744 | station = json.loads(stationStr) |
745 | ap = json.loads(apStr) | |
9798 | 746 | overall = json.loads(overallStr) |
9795 | 747 | try: |
748 | station["status"] = self.__statusTranslations[station["status"]] | |
749 | except KeyError: | |
750 | station["status"] = str(station["status"]) | |
751 | try: | |
752 | ap["status"] = self.__statusTranslations[ap["status"]] | |
753 | except KeyError: | |
754 | ap["status"] = str(ap["status"]) | |
9798 | 755 | return station, ap, overall |
9795 | 756 | |
10153 | 757 | def connectWifi(self, ssid, password, hostname): |
9795 | 758 | """ |
759 | Public method to connect a device to a WiFi network. | |
760 | ||
761 | @param ssid name (SSID) of the WiFi network | |
762 | @type str | |
763 | @param password password needed to connect | |
764 | @type str | |
10153 | 765 | @param hostname host name of the device |
766 | @type str | |
9795 | 767 | @return tuple containing the connection status and an error string |
768 | @rtype tuple of (bool, str) | |
769 | """ | |
9866 | 770 | if self.hasCircuitPython(): |
10153 | 771 | return self.__cpyDevice.connectWifi(ssid, password, hostname) |
9866 | 772 | |
9795 | 773 | command = """ |
10153 | 774 | def connect_wifi(ssid, password, hostname): |
9795 | 775 | import network |
776 | import ujson | |
777 | from time import sleep | |
778 | ||
10153 | 779 | if hostname: |
780 | try: | |
781 | network.hostname(hostname) | |
782 | except AttributeError: | |
783 | pass | |
784 | ||
9795 | 785 | wifi = network.WLAN(network.STA_IF) |
786 | wifi.active(False) | |
787 | wifi.active(True) | |
788 | wifi.connect(ssid, password) | |
789 | max_wait = 140 | |
790 | while max_wait and wifi.status() == network.STAT_CONNECTING: | |
791 | max_wait -= 1 | |
792 | sleep(0.1) | |
793 | status = wifi.status() | |
794 | print(ujson.dumps({{'connected': wifi.isconnected(), 'status': status}})) | |
795 | ||
10153 | 796 | connect_wifi({0}, {1}, {2}) |
9795 | 797 | del connect_wifi |
798 | """.format( | |
9798 | 799 | repr(ssid), |
800 | repr(password if password else ""), | |
10153 | 801 | repr(hostname), |
9798 | 802 | ) |
9795 | 803 | |
804 | with EricOverrideCursor(): | |
9989 | 805 | out, err = self.executeCommands( |
9827 | 806 | command, mode=self._submitMode, timeout=15000 |
9799 | 807 | ) |
9795 | 808 | if err: |
809 | return False, err | |
810 | ||
10235
4a12b160094c
MicroPython interface
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10233
diff
changeset
|
811 | while not out.startswith(b"{"): |
4a12b160094c
MicroPython interface
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10233
diff
changeset
|
812 | # discard output until next newline |
4a12b160094c
MicroPython interface
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10233
diff
changeset
|
813 | _, out = out.split(b"\r\n", 1) |
9795 | 814 | result = json.loads(out.decode("utf-8").strip()) |
815 | if result["connected"]: | |
816 | error = "" | |
817 | else: | |
818 | try: | |
819 | error = self.__statusTranslations[result["status"]] | |
820 | except KeyError: | |
821 | error = str(result["status"]) | |
822 | ||
823 | return result["connected"], error | |
824 | ||
825 | def disconnectWifi(self): | |
826 | """ | |
827 | Public method to disconnect a device from the WiFi network. | |
828 | ||
829 | @return tuple containing a flag indicating success and an error string | |
830 | @rtype tuple of (bool, str) | |
831 | """ | |
9866 | 832 | if self.hasCircuitPython(): |
833 | return self.__cpyDevice.disconnectWifi() | |
834 | ||
9795 | 835 | command = """ |
836 | def disconnect_wifi(): | |
837 | import network | |
838 | from time import sleep | |
839 | ||
840 | wifi = network.WLAN(network.STA_IF) | |
841 | wifi.disconnect() | |
842 | wifi.active(False) | |
843 | sleep(0.1) | |
844 | print(not wifi.isconnected()) | |
845 | ||
846 | disconnect_wifi() | |
847 | del disconnect_wifi | |
848 | """ | |
849 | ||
9989 | 850 | out, err = self.executeCommands(command, mode=self._submitMode) |
9795 | 851 | if err: |
852 | return False, err | |
853 | ||
10144 | 854 | return out.decode("utf-8").strip() == "True", "" |
855 | ||
856 | def isWifiClientConnected(self): | |
857 | """ | |
858 | Public method to check the WiFi connection status as client. | |
859 | ||
860 | @return flag indicating the WiFi connection status | |
861 | @rtype bool | |
862 | """ | |
863 | if self.hasCircuitPython(): | |
864 | return self.__cpyDevice.isWifiClientConnected() | |
865 | ||
866 | command = """ | |
867 | def wifi_connected(): | |
868 | import network | |
869 | ||
870 | wifi = network.WLAN(network.STA_IF) | |
871 | print(wifi.isconnected()) | |
872 | ||
873 | wifi_connected() | |
874 | del wifi_connected | |
875 | """ | |
876 | ||
877 | out, err = self.executeCommands(command, mode=self._submitMode) | |
878 | if err: | |
879 | return False | |
10138 | 880 | |
10144 | 881 | return out.strip() == b"True" |
882 | ||
883 | def isWifiApConnected(self): | |
884 | """ | |
885 | Public method to check the WiFi connection status as access point. | |
886 | ||
887 | @return flag indicating the WiFi connection status | |
888 | @rtype bool | |
889 | """ | |
890 | if self.hasCircuitPython(): | |
891 | return self.__cpyDevice.isWifiApConnected() | |
892 | ||
893 | command = """ | |
894 | def wifi_connected(): | |
895 | import network | |
896 | ||
897 | wifi = network.WLAN(network.AP_IF) | |
898 | print(wifi.isconnected()) | |
899 | ||
900 | wifi_connected() | |
901 | del wifi_connected | |
902 | """ | |
903 | ||
904 | out, err = self.executeCommands(command, mode=self._submitMode) | |
905 | if err: | |
906 | return False | |
907 | ||
908 | return out.strip() == b"True" | |
9795 | 909 | |
10153 | 910 | def writeCredentials(self, ssid, password, hostname, country): |
9795 | 911 | """ |
912 | Public method to write the given credentials to the connected device and modify | |
913 | the start script to connect automatically. | |
914 | ||
915 | @param ssid SSID of the network to connect to | |
916 | @type str | |
917 | @param password password needed to authenticate | |
918 | @type str | |
10153 | 919 | @param hostname host name of the device |
920 | @type str | |
921 | @param country WiFi country code | |
922 | @type str | |
9795 | 923 | @return tuple containing a flag indicating success and an error message |
924 | @rtype tuple of (bool, str) | |
925 | """ | |
9866 | 926 | if self.hasCircuitPython(): |
10153 | 927 | return self.__cpyDevice.writeCredentials(ssid, password, hostname) |
9866 | 928 | |
9795 | 929 | nvsCommand = """ |
10153 | 930 | def save_wifi_creds(ssid, password, hostname, country): |
9795 | 931 | import esp32 |
932 | ||
933 | nvs = esp32.NVS('wifi_creds') | |
934 | nvs.set_blob('ssid', ssid) | |
935 | nvs.set_blob('password', password) | |
10153 | 936 | nvs.set_blob('hostname', hostname) |
937 | nvs.set_blob('country', country) | |
9795 | 938 | nvs.commit() |
939 | ||
10153 | 940 | save_wifi_creds({0}, {1}, {2}, {3}) |
9795 | 941 | del save_wifi_creds |
9798 | 942 | """.format( |
10153 | 943 | repr(ssid), |
944 | repr(password) if password else "''", | |
945 | repr(hostname) if hostname else "''", | |
946 | repr(country.upper()) if country else "''", | |
9798 | 947 | ) |
9795 | 948 | bootCommand = """ |
949 | def modify_boot(): | |
950 | add = True | |
951 | try: | |
952 | with open('/boot.py', 'r') as f: | |
953 | for ln in f.readlines(): | |
954 | if 'wifi_connect' in ln: | |
955 | add = False | |
956 | break | |
957 | except: | |
958 | pass | |
959 | if add: | |
960 | with open('/boot.py', 'a') as f: | |
961 | f.write('\\nimport wifi_connect\\n') | |
962 | print(True) | |
963 | ||
964 | modify_boot() | |
965 | del modify_boot | |
966 | """ | |
967 | ||
9989 | 968 | out, err = self.executeCommands(nvsCommand, mode=self._submitMode) |
9795 | 969 | if err: |
970 | return False, self.tr("Error saving credentials: {0}").format(err) | |
971 | ||
972 | try: | |
973 | # copy auto-connect file | |
974 | self.put( | |
975 | os.path.join( | |
976 | os.path.dirname(__file__), "MCUScripts", "esp32WiFiConnect.py" | |
977 | ), | |
978 | "/wifi_connect.py", | |
979 | ) | |
980 | except OSError as err: | |
981 | return False, self.tr("Error saving auto-connect script: {0}").format(err) | |
982 | ||
9989 | 983 | out, err = self.executeCommands(bootCommand, mode=self._submitMode) |
9795 | 984 | if err: |
985 | return False, self.tr("Error modifying 'boot.py': {0}").format(err) | |
986 | ||
987 | return True, "" | |
988 | ||
989 | def removeCredentials(self): | |
990 | """ | |
991 | Public method to remove the saved credentials from the connected device. | |
992 | ||
993 | @return tuple containing a flag indicating success and an error message | |
994 | @rtype tuple of (bool, str) | |
995 | """ | |
9866 | 996 | if self.hasCircuitPython(): |
997 | return self.__cpyDevice.removeCredentials() | |
998 | ||
9795 | 999 | nvsCommand = """ |
1000 | def delete_wifi_creds(): | |
1001 | import esp32 | |
1002 | ||
1003 | nvs = esp32.NVS('wifi_creds') | |
1004 | try: | |
1005 | nvs.erase_key('ssid') | |
1006 | nvs.erase_key('password') | |
1007 | nvs.commit() | |
1008 | except OSError: | |
1009 | pass | |
1010 | ||
1011 | delete_wifi_creds() | |
1012 | del delete_wifi_creds | |
1013 | """ | |
1014 | ||
9989 | 1015 | out, err = self.executeCommands(nvsCommand, mode=self._submitMode) |
9795 | 1016 | if err: |
1017 | return False, self.tr("Error deleting credentials: {0}").format(err) | |
1018 | ||
1019 | return True, "" | |
1020 | ||
1021 | def checkInternet(self): | |
1022 | """ | |
1023 | Public method to check, if the internet can be reached. | |
1024 | ||
1025 | @return tuple containing a flag indicating reachability and an error string | |
1026 | @rtype tuple of (bool, str) | |
1027 | """ | |
9866 | 1028 | if self.hasCircuitPython(): |
1029 | return self.__cpyDevice.checkInternet() | |
1030 | ||
9795 | 1031 | command = """ |
1032 | def check_internet(): | |
1033 | import network | |
1034 | import socket | |
1035 | ||
1036 | wifi = network.WLAN(network.STA_IF) | |
1037 | if wifi.isconnected(): | |
1038 | s = socket.socket() | |
1039 | try: | |
10233
51a6649ba79d
MicroPython Interface
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10170
diff
changeset
|
1040 | s.connect(socket.getaddrinfo('quad9.net', 443)[0][-1]) |
9795 | 1041 | s.close() |
1042 | print(True) | |
1043 | except: | |
1044 | print(False) | |
1045 | else: | |
1046 | print(False) | |
1047 | ||
1048 | check_internet() | |
1049 | del check_internet | |
1050 | """ | |
1051 | ||
9989 | 1052 | out, err = self.executeCommands(command, mode=self._submitMode) |
9795 | 1053 | if err: |
1054 | return False, err | |
1055 | ||
1056 | return out.decode("utf-8").strip() == "True", "" | |
1057 | ||
1058 | def scanNetworks(self): | |
1059 | """ | |
1060 | Public method to scan for available WiFi networks. | |
1061 | ||
1062 | @return tuple containing the list of available networks as a tuple of 'Name', | |
1063 | 'MAC-Address', 'channel', 'RSSI' and 'security' and an error string | |
1064 | @rtype tuple of (list of tuple of (str, str, int, int, str), str) | |
1065 | """ | |
9866 | 1066 | if self.hasCircuitPython(): |
1067 | return self.__cpyDevice.scanNetworks() | |
1068 | ||
9795 | 1069 | command = """ |
1070 | def scan_networks(): | |
1071 | import network | |
1072 | ||
1073 | wifi = network.WLAN(network.STA_IF) | |
1074 | active = wifi.active() | |
1075 | if not active: | |
1076 | wifi.active(True) | |
1077 | network_list = wifi.scan() | |
1078 | if not active: | |
1079 | wifi.active(False) | |
1080 | print(network_list) | |
1081 | ||
1082 | scan_networks() | |
1083 | del scan_networks | |
1084 | """ | |
1085 | ||
9989 | 1086 | out, err = self.executeCommands(command, mode=self._submitMode, timeout=15000) |
9795 | 1087 | if err: |
1088 | return [], err | |
1089 | ||
1090 | networksList = ast.literal_eval(out.decode("utf-8")) | |
1091 | networks = [] | |
1092 | for network in networksList: | |
1093 | if network[0]: | |
1094 | ssid = network[0].decode("utf-8") | |
1095 | mac = binascii.hexlify(network[1], ":").decode("utf-8") | |
1096 | channel = network[2] | |
1097 | rssi = network[3] | |
1098 | try: | |
1099 | security = self.__securityTranslations[network[4]] | |
1100 | except KeyError: | |
1101 | security = self.tr("unknown ({0})").format(network[4]) | |
1102 | networks.append((ssid, mac, channel, rssi, security)) | |
1103 | ||
1104 | return networks, "" | |
1105 | ||
1106 | def deactivateInterface(self, interface): | |
1107 | """ | |
1108 | Public method to deactivate a given WiFi interface of the connected device. | |
1109 | ||
1110 | @param interface designation of the interface to be deactivated (one of 'AP' | |
1111 | or 'STA') | |
1112 | @type str | |
1113 | @return tuple containg a flag indicating success and an error message | |
1114 | @rtype tuple of (bool, str) | |
1115 | @exception ValueError raised to indicate a wrong value for the interface type | |
1116 | """ | |
1117 | if interface not in ("STA", "AP"): | |
1118 | raise ValueError( | |
1119 | "interface must be 'AP' or 'STA', got '{0}'".format(interface) | |
1120 | ) | |
1121 | ||
9866 | 1122 | if self.hasCircuitPython(): |
1123 | return self.__cpyDevice.deactivateInterface(interface) | |
1124 | ||
9795 | 1125 | command = """ |
1126 | def deactivate(): | |
1127 | import network | |
1128 | from time import sleep | |
1129 | ||
1130 | wifi = network.WLAN(network.{0}_IF) | |
1131 | wifi.active(False) | |
1132 | sleep(0.1) | |
1133 | print(not wifi.active()) | |
1134 | ||
1135 | deactivate() | |
1136 | del deactivate | |
1137 | """.format( | |
9798 | 1138 | interface |
1139 | ) | |
9795 | 1140 | |
9989 | 1141 | out, err = self.executeCommands(command, mode=self._submitMode) |
9795 | 1142 | if err: |
1143 | return False, err | |
1144 | else: | |
1145 | return out.decode("utf-8").strip() == "True", "" | |
1146 | ||
10153 | 1147 | def startAccessPoint( |
1148 | self, | |
1149 | ssid, | |
1150 | security=None, | |
1151 | password=None, | |
1152 | hostname=None, | |
1153 | ifconfig=None, | |
1154 | ): | |
9795 | 1155 | """ |
1156 | Public method to start the access point interface. | |
1157 | ||
1158 | @param ssid SSID of the access point | |
1159 | @type str | |
1160 | @param security security method (defaults to None) | |
1161 | @type int (optional) | |
1162 | @param password password (defaults to None) | |
1163 | @type str (optional) | |
10153 | 1164 | @param hostname host name of the device (defaults to None) |
1165 | @type str (optional) | |
9797 | 1166 | @param ifconfig IPv4 configuration for the access point if not default |
1167 | (IPv4 address, netmask, gateway address, DNS server address) | |
1168 | @type tuple of (str, str, str, str) | |
9795 | 1169 | @return tuple containing a flag indicating success and an error message |
1170 | @rtype tuple of (bool, str) | |
1171 | """ | |
9866 | 1172 | if self.hasCircuitPython(): |
1173 | return self.__cpyDevice.startAccessPoint( | |
10153 | 1174 | ssid, |
1175 | security=security, | |
1176 | password=password, | |
1177 | hostname=hostname, | |
1178 | ifconfig=ifconfig, | |
9866 | 1179 | ) |
1180 | ||
9795 | 1181 | if security is None or password is None: |
1182 | security = 0 | |
10170
6cf1ee737d8f
Corrected some more code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10153
diff
changeset
|
1183 | password = "" # secok |
9795 | 1184 | if security > 4: |
1185 | security = 4 # security >4 cause an error thrown by the ESP32 | |
1186 | ||
1187 | command = """ | |
10153 | 1188 | def start_ap(ssid, authmode, password, hostname, ifconfig): |
9795 | 1189 | import network |
1190 | ||
10153 | 1191 | if hostname: |
1192 | try: | |
1193 | network.hostname(hostname) | |
1194 | except AttributeError: | |
1195 | pass | |
1196 | ||
9795 | 1197 | ap = network.WLAN(network.AP_IF) |
1198 | ap.active(False) | |
9797 | 1199 | if ifconfig: |
1200 | ap.ifconfig(ifconfig) | |
9795 | 1201 | ap.active(True) |
1202 | try: | |
9797 | 1203 | ap.config(ssid=ssid, authmode=authmode, password=password) |
9795 | 1204 | except: |
9797 | 1205 | ap.config(essid=ssid, authmode=authmode, password=password) |
9795 | 1206 | |
10153 | 1207 | start_ap({0}, {1}, {2}, {3}, {4}) |
9795 | 1208 | del start_ap |
1209 | """.format( | |
10153 | 1210 | repr(ssid), security, repr(password), repr(hostname), ifconfig |
9798 | 1211 | ) |
9795 | 1212 | |
9989 | 1213 | out, err = self.executeCommands(command, mode=self._submitMode, timeout=15000) |
9795 | 1214 | if err: |
1215 | return False, err | |
1216 | else: | |
1217 | return True, "" | |
1218 | ||
1219 | def stopAccessPoint(self): | |
1220 | """ | |
1221 | Public method to stop the access point interface. | |
1222 | ||
1223 | @return tuple containg a flag indicating success and an error message | |
1224 | @rtype tuple of (bool, str) | |
1225 | """ | |
9866 | 1226 | if self.hasCircuitPython(): |
1227 | return self.__cpyDevice.stopAccessPoint() | |
1228 | ||
9795 | 1229 | return self.deactivateInterface("AP") |
1230 | ||
1231 | def getConnectedClients(self): | |
1232 | """ | |
1233 | Public method to get a list of connected clients. | |
1234 | ||
1235 | @return a tuple containing a list of tuples containing the client MAC-Address | |
1236 | and the RSSI (if supported and available) and an error message | |
1237 | @rtype tuple of ([(bytes, int)], str) | |
1238 | """ | |
9866 | 1239 | if self.hasCircuitPython(): |
1240 | return self.__cpyDevice.getConnectedClients() | |
1241 | ||
9795 | 1242 | command = """ |
1243 | def get_stations(): | |
1244 | import network | |
1245 | ||
1246 | ap = network.WLAN(network.AP_IF) | |
1247 | stations = ap.status('stations') | |
1248 | print(stations) | |
1249 | ||
1250 | get_stations() | |
1251 | del get_stations | |
1252 | """ | |
1253 | ||
9989 | 1254 | out, err = self.executeCommands(command, mode=self._submitMode, timeout=10000) |
9795 | 1255 | if err: |
1256 | return [], err | |
1257 | ||
1258 | clientsList = ast.literal_eval(out.decode("utf-8")) | |
1259 | return clientsList, "" | |
1260 | ||
10022 | 1261 | def enableWebrepl(self, password): |
1262 | """ | |
1263 | Public method to write the given WebREPL password to the connected device and | |
1264 | modify the start script to start the WebREPL server. | |
1265 | ||
1266 | @param password password needed to authenticate | |
1267 | @type str | |
1268 | @return tuple containing a flag indicating success and an error message | |
1269 | @rtype tuple of (bool, str) | |
1270 | """ | |
1271 | command = """ | |
1272 | def modify_boot(): | |
1273 | import os | |
1274 | ||
1275 | try: | |
1276 | with open('/boot.py', 'r') as old_f, open('/boot.py.tmp', 'w') as new_f: | |
1277 | found = False | |
1278 | for l in old_f.read().splitlines(): | |
1279 | if 'webrepl' in l: | |
1280 | found = True | |
1281 | if l.startswith('#'): | |
1282 | l = l[1:] | |
1283 | new_f.write(l + '\\n') | |
1284 | if not found: | |
1285 | new_f.write('\\nimport webrepl\\nwebrepl.start()\\n') | |
1286 | ||
1287 | os.remove('/boot.py') | |
1288 | os.rename('/boot.py.tmp', '/boot.py') | |
1289 | except: | |
1290 | pass | |
1291 | ||
1292 | print(True) | |
1293 | ||
1294 | modify_boot() | |
1295 | del modify_boot | |
1296 | """ | |
1297 | ||
1298 | try: | |
1299 | # write config file | |
1300 | config = "PASS = {0}\n".format(repr(password)) | |
1301 | self.putData("/webrepl_cfg.py", config.encode("utf-8")) | |
1302 | except OSError as err: | |
1303 | return False, str(err) | |
1304 | ||
1305 | # modify boot.py | |
1306 | out, err = self.executeCommands(command, mode=self._submitMode) | |
1307 | if err: | |
1308 | return False, err | |
1309 | ||
1310 | return out.decode("utf-8").strip() == "True", "" | |
1311 | ||
1312 | def disableWebrepl(self): | |
1313 | """ | |
1314 | Public method to write the given WebREPL password to the connected device and | |
1315 | modify the start script to start the WebREPL server. | |
1316 | ||
1317 | @return tuple containing a flag indicating success and an error message | |
1318 | @rtype tuple of (bool, str) | |
1319 | """ | |
1320 | command = """ | |
1321 | def modify_boot(): | |
1322 | import os | |
1323 | ||
1324 | try: | |
1325 | with open('/boot.py', 'r') as old_f, open('/boot.py.tmp', 'w') as new_f: | |
1326 | for l in old_f.read().splitlines(): | |
1327 | if 'webrepl' in l: | |
1328 | if not l.startswith('#'): | |
1329 | l = '#' + l | |
1330 | new_f.write(l + '\\n') | |
1331 | ||
1332 | os.remove('/boot.py') | |
1333 | os.rename('/boot.py.tmp', '/boot.py') | |
1334 | except: | |
1335 | pass | |
1336 | ||
1337 | print(True) | |
1338 | ||
1339 | modify_boot() | |
1340 | del modify_boot | |
1341 | """ | |
1342 | ||
1343 | # modify boot.py | |
1344 | out, err = self.executeCommands(command, mode=self._submitMode) | |
1345 | if err: | |
1346 | return False, err | |
1347 | ||
1348 | return out.decode("utf-8").strip() == "True", "" | |
1349 | ||
10153 | 1350 | @pyqtSlot() |
1351 | def __setCountry(self): | |
1352 | """ | |
1353 | Private slot to configure the country of the connected ESP32 device. | |
1354 | ||
1355 | The country is the two-letter ISO 3166-1 Alpha-2 country code. | |
1356 | """ | |
1357 | from ..WifiDialogs.WifiCountryDialog import WifiCountryDialog | |
1358 | ||
11005
b918c6c2736b
MicroPython Interface
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10933
diff
changeset
|
1359 | dlg = WifiCountryDialog(parent=self.microPython) |
10153 | 1360 | if dlg.exec() == QDialog.DialogCode.Accepted: |
1361 | country, remember = dlg.getCountry() | |
1362 | if remember: | |
1363 | Preferences.setMicroPython("WifiCountry", country) | |
1364 | ||
1365 | command = """ | |
1366 | try: | |
1367 | import network | |
1368 | network.country({0}) | |
1369 | except AttributeError: | |
1370 | pass | |
1371 | """.format( | |
1372 | repr(country) | |
1373 | ) | |
1374 | ||
1375 | out, err = self.executeCommands(command, mode=self._submitMode) | |
1376 | if err: | |
1377 | self.microPython.showError("country()", err) | |
1378 | ||
1379 | @pyqtSlot() | |
1380 | def __resetCountry(self): | |
1381 | """ | |
1382 | Private slot to reset the country of the connected ESP32 device. | |
1383 | ||
1384 | The country is the two-letter ISO 3166-1 Alpha-2 country code. This method | |
1385 | resets it to the default code 'XX' representing the "worldwide" region. | |
1386 | """ | |
1387 | command = """ | |
1388 | try: | |
1389 | import network | |
1390 | network.country('XX') | |
1391 | except AttributeError: | |
1392 | pass | |
1393 | """ | |
1394 | ||
1395 | out, err = self.executeCommands(command, mode=self._submitMode) | |
1396 | if err: | |
1397 | self.microPython.showError("country()", err) | |
1398 | ||
9855 | 1399 | ################################################################## |
1400 | ## Methods below implement Bluetooth related methods | |
1401 | ################################################################## | |
1402 | ||
1403 | def hasBluetooth(self): | |
1404 | """ | |
1405 | Public method to check the availability of Bluetooth. | |
1406 | ||
1407 | @return flag indicating the availability of Bluetooth | |
1408 | @rtype bool | |
9857 | 1409 | @exception OSError raised to indicate an issue with the device |
9855 | 1410 | """ |
9866 | 1411 | if self.hasCircuitPython(): |
1412 | self.__createCpyDevice() | |
1413 | return self.__cpyDevice.hasBluetooth() | |
1414 | ||
9855 | 1415 | command = """ |
1416 | def has_bt(): | |
1417 | try: | |
1418 | import bluetooth | |
1419 | if hasattr(bluetooth, 'BLE'): | |
1420 | return True | |
1421 | except ImportError: | |
1422 | pass | |
1423 | ||
1424 | return False | |
1425 | ||
1426 | print(has_bt()) | |
1427 | del has_bt | |
1428 | """ | |
9989 | 1429 | out, err = self.executeCommands(command, mode=self._submitMode, timeout=10000) |
9855 | 1430 | if err: |
1431 | raise OSError(self._shortError(err)) | |
1432 | return out.strip() == b"True" | |
1433 | ||
1434 | def getBluetoothStatus(self): | |
1435 | """ | |
1436 | Public method to get Bluetooth status data of the connected board. | |
1437 | ||
1438 | @return list of tuples containing the translated status data label and | |
1439 | the associated value | |
1440 | @rtype list of tuples of (str, str) | |
9857 | 1441 | @exception OSError raised to indicate an issue with the device |
9855 | 1442 | """ |
9866 | 1443 | if self.hasCircuitPython(): |
1444 | return self.__cpyDevice.getBluetoothStatus() | |
1445 | ||
9855 | 1446 | command = """ |
1447 | def ble_status(): | |
1448 | import bluetooth | |
1449 | import ubinascii | |
1450 | import ujson | |
1451 | ||
1452 | ble = bluetooth.BLE() | |
1453 | ||
1454 | ble_active = ble.active() | |
1455 | if not ble_active: | |
1456 | ble.active(True) | |
1457 | ||
1458 | res = { | |
1459 | 'active': ble_active, | |
1460 | 'mac': ubinascii.hexlify(ble.config('mac')[1], ':').decode(), | |
1461 | 'addr_type': ble.config('mac')[0], | |
1462 | 'name': ble.config('gap_name'), | |
1463 | 'mtu': ble.config('mtu'), | |
1464 | } | |
1465 | ||
1466 | if not ble_active: | |
1467 | ble.active(False) | |
1468 | ||
1469 | print(ujson.dumps(res)) | |
1470 | ||
1471 | ble_status() | |
1472 | del ble_status | |
1473 | """ | |
9989 | 1474 | out, err = self.executeCommands(command, mode=self._submitMode) |
9855 | 1475 | if err: |
1476 | raise OSError(self._shortError(err)) | |
1477 | ||
1478 | status = [] | |
1479 | bleStatus = json.loads(out.decode("utf-8")) | |
1480 | status.append((self.tr("Active"), self.bool2str(bleStatus["active"]))) | |
1481 | status.append((self.tr("Name"), bleStatus["name"])) | |
1482 | status.append((self.tr("MAC-Address"), bleStatus["mac"])) | |
1483 | status.append( | |
1484 | ( | |
1485 | self.tr("Address Type"), | |
1486 | self.tr("Public") if bleStatus == 0 else self.tr("Random"), | |
1487 | ) | |
1488 | ) | |
9857 | 1489 | status.append((self.tr("MTU"), self.tr("{0} Bytes").format(bleStatus["mtu"]))) |
9855 | 1490 | |
1491 | return status | |
1492 | ||
1493 | def activateBluetoothInterface(self): | |
1494 | """ | |
1495 | Public method to activate the Bluetooth interface. | |
1496 | ||
1497 | @return flag indicating the new state of the Bluetooth interface | |
1498 | @rtype bool | |
9857 | 1499 | @exception OSError raised to indicate an issue with the device |
9855 | 1500 | """ |
9866 | 1501 | if self.hasCircuitPython(): |
1502 | return self.__cpyDevice.activateBluetoothInterface() | |
1503 | ||
9855 | 1504 | command = """ |
1505 | def activate_ble(): | |
1506 | import bluetooth | |
1507 | ||
1508 | ble = bluetooth.BLE() | |
1509 | if not ble.active(): | |
1510 | ble.active(True) | |
1511 | print(ble.active()) | |
1512 | ||
1513 | activate_ble() | |
1514 | del activate_ble | |
1515 | """ | |
9989 | 1516 | out, err = self.executeCommands(command, mode=self._submitMode) |
9855 | 1517 | if err: |
1518 | raise OSError(self._shortError(err)) | |
1519 | ||
1520 | return out.strip() == b"True" | |
1521 | ||
1522 | def deactivateBluetoothInterface(self): | |
1523 | """ | |
1524 | Public method to deactivate the Bluetooth interface. | |
1525 | ||
1526 | @return flag indicating the new state of the Bluetooth interface | |
1527 | @rtype bool | |
9857 | 1528 | @exception OSError raised to indicate an issue with the device |
9855 | 1529 | """ |
9866 | 1530 | if self.hasCircuitPython(): |
1531 | return self.__cpyDevice.deactivateBluetoothInterface() | |
1532 | ||
9855 | 1533 | command = """ |
1534 | def deactivate_ble(): | |
1535 | import bluetooth | |
1536 | ||
1537 | ble = bluetooth.BLE() | |
1538 | if ble.active(): | |
1539 | ble.active(False) | |
1540 | print(ble.active()) | |
1541 | ||
1542 | deactivate_ble() | |
1543 | del deactivate_ble | |
1544 | """ | |
9989 | 1545 | out, err = self.executeCommands(command, mode=self._submitMode) |
9855 | 1546 | if err: |
1547 | raise OSError(self._shortError(err)) | |
1548 | ||
1549 | return out.strip() == b"True" | |
1550 | ||
9859 | 1551 | def getDeviceScan(self, timeout=10): |
1552 | """ | |
1553 | Public method to perform a Bluetooth device scan. | |
1554 | ||
1555 | @param timeout duration of the device scan in seconds (defaults | |
1556 | to 10) | |
1557 | @type int (optional) | |
1558 | @return tuple containing a dictionary with the scan results and | |
1559 | an error string | |
1560 | @rtype tuple of (dict, str) | |
1561 | """ | |
1562 | from ..BluetoothDialogs.BluetoothAdvertisement import BluetoothAdvertisement | |
1563 | ||
9866 | 1564 | if self.hasCircuitPython(): |
1565 | return self.__cpyDevice.getDeviceScan(timeout) | |
1566 | ||
9859 | 1567 | command = """ |
10032
102b79b2a8cd
Finetuned the bluetooth scan function for various MicroPython boards.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10022
diff
changeset
|
1568 | _scan_done = False |
102b79b2a8cd
Finetuned the bluetooth scan function for various MicroPython boards.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10022
diff
changeset
|
1569 | |
9859 | 1570 | def ble_scan(): |
1571 | import bluetooth | |
1572 | import time | |
1573 | import ubinascii | |
1574 | ||
1575 | IRQ_SCAN_RESULT = 5 | |
1576 | IRQ_SCAN_DONE = 6 | |
1577 | ||
1578 | def _bleIrq(event, data): | |
10032
102b79b2a8cd
Finetuned the bluetooth scan function for various MicroPython boards.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10022
diff
changeset
|
1579 | global _scan_done |
9859 | 1580 | if event == IRQ_SCAN_RESULT: |
1581 | addr_type, addr, adv_type, rssi, adv_data = data | |
1582 | if addr: | |
1583 | print({{ | |
1584 | 'address': ubinascii.hexlify(addr,':').decode('utf-8'), | |
1585 | 'rssi': rssi, | |
1586 | 'adv_type': adv_type, | |
1587 | 'advertisement': bytes(adv_data), | |
1588 | }}) | |
10032
102b79b2a8cd
Finetuned the bluetooth scan function for various MicroPython boards.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10022
diff
changeset
|
1589 | elif event == IRQ_SCAN_DONE: |
102b79b2a8cd
Finetuned the bluetooth scan function for various MicroPython boards.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10022
diff
changeset
|
1590 | _scan_done = True |
9859 | 1591 | |
1592 | ble = bluetooth.BLE() | |
1593 | ||
1594 | ble_active = ble.active() | |
1595 | if not ble_active: | |
1596 | ble.active(True) | |
1597 | ||
1598 | ble.irq(_bleIrq) | |
1599 | ble.gap_scan({0} * 1000, 1000000, 50000, True) | |
10032
102b79b2a8cd
Finetuned the bluetooth scan function for various MicroPython boards.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10022
diff
changeset
|
1600 | while not _scan_done: |
102b79b2a8cd
Finetuned the bluetooth scan function for various MicroPython boards.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10022
diff
changeset
|
1601 | time.sleep(0.2) |
9859 | 1602 | |
1603 | if not ble_active: | |
1604 | ble.active(False) | |
1605 | ||
1606 | ble_scan() | |
10032
102b79b2a8cd
Finetuned the bluetooth scan function for various MicroPython boards.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10022
diff
changeset
|
1607 | del ble_scan, _scan_done |
9859 | 1608 | """.format( |
1609 | timeout | |
1610 | ) | |
9989 | 1611 | out, err = self.executeCommands( |
9859 | 1612 | command, mode=self._submitMode, timeout=(timeout + 5) * 1000 |
1613 | ) | |
1614 | if err: | |
1615 | return {}, err | |
1616 | ||
1617 | scanResults = {} | |
1618 | for line in out.decode("utf-8").splitlines(): | |
1619 | res = ast.literal_eval(line) | |
1620 | address = res["address"] | |
1621 | if address not in scanResults: | |
1622 | scanResults[address] = BluetoothAdvertisement(address) | |
1623 | scanResults[address].update( | |
1624 | res["adv_type"], res["rssi"], res["advertisement"] | |
1625 | ) | |
1626 | ||
1627 | return scanResults, "" | |
1628 | ||
9868 | 1629 | ################################################################## |
1630 | ## Methods below implement NTP related methods | |
1631 | ################################################################## | |
1632 | ||
1633 | def hasNetworkTime(self): | |
1634 | """ | |
1635 | Public method to check the availability of network time functions. | |
1636 | ||
1637 | @return flag indicating the availability of network time functions | |
1638 | @rtype bool | |
9870
0399d3607829
Fixed a few code formatting and style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9868
diff
changeset
|
1639 | @exception OSError raised to indicate an issue with the device |
9868 | 1640 | """ |
1641 | if self.hasCircuitPython(): | |
1642 | self.__createCpyDevice() | |
1643 | return self.__cpyDevice.hasNetworkTime() | |
1644 | ||
1645 | command = """ | |
1646 | def has_ntp(): | |
1647 | try: | |
1648 | import ntptime | |
1649 | return True | |
1650 | except ImportError: | |
1651 | return False | |
1652 | ||
1653 | print(has_ntp()) | |
1654 | del has_ntp | |
1655 | """ | |
9989 | 1656 | out, err = self.executeCommands(command, mode=self._submitMode) |
9868 | 1657 | if err: |
1658 | raise OSError(self._shortError(err)) | |
1659 | return out.strip() == b"True" | |
1660 | ||
1661 | def setNetworkTime(self, server="0.pool.ntp.org", tzOffset=0, timeout=10): | |
1662 | """ | |
1663 | Public method to set the time to the network time retrieved from an | |
1664 | NTP server. | |
1665 | ||
1666 | @param server name of the NTP server to get the network time from | |
1667 | (defaults to "0.pool.ntp.org") | |
1668 | @type str (optional) | |
1669 | @param tzOffset offset with respect to UTC (defaults to 0) | |
1670 | @type int (optional) | |
1671 | @param timeout maximum time to wait for a server response in seconds | |
1672 | (defaults to 10) | |
1673 | @type int | |
1674 | @return tuple containing a flag indicating success and an error string | |
1675 | @rtype tuple of (bool, str) | |
1676 | """ | |
1677 | if self.hasCircuitPython(): | |
1678 | return self.__cpyDevice.setNetworkTime( | |
1679 | server=server, tzOffset=tzOffset, timeout=timeout | |
1680 | ) | |
1681 | ||
1682 | command = """ | |
1683 | def set_ntp_time(server, tz_offset, timeout): | |
1684 | import network | |
1685 | import ntptime | |
1686 | import machine | |
1687 | ||
1688 | if not network.WLAN(network.STA_IF).isconnected(): | |
1689 | return False | |
1690 | ||
1691 | ntptime.host = server | |
1692 | ntptime.timeout = timeout | |
1693 | ntptime.settime() | |
1694 | ||
1695 | rtc = machine.RTC() | |
1696 | t = list(rtc.datetime()) | |
1697 | t[4] += tz_offset | |
1698 | rtc.datetime(t) | |
1699 | ||
1700 | return True | |
1701 | ||
1702 | try: | |
1703 | print({{ | |
1704 | 'result': set_ntp_time({0}, {1}, {2}), | |
1705 | 'error': '', | |
1706 | }}) | |
1707 | except Exception as err: | |
1708 | print({{ | |
1709 | 'result': False, | |
1710 | 'error': str(err), | |
1711 | }}) | |
1712 | del set_ntp_time | |
1713 | """.format( | |
1714 | repr(server), tzOffset, timeout | |
1715 | ) | |
9989 | 1716 | out, err = self.executeCommands( |
9868 | 1717 | command, mode=self._submitMode, timeout=(timeout + 2) * 1000 |
1718 | ) | |
1719 | if err: | |
1720 | return False, err | |
1721 | else: | |
1722 | res = ast.literal_eval(out.decode("utf-8")) | |
1723 | return res["result"], res["error"] | |
1724 | ||
9496
05017f795c24
Changed MicroPython device imports to use importlib.import_module().
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9473
diff
changeset
|
1725 | |
10683
779cda568acb
Changed the source code and the source code documentation to improve the indication of unused method/function arguments.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10439
diff
changeset
|
1726 | def createDevice(microPythonWidget, deviceType, _vid, _pid, _boardName, _serialNumber): |
9496
05017f795c24
Changed MicroPython device imports to use importlib.import_module().
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9473
diff
changeset
|
1727 | """ |
05017f795c24
Changed MicroPython device imports to use importlib.import_module().
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9473
diff
changeset
|
1728 | Function to instantiate a MicroPython device object. |
05017f795c24
Changed MicroPython device imports to use importlib.import_module().
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9473
diff
changeset
|
1729 | |
05017f795c24
Changed MicroPython device imports to use importlib.import_module().
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9473
diff
changeset
|
1730 | @param microPythonWidget reference to the main MicroPython widget |
05017f795c24
Changed MicroPython device imports to use importlib.import_module().
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9473
diff
changeset
|
1731 | @type MicroPythonWidget |
05017f795c24
Changed MicroPython device imports to use importlib.import_module().
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9473
diff
changeset
|
1732 | @param deviceType device type assigned to this device interface |
05017f795c24
Changed MicroPython device imports to use importlib.import_module().
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9473
diff
changeset
|
1733 | @type str |
10683
779cda568acb
Changed the source code and the source code documentation to improve the indication of unused method/function arguments.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10439
diff
changeset
|
1734 | @param _vid vendor ID (unused) |
9496
05017f795c24
Changed MicroPython device imports to use importlib.import_module().
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9473
diff
changeset
|
1735 | @type int |
10683
779cda568acb
Changed the source code and the source code documentation to improve the indication of unused method/function arguments.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10439
diff
changeset
|
1736 | @param _pid product ID (unused) |
9496
05017f795c24
Changed MicroPython device imports to use importlib.import_module().
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9473
diff
changeset
|
1737 | @type int |
10683
779cda568acb
Changed the source code and the source code documentation to improve the indication of unused method/function arguments.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10439
diff
changeset
|
1738 | @param _boardName name of the board (unused) |
9738 | 1739 | @type str |
10683
779cda568acb
Changed the source code and the source code documentation to improve the indication of unused method/function arguments.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10439
diff
changeset
|
1740 | @param _serialNumber serial number of the board (unused) |
9751
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9749
diff
changeset
|
1741 | @type str |
9496
05017f795c24
Changed MicroPython device imports to use importlib.import_module().
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9473
diff
changeset
|
1742 | @return reference to the instantiated device object |
05017f795c24
Changed MicroPython device imports to use importlib.import_module().
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9473
diff
changeset
|
1743 | @rtype EspDevice |
05017f795c24
Changed MicroPython device imports to use importlib.import_module().
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9473
diff
changeset
|
1744 | """ |
05017f795c24
Changed MicroPython device imports to use importlib.import_module().
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9473
diff
changeset
|
1745 | return EspDevice(microPythonWidget, deviceType) |
9820 | 1746 | |
1747 | ||
1748 | ################################################################################ | |
1749 | ## Functions below implement flashing related functionality needed elsewhere ## | |
1750 | ## as well. ## | |
1751 | ################################################################################ | |
1752 | ||
1753 | ||
1754 | @pyqtSlot() | |
11006
a671918232f3
Modified modal dialog usage to always include a valid parent (needed for Wayland).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11005
diff
changeset
|
1755 | def eraseFlash(port, parent=None): |
9820 | 1756 | """ |
1757 | Slot to erase the device flash memory. | |
1758 | ||
1759 | @param port name of the serial port device to be used | |
1760 | @type str | |
11006
a671918232f3
Modified modal dialog usage to always include a valid parent (needed for Wayland).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11005
diff
changeset
|
1761 | @param parent reference to the parent widget (defaults to None) |
a671918232f3
Modified modal dialog usage to always include a valid parent (needed for Wayland).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11005
diff
changeset
|
1762 | @type QWidget |
9820 | 1763 | """ |
1764 | ok = EricMessageBox.yesNo( | |
11006
a671918232f3
Modified modal dialog usage to always include a valid parent (needed for Wayland).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11005
diff
changeset
|
1765 | parent, |
9820 | 1766 | QCoreApplication.translate("EspDevice", "Erase Flash"), |
1767 | QCoreApplication.translate( | |
1768 | "EspDevice", """Shall the flash of the selected device really be erased?""" | |
1769 | ), | |
1770 | ) | |
1771 | if ok: | |
1772 | flashArgs = [ | |
1773 | "-u", | |
1774 | "-m", | |
1775 | "esptool", | |
1776 | "--port", | |
1777 | port, | |
1778 | "erase_flash", | |
1779 | ] | |
1780 | dlg = EricProcessDialog( | |
1781 | QCoreApplication.translate("EspDevice", "'esptool erase_flash' Output"), | |
1782 | QCoreApplication.translate("EspDevice", "Erase Flash"), | |
1783 | showProgress=True, | |
10933
95a15b70f7bb
Refactored some packages, modules and code to allow extracting the 'EricXxx' packages into a library project.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10806
diff
changeset
|
1784 | monospacedFont=Preferences.getEditorOtherFonts("MonospacedFont"), |
95a15b70f7bb
Refactored some packages, modules and code to allow extracting the 'EricXxx' packages into a library project.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10806
diff
changeset
|
1785 | encoding=Preferences.getSystem("IOEncoding"), |
11006
a671918232f3
Modified modal dialog usage to always include a valid parent (needed for Wayland).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11005
diff
changeset
|
1786 | parent=parent, |
9820 | 1787 | ) |
1788 | res = dlg.startProcess(PythonUtilities.getPythonExecutable(), flashArgs) | |
1789 | if res: | |
1790 | dlg.exec() | |
1791 | ||
1792 | ||
1793 | @pyqtSlot() | |
11005
b918c6c2736b
MicroPython Interface
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10933
diff
changeset
|
1794 | def flashPythonFirmware(port, parent=None): |
9820 | 1795 | """ |
1796 | Slot to flash a MicroPython firmware to the device. | |
1797 | ||
1798 | @param port name of the serial port device to be used | |
1799 | @type str | |
11005
b918c6c2736b
MicroPython Interface
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10933
diff
changeset
|
1800 | @param parent reference to the parent widget (defaults to None) |
b918c6c2736b
MicroPython Interface
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10933
diff
changeset
|
1801 | @type QWidget |
9820 | 1802 | """ |
1803 | from .EspDialogs.EspFirmwareSelectionDialog import EspFirmwareSelectionDialog | |
1804 | ||
11005
b918c6c2736b
MicroPython Interface
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10933
diff
changeset
|
1805 | dlg = EspFirmwareSelectionDialog(parent=parent) |
9820 | 1806 | if dlg.exec() == QDialog.DialogCode.Accepted: |
1807 | chip, firmware, baudRate, flashMode, flashAddress = dlg.getData() | |
1808 | flashArgs = [ | |
1809 | "-u", | |
1810 | "-m", | |
1811 | "esptool", | |
1812 | "--chip", | |
1813 | chip, | |
1814 | "--port", | |
1815 | port, | |
1816 | ] | |
1817 | if baudRate != "115200": | |
1818 | flashArgs += ["--baud", baudRate] | |
1819 | flashArgs.append("write_flash") | |
1820 | if flashMode: | |
1821 | flashArgs += ["--flash_mode", flashMode] | |
9848
3d750b2e012c
Corrected flashing of ESP 8266 devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9836
diff
changeset
|
1822 | if chip == "esp8266": |
3d750b2e012c
Corrected flashing of ESP 8266 devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9836
diff
changeset
|
1823 | # ESP 8266 seems to need flash size detection |
3d750b2e012c
Corrected flashing of ESP 8266 devices.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9836
diff
changeset
|
1824 | flashArgs += ["--flash_size", "detect"] |
9820 | 1825 | flashArgs += [ |
1826 | flashAddress, | |
1827 | firmware, | |
1828 | ] | |
1829 | dlg = EricProcessDialog( | |
1830 | QCoreApplication.translate("EspDevice", "'esptool write_flash' Output"), | |
1831 | QCoreApplication.translate("EspDevice", "Flash µPy/CPy Firmware"), | |
1832 | showProgress=True, | |
10933
95a15b70f7bb
Refactored some packages, modules and code to allow extracting the 'EricXxx' packages into a library project.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10806
diff
changeset
|
1833 | monospacedFont=Preferences.getEditorOtherFonts("MonospacedFont"), |
95a15b70f7bb
Refactored some packages, modules and code to allow extracting the 'EricXxx' packages into a library project.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10806
diff
changeset
|
1834 | encoding=Preferences.getSystem("IOEncoding"), |
11006
a671918232f3
Modified modal dialog usage to always include a valid parent (needed for Wayland).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11005
diff
changeset
|
1835 | parent=parent, |
9820 | 1836 | ) |
1837 | res = dlg.startProcess(PythonUtilities.getPythonExecutable(), flashArgs) | |
1838 | if res: | |
1839 | dlg.exec() | |
1840 | ||
1841 | ||
1842 | @pyqtSlot() | |
11005
b918c6c2736b
MicroPython Interface
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10933
diff
changeset
|
1843 | def flashAddonFirmware(port, parent=None): |
9820 | 1844 | """ |
1845 | Slot to flash some additional firmware images. | |
1846 | ||
1847 | @param port name of the serial port device to be used | |
1848 | @type str | |
11005
b918c6c2736b
MicroPython Interface
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10933
diff
changeset
|
1849 | @param parent reference to the parent widget (defaults to None) |
b918c6c2736b
MicroPython Interface
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10933
diff
changeset
|
1850 | @type QWidget |
9820 | 1851 | """ |
1852 | from .EspDialogs.EspFirmwareSelectionDialog import EspFirmwareSelectionDialog | |
1853 | ||
11005
b918c6c2736b
MicroPython Interface
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10933
diff
changeset
|
1854 | dlg = EspFirmwareSelectionDialog(addon=True, parent=parent) |
9820 | 1855 | if dlg.exec() == QDialog.DialogCode.Accepted: |
1856 | chip, firmware, baudRate, flashMode, flashAddress = dlg.getData() | |
1857 | flashArgs = [ | |
1858 | "-u", | |
1859 | "-m", | |
1860 | "esptool", | |
1861 | "--chip", | |
1862 | chip, | |
1863 | "--port", | |
1864 | port, | |
1865 | ] | |
1866 | if baudRate != "115200": | |
1867 | flashArgs += ["--baud", baudRate] | |
1868 | flashArgs.append("write_flash") | |
1869 | if flashMode: | |
1870 | flashArgs += ["--flash_mode", flashMode] | |
1871 | flashArgs += [ | |
1872 | flashAddress.lower(), | |
1873 | firmware, | |
1874 | ] | |
1875 | dlg = EricProcessDialog( | |
1876 | QCoreApplication.translate("EspDevice", "'esptool write_flash' Output"), | |
1877 | QCoreApplication.translate("EspDevice", "Flash Additional Firmware"), | |
1878 | showProgress=True, | |
10933
95a15b70f7bb
Refactored some packages, modules and code to allow extracting the 'EricXxx' packages into a library project.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10806
diff
changeset
|
1879 | monospacedFont=Preferences.getEditorOtherFonts("MonospacedFont"), |
95a15b70f7bb
Refactored some packages, modules and code to allow extracting the 'EricXxx' packages into a library project.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10806
diff
changeset
|
1880 | encoding=Preferences.getSystem("IOEncoding"), |
11006
a671918232f3
Modified modal dialog usage to always include a valid parent (needed for Wayland).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11005
diff
changeset
|
1881 | parent=parent, |
9820 | 1882 | ) |
1883 | res = dlg.startProcess(PythonUtilities.getPythonExecutable(), flashArgs) | |
1884 | if res: | |
1885 | dlg.exec() |