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