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