Wed, 01 Mar 2023 19:53:49 +0100
MicroPython
- corrected some execute() calls
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 | |
9653
e67609152c5e
Updated copyright for 2023.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9624
diff
changeset
|
3 | # Copyright (c) 2019 - 2023 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 |
9854647c8c5c
Reorganized the MicroPython package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9752
diff
changeset
|
29 | from .DeviceBase import BaseDevice |
7059
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
30 | |
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
31 | |
9756
9854647c8c5c
Reorganized the MicroPython package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9752
diff
changeset
|
32 | class EspDevice(BaseDevice): |
7059
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
33 | """ |
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
34 | 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
|
35 | """ |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
36 | |
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
|
37 | def __init__(self, microPythonWidget, deviceType, parent=None): |
7059
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
38 | """ |
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
39 | Constructor |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
40 | |
7059
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
41 | @param microPythonWidget reference to the main MicroPython widget |
7134
21d23ca51680
Renamed "MicroPythonReplWidget" to "MicroPythonWidget".
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7125
diff
changeset
|
42 | @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
|
43 | @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
|
44 | @type str |
7059
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
45 | @param parent reference to the parent object |
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
46 | @type QObject |
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
47 | """ |
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
|
48 | 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
|
49 | |
9752
2b9546c0cbd9
Moved the MicroPython board specific functions to a separate submenu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9751
diff
changeset
|
50 | self.__createEsp32Submenu() |
2b9546c0cbd9
Moved the MicroPython board specific functions to a separate submenu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9751
diff
changeset
|
51 | |
9795 | 52 | self.__statusTranslations = { |
53 | 200: self.tr("beacon timeout"), | |
54 | 201: self.tr("no matching access point found"), | |
55 | 202: self.tr("authentication failed"), | |
56 | 203: self.tr("association failed"), | |
57 | 204: self.tr("handshake timeout"), | |
58 | 1000: self.tr("idle"), | |
59 | 1001: self.tr("connecting"), | |
60 | 1010: self.tr("connected"), | |
61 | } | |
62 | self.__securityTranslations = { | |
63 | 0: self.tr("open", "open WiFi network"), | |
64 | 1: "WEP", | |
65 | 2: "WPA", | |
66 | 3: "WPA2", | |
67 | 4: "WPA/WPA2", | |
68 | 5: "WPA2 (CCMP)", | |
69 | 6: "WPA3", | |
70 | 7: "WPA2/WPA3", | |
71 | } | |
72 | ||
7059
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
73 | def setButtons(self): |
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
74 | """ |
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
75 | Public method to enable the supported action buttons. |
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
76 | """ |
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
|
77 | 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
|
78 | |
7059
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
79 | self.microPython.setActionButtons( |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
80 | 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
|
81 | ) |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
82 | |
7059
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
83 | def forceInterrupt(self): |
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
84 | """ |
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
85 | 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
|
86 | serial connection. |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
87 | |
7059
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
88 | @return flag indicating an interrupt is needed |
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
89 | @rtype bool |
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
90 | """ |
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
91 | return True |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
92 | |
7125
2028553ee58c
CircuitPythonDevices, EspDevices, MicroPythonDevices: added a method to get the device name.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7115
diff
changeset
|
93 | 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
|
94 | """ |
2028553ee58c
CircuitPythonDevices, EspDevices, MicroPythonDevices: added a method to get the device name.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7115
diff
changeset
|
95 | 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
|
96 | |
7125
2028553ee58c
CircuitPythonDevices, EspDevices, MicroPythonDevices: added a method to get the device name.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7115
diff
changeset
|
97 | @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
|
98 | @rtype str |
2028553ee58c
CircuitPythonDevices, EspDevices, MicroPythonDevices: added a method to get the device name.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7115
diff
changeset
|
99 | """ |
2028553ee58c
CircuitPythonDevices, EspDevices, MicroPythonDevices: added a method to get the device name.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7115
diff
changeset
|
100 | 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
|
101 | |
7059
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
102 | def canStartRepl(self): |
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
103 | """ |
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
104 | 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
|
105 | |
7059
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
106 | @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
|
107 | and a reason why it cannot. |
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
108 | @rtype tuple of (bool, str) |
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
109 | """ |
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
|
110 | return True, "" |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
111 | |
7059
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
112 | def canStartPlotter(self): |
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
113 | """ |
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
114 | 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
|
115 | |
7059
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
116 | @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
|
117 | Plotter and a reason why it cannot. |
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
118 | @rtype tuple of (bool, str) |
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
119 | """ |
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
|
120 | return True, "" |
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 | def canRunScript(self): |
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
123 | """ |
7091
84d2a73b448a
EspDevices, MicroPythonDevices: fixed a wrong source docu string.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7077
diff
changeset
|
124 | 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
|
125 | |
7059
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
126 | @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
|
127 | Plotter and a reason why it cannot. |
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
128 | @rtype tuple of (bool, str) |
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
129 | """ |
8119
1653972f2de5
EspDevices: fixed a typo and a little issue.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8117
diff
changeset
|
130 | return True, "" |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
131 | |
7059
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
132 | def runScript(self, script): |
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
133 | """ |
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
134 | 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
|
135 | |
7059
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
136 | @param script script to be executed |
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
137 | @type str |
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
138 | """ |
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
139 | pythonScript = script.split("\n") |
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
140 | self.sendCommands(pythonScript) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
141 | |
7059
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
142 | def canStartFileManager(self): |
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
143 | """ |
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
144 | 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
|
145 | |
7059
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
146 | @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
|
147 | File Manager and a reason why it cannot. |
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
148 | @rtype tuple of (bool, str) |
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
149 | """ |
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
|
150 | return True, "" |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
151 | |
9752
2b9546c0cbd9
Moved the MicroPython board specific functions to a separate submenu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9751
diff
changeset
|
152 | def __createEsp32Submenu(self): |
2b9546c0cbd9
Moved the MicroPython board specific functions to a separate submenu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9751
diff
changeset
|
153 | """ |
2b9546c0cbd9
Moved the MicroPython board specific functions to a separate submenu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9751
diff
changeset
|
154 | 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
|
155 | """ |
2b9546c0cbd9
Moved the MicroPython board specific functions to a separate submenu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9751
diff
changeset
|
156 | 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
|
157 | |
2b9546c0cbd9
Moved the MicroPython board specific functions to a separate submenu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9751
diff
changeset
|
158 | 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
|
159 | 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
|
160 | ) |
2b9546c0cbd9
Moved the MicroPython board specific functions to a separate submenu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9751
diff
changeset
|
161 | self.__espMenu.addSeparator() |
2b9546c0cbd9
Moved the MicroPython board specific functions to a separate submenu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9751
diff
changeset
|
162 | 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
|
163 | 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
|
164 | ) |
2b9546c0cbd9
Moved the MicroPython board specific functions to a separate submenu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9751
diff
changeset
|
165 | 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
|
166 | 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
|
167 | ) |
2b9546c0cbd9
Moved the MicroPython board specific functions to a separate submenu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9751
diff
changeset
|
168 | self.__espMenu.addSeparator() |
2b9546c0cbd9
Moved the MicroPython board specific functions to a separate submenu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9751
diff
changeset
|
169 | 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
|
170 | 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
|
171 | ) |
2b9546c0cbd9
Moved the MicroPython board specific functions to a separate submenu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9751
diff
changeset
|
172 | self.__espMenu.addSeparator() |
2b9546c0cbd9
Moved the MicroPython board specific functions to a separate submenu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9751
diff
changeset
|
173 | 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
|
174 | 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
|
175 | ) |
2b9546c0cbd9
Moved the MicroPython board specific functions to a separate submenu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9751
diff
changeset
|
176 | 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
|
177 | 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
|
178 | ) |
2b9546c0cbd9
Moved the MicroPython board specific functions to a separate submenu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9751
diff
changeset
|
179 | self.__espMenu.addSeparator() |
2b9546c0cbd9
Moved the MicroPython board specific functions to a separate submenu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9751
diff
changeset
|
180 | 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
|
181 | 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
|
182 | ) |
2b9546c0cbd9
Moved the MicroPython board specific functions to a separate submenu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9751
diff
changeset
|
183 | 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
|
184 | 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
|
185 | ) |
2b9546c0cbd9
Moved the MicroPython board specific functions to a separate submenu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9751
diff
changeset
|
186 | 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
|
187 | 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
|
188 | ) |
2b9546c0cbd9
Moved the MicroPython board specific functions to a separate submenu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9751
diff
changeset
|
189 | self.__espMenu.addSeparator() |
2b9546c0cbd9
Moved the MicroPython board specific functions to a separate submenu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9751
diff
changeset
|
190 | 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
|
191 | 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
|
192 | ) |
2b9546c0cbd9
Moved the MicroPython board specific functions to a separate submenu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9751
diff
changeset
|
193 | self.__espMenu.addSeparator() |
2b9546c0cbd9
Moved the MicroPython board specific functions to a separate submenu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9751
diff
changeset
|
194 | 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
|
195 | |
7108
4f6133a01c6a
Started rearranging menu structure and testing and fixing on CircuitPython.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7100
diff
changeset
|
196 | 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
|
197 | """ |
4f6133a01c6a
Started rearranging menu structure and testing and fixing on CircuitPython.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7100
diff
changeset
|
198 | 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
|
199 | |
7108
4f6133a01c6a
Started rearranging menu structure and testing and fixing on CircuitPython.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7100
diff
changeset
|
200 | @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
|
201 | @type QMenu |
4f6133a01c6a
Started rearranging menu structure and testing and fixing on CircuitPython.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7100
diff
changeset
|
202 | """ |
4f6133a01c6a
Started rearranging menu structure and testing and fixing on CircuitPython.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7100
diff
changeset
|
203 | connected = self.microPython.isConnected() |
9749 | 204 | linkConnected = self.microPython.isLinkConnected() |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
205 | |
9752
2b9546c0cbd9
Moved the MicroPython board specific functions to a separate submenu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9751
diff
changeset
|
206 | 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
|
207 | 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
|
208 | 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
|
209 | 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
|
210 | 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
|
211 | 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
|
212 | 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
|
213 | 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
|
214 | 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
|
215 | 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
|
216 | |
2b9546c0cbd9
Moved the MicroPython board specific functions to a separate submenu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9751
diff
changeset
|
217 | menu.addMenu(self.__espMenu) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
218 | |
8096 | 219 | def hasFlashMenuEntry(self): |
220 | """ | |
221 | 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
|
222 | |
8096 | 223 | @return flag indicating a specific flash menu entry |
224 | @rtype bool | |
225 | """ | |
226 | return True | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
227 | |
7108
4f6133a01c6a
Started rearranging menu structure and testing and fixing on CircuitPython.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7100
diff
changeset
|
228 | @pyqtSlot() |
4f6133a01c6a
Started rearranging menu structure and testing and fixing on CircuitPython.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7100
diff
changeset
|
229 | def __eraseFlash(self): |
4f6133a01c6a
Started rearranging menu structure and testing and fixing on CircuitPython.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7100
diff
changeset
|
230 | """ |
4f6133a01c6a
Started rearranging menu structure and testing and fixing on CircuitPython.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7100
diff
changeset
|
231 | 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
|
232 | """ |
9820 | 233 | eraseFlash(self.microPython.getCurrentPort()) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
234 | |
7108
4f6133a01c6a
Started rearranging menu structure and testing and fixing on CircuitPython.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7100
diff
changeset
|
235 | @pyqtSlot() |
4f6133a01c6a
Started rearranging menu structure and testing and fixing on CircuitPython.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7100
diff
changeset
|
236 | def __flashMicroPython(self): |
4f6133a01c6a
Started rearranging menu structure and testing and fixing on CircuitPython.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7100
diff
changeset
|
237 | """ |
4f6133a01c6a
Started rearranging menu structure and testing and fixing on CircuitPython.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7100
diff
changeset
|
238 | 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
|
239 | """ |
9820 | 240 | flashPythonFirmware(self.microPython.getCurrentPort()) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
241 | |
7108
4f6133a01c6a
Started rearranging menu structure and testing and fixing on CircuitPython.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7100
diff
changeset
|
242 | @pyqtSlot() |
4f6133a01c6a
Started rearranging menu structure and testing and fixing on CircuitPython.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7100
diff
changeset
|
243 | def __flashAddons(self): |
4f6133a01c6a
Started rearranging menu structure and testing and fixing on CircuitPython.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7100
diff
changeset
|
244 | """ |
4f6133a01c6a
Started rearranging menu structure and testing and fixing on CircuitPython.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7100
diff
changeset
|
245 | 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
|
246 | """ |
9820 | 247 | flashAddonFirmware(self.microPython.getCurrentPort()) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
248 | |
7108
4f6133a01c6a
Started rearranging menu structure and testing and fixing on CircuitPython.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7100
diff
changeset
|
249 | @pyqtSlot() |
7352 | 250 | def __backupFlash(self): |
251 | """ | |
252 | Private slot to backup the currently flashed firmware. | |
253 | """ | |
9756
9854647c8c5c
Reorganized the MicroPython package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9752
diff
changeset
|
254 | from .EspDialogs.EspBackupRestoreFirmwareDialog import ( |
9765
6378da868bb0
Reorganized the MicroPython code even more.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
255 | EspBackupRestoreFirmwareDialog, |
9756
9854647c8c5c
Reorganized the MicroPython package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9752
diff
changeset
|
256 | ) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
257 | |
7352 | 258 | 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
|
259 | if dlg.exec() == QDialog.DialogCode.Accepted: |
8945 | 260 | chip, flashSize, baudRate, flashMode, firmware = dlg.getData() |
7352 | 261 | flashArgs = [ |
262 | "-u", | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
263 | "-m", |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
264 | "esptool", |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
265 | "--chip", |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
266 | chip, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
267 | "--port", |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
268 | self.microPython.getCurrentPort(), |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
269 | "--baud", |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
270 | baudRate, |
7352 | 271 | "read_flash", |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
272 | "0x0", |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
273 | flashSize, |
7352 | 274 | firmware, |
275 | ] | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
276 | dlg = EricProcessDialog( |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
277 | 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
|
278 | self.tr("Backup Firmware"), |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
279 | showProgress=True, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
280 | ) |
9624
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9576
diff
changeset
|
281 | res = dlg.startProcess(PythonUtilities.getPythonExecutable(), flashArgs) |
7352 | 282 | if res: |
7759
51aa6c6b66f7
Changed calls to exec_() into exec() (remainder of Python2 elimination).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7595
diff
changeset
|
283 | dlg.exec() |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
284 | |
7352 | 285 | @pyqtSlot() |
286 | def __restoreFlash(self): | |
287 | """ | |
288 | Private slot to restore a previously saved firmware. | |
289 | """ | |
9756
9854647c8c5c
Reorganized the MicroPython package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9752
diff
changeset
|
290 | from .EspDialogs.EspBackupRestoreFirmwareDialog import ( |
9765
6378da868bb0
Reorganized the MicroPython code even more.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
291 | EspBackupRestoreFirmwareDialog, |
9756
9854647c8c5c
Reorganized the MicroPython package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9752
diff
changeset
|
292 | ) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
293 | |
7352 | 294 | 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
|
295 | if dlg.exec() == QDialog.DialogCode.Accepted: |
8945 | 296 | chip, flashSize, baudRate, flashMode, firmware = dlg.getData() |
7352 | 297 | flashArgs = [ |
298 | "-u", | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
299 | "-m", |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
300 | "esptool", |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
301 | "--chip", |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
302 | chip, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
303 | "--port", |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
304 | self.microPython.getCurrentPort(), |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
305 | "--baud", |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
306 | baudRate, |
7352 | 307 | "write_flash", |
308 | ] | |
8945 | 309 | if flashMode: |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
310 | flashArgs.extend( |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
311 | [ |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
312 | "--flash_mode", |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
313 | flashMode, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
314 | ] |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
315 | ) |
7352 | 316 | if bool(flashSize): |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
317 | flashArgs.extend( |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
318 | [ |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
319 | "--flash_size", |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
320 | flashSize, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
321 | ] |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
322 | ) |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
323 | flashArgs.extend( |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
324 | [ |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
325 | "0x0", |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
326 | firmware, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
327 | ] |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
328 | ) |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
329 | dlg = EricProcessDialog( |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
330 | 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
|
331 | self.tr("Restore Firmware"), |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
332 | showProgress=True, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
333 | ) |
9624
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9576
diff
changeset
|
334 | res = dlg.startProcess(PythonUtilities.getPythonExecutable(), flashArgs) |
7352 | 335 | if res: |
7759
51aa6c6b66f7
Changed calls to exec_() into exec() (remainder of Python2 elimination).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7595
diff
changeset
|
336 | dlg.exec() |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
337 | |
7352 | 338 | @pyqtSlot() |
9749 | 339 | def __showFirmwareVersions(self): |
340 | """ | |
341 | Private slot to show the firmware version of the connected device and the | |
342 | available firmware version. | |
343 | """ | |
344 | if 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
|
345 | 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
|
346 | 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
|
347 | 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
|
348 | 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
|
349 | else: |
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9749
diff
changeset
|
350 | EricMessageBox.critical( |
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9749
diff
changeset
|
351 | None, |
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9749
diff
changeset
|
352 | 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
|
353 | self.tr( |
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9749
diff
changeset
|
354 | """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
|
355 | """ 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
|
356 | """ or CircuitPython. Aborting...""" |
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9749
diff
changeset
|
357 | ), |
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9749
diff
changeset
|
358 | ) |
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9749
diff
changeset
|
359 | return |
9749 | 360 | |
9751
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9749
diff
changeset
|
361 | 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
|
362 | request = QNetworkRequest(url) |
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9749
diff
changeset
|
363 | 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
|
364 | 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
|
365 | |
9820 | 366 | @pyqtSlot(QNetworkReply) |
9751
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9749
diff
changeset
|
367 | def __firmwareVersionResponse(self, reply): |
9749 | 368 | """ |
9820 | 369 | Private slot handling the response of the latest version request. |
9749 | 370 | |
371 | @param reply reference to the reply object | |
372 | @type QNetworkReply | |
373 | """ | |
374 | latestUrl = reply.url().toString() | |
375 | tag = latestUrl.rsplit("/", 1)[-1] | |
376 | while tag and not tag[0].isdecimal(): | |
377 | # get rid of leading non-decimal characters | |
378 | tag = tag[1:] | |
379 | latestVersion = Globals.versionToTuple(tag) | |
380 | ||
9751
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9749
diff
changeset
|
381 | if self._deviceData["mpy_version"] == "unknown": |
9749 | 382 | currentVersionStr = self.tr("unknown") |
383 | currentVersion = (0, 0, 0) | |
384 | else: | |
9751
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9749
diff
changeset
|
385 | currentVersionStr = self._deviceData["mpy_version"] |
9749 | 386 | currentVersion = Globals.versionToTuple(currentVersionStr) |
387 | ||
9751
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9749
diff
changeset
|
388 | if self._deviceData["mpy_name"] == "circuitpython": |
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9749
diff
changeset
|
389 | kind = "CircuitPython" |
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9749
diff
changeset
|
390 | elif self._deviceData["mpy_name"] == "micropython": |
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9749
diff
changeset
|
391 | kind = "MicroPython" |
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9749
diff
changeset
|
392 | |
9749 | 393 | 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
|
394 | "<h4>{0} Version Information</h4>" |
9749 | 395 | "<table>" |
9751
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9749
diff
changeset
|
396 | "<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
|
397 | "<tr><td>Available:</td><td>{2}</td></tr>" |
9749 | 398 | "</table>" |
9751
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9749
diff
changeset
|
399 | ).format(kind, currentVersionStr, tag) |
9749 | 400 | if currentVersion < latestVersion: |
401 | msg += self.tr("<p><b>Update available!</b></p>") | |
402 | ||
403 | EricMessageBox.information( | |
404 | None, | |
9751
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9749
diff
changeset
|
405 | self.tr("{0} Version").format(kind), |
9749 | 406 | msg, |
407 | ) | |
408 | ||
409 | @pyqtSlot() | |
7346 | 410 | def __showChipID(self): |
411 | """ | |
412 | Private slot to show the ID of the ESP chip. | |
413 | """ | |
414 | args = [ | |
415 | "-u", | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
416 | "-m", |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
417 | "esptool", |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
418 | "--port", |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
419 | self.microPython.getCurrentPort(), |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
420 | "chip_id", |
7346 | 421 | ] |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
422 | dlg = EricProcessDialog( |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
423 | 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
|
424 | ) |
9624
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9576
diff
changeset
|
425 | res = dlg.startProcess(PythonUtilities.getPythonExecutable(), args) |
7346 | 426 | if res: |
7759
51aa6c6b66f7
Changed calls to exec_() into exec() (remainder of Python2 elimination).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7595
diff
changeset
|
427 | dlg.exec() |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
428 | |
7346 | 429 | @pyqtSlot() |
430 | def __showFlashID(self): | |
431 | """ | |
432 | Private slot to show the ID of the ESP flash chip. | |
433 | """ | |
434 | args = [ | |
435 | "-u", | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
436 | "-m", |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
437 | "esptool", |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
438 | "--port", |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
439 | self.microPython.getCurrentPort(), |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
440 | "flash_id", |
7346 | 441 | ] |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
442 | dlg = EricProcessDialog( |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
443 | 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
|
444 | ) |
9624
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9576
diff
changeset
|
445 | res = dlg.startProcess(PythonUtilities.getPythonExecutable(), args) |
7346 | 446 | if res: |
7759
51aa6c6b66f7
Changed calls to exec_() into exec() (remainder of Python2 elimination).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7595
diff
changeset
|
447 | dlg.exec() |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
448 | |
7346 | 449 | @pyqtSlot() |
450 | def __showMACAddress(self): | |
451 | """ | |
452 | Private slot to show the MAC address of the ESP chip. | |
453 | """ | |
454 | args = [ | |
455 | "-u", | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
456 | "-m", |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
457 | "esptool", |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
458 | "--port", |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
459 | self.microPython.getCurrentPort(), |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
460 | "read_mac", |
7346 | 461 | ] |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
462 | dlg = EricProcessDialog( |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
463 | 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
|
464 | ) |
9624
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9576
diff
changeset
|
465 | res = dlg.startProcess(PythonUtilities.getPythonExecutable(), args) |
7346 | 466 | if res: |
7759
51aa6c6b66f7
Changed calls to exec_() into exec() (remainder of Python2 elimination).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7595
diff
changeset
|
467 | dlg.exec() |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
468 | |
7346 | 469 | @pyqtSlot() |
7174
de8175253dfc
MicroPython: did some fine tuning of the MicroPython interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7173
diff
changeset
|
470 | def __resetDevice(self): |
de8175253dfc
MicroPython: did some fine tuning of the MicroPython interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7173
diff
changeset
|
471 | """ |
de8175253dfc
MicroPython: did some fine tuning of the MicroPython interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7173
diff
changeset
|
472 | 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
|
473 | """ |
7353
caa2ccd5677c
EspDevices: fixed an issue resetting the attached device when not connected.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7352
diff
changeset
|
474 | if self.microPython.isConnected(): |
9765
6378da868bb0
Reorganized the MicroPython code even more.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
475 | self.microPython.deviceInterface().execute( |
9834 | 476 | "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
|
477 | ) |
7353
caa2ccd5677c
EspDevices: fixed an issue resetting the attached device when not connected.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7352
diff
changeset
|
478 | else: |
caa2ccd5677c
EspDevices: fixed an issue resetting the attached device when not connected.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7352
diff
changeset
|
479 | # 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
|
480 | # the output |
caa2ccd5677c
EspDevices: fixed an issue resetting the attached device when not connected.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7352
diff
changeset
|
481 | args = [ |
caa2ccd5677c
EspDevices: fixed an issue resetting the attached device when not connected.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7352
diff
changeset
|
482 | "-u", |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
483 | "-m", |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
484 | "esptool", |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
485 | "--port", |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
486 | self.microPython.getCurrentPort(), |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
487 | "flash_id", |
7353
caa2ccd5677c
EspDevices: fixed an issue resetting the attached device when not connected.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7352
diff
changeset
|
488 | ] |
caa2ccd5677c
EspDevices: fixed an issue resetting the attached device when not connected.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7352
diff
changeset
|
489 | 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
|
490 | 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
|
491 | 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
|
492 | if procStarted: |
caa2ccd5677c
EspDevices: fixed an issue resetting the attached device when not connected.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7352
diff
changeset
|
493 | proc.waitForFinished(10000) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
494 | |
7174
de8175253dfc
MicroPython: did some fine tuning of the MicroPython interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7173
diff
changeset
|
495 | @pyqtSlot() |
7108
4f6133a01c6a
Started rearranging menu structure and testing and fixing on CircuitPython.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7100
diff
changeset
|
496 | def __installEspTool(self): |
4f6133a01c6a
Started rearranging menu structure and testing and fixing on CircuitPython.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7100
diff
changeset
|
497 | """ |
4f6133a01c6a
Started rearranging menu structure and testing and fixing on CircuitPython.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7100
diff
changeset
|
498 | 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
|
499 | """ |
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
|
500 | 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
|
501 | 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
|
502 | ["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
|
503 | ) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
504 | |
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
|
505 | 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
|
506 | """ |
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
|
507 | 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
|
508 | |
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
|
509 | @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
|
510 | @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
|
511 | """ |
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
|
512 | return Preferences.getMicroPython("MicroPythonDocuUrl") |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
513 | |
7328 | 514 | def getFirmwareUrl(self): |
515 | """ | |
516 | 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
|
517 | |
7328 | 518 | @return firmware download URL of the device |
519 | @rtype str | |
520 | """ | |
521 | 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
|
522 | |
9765
6378da868bb0
Reorganized the MicroPython code even more.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
523 | ################################################################## |
6378da868bb0
Reorganized the MicroPython code even more.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
524 | ## time related methods below |
6378da868bb0
Reorganized the MicroPython code even more.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
525 | ################################################################## |
6378da868bb0
Reorganized the MicroPython code even more.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
526 | |
6378da868bb0
Reorganized the MicroPython code even more.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
527 | def _getSetTimeCode(self): |
6378da868bb0
Reorganized the MicroPython code even more.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
528 | """ |
6378da868bb0
Reorganized the MicroPython code even more.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
529 | 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
|
530 | |
6378da868bb0
Reorganized the MicroPython code even more.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
531 | 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
|
532 | subclasses. |
6378da868bb0
Reorganized the MicroPython code even more.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
533 | |
6378da868bb0
Reorganized the MicroPython code even more.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
534 | @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
|
535 | @rtype str |
6378da868bb0
Reorganized the MicroPython code even more.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
536 | """ |
6378da868bb0
Reorganized the MicroPython code even more.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
537 | # rtc_time[0] - year 4 digit |
6378da868bb0
Reorganized the MicroPython code even more.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
538 | # rtc_time[1] - month 1..12 |
6378da868bb0
Reorganized the MicroPython code even more.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
539 | # rtc_time[2] - day 1..31 |
6378da868bb0
Reorganized the MicroPython code even more.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
540 | # 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
|
541 | # rtc_time[4] - hour 0..23 |
6378da868bb0
Reorganized the MicroPython code even more.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
542 | # rtc_time[5] - minute 0..59 |
6378da868bb0
Reorganized the MicroPython code even more.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
543 | # rtc_time[6] - second 0..59 |
6378da868bb0
Reorganized the MicroPython code even more.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
544 | # rtc_time[7] - yearday 1..366 |
6378da868bb0
Reorganized the MicroPython code even more.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
545 | # 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
|
546 | |
6378da868bb0
Reorganized the MicroPython code even more.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
547 | # 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
|
548 | # take the arguments in the order: |
6378da868bb0
Reorganized the MicroPython code even more.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
549 | # (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
|
550 | # __IGNORE_WARNING_M891__ |
6378da868bb0
Reorganized the MicroPython code even more.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
551 | # 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
|
552 | # |
6378da868bb0
Reorganized the MicroPython code even more.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
553 | # LoBo variant of MPy deviates. |
6378da868bb0
Reorganized the MicroPython code even more.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
554 | return """ |
6378da868bb0
Reorganized the MicroPython code even more.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
555 | def set_time(rtc_time): |
6378da868bb0
Reorganized the MicroPython code even more.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
556 | import machine |
6378da868bb0
Reorganized the MicroPython code even more.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
557 | rtc = machine.RTC() |
6378da868bb0
Reorganized the MicroPython code even more.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
558 | try: |
6378da868bb0
Reorganized the MicroPython code even more.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
559 | rtc.datetime(rtc_time[:7] + (0,)) |
6378da868bb0
Reorganized the MicroPython code even more.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
560 | except Exception: |
6378da868bb0
Reorganized the MicroPython code even more.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
561 | import os |
6378da868bb0
Reorganized the MicroPython code even more.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
562 | if 'LoBo' in os.uname()[0]: |
6378da868bb0
Reorganized the MicroPython code even more.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
563 | 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
|
564 | else: |
6378da868bb0
Reorganized the MicroPython code even more.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
565 | clock_time = rtc_time[:7] + (0,) |
6378da868bb0
Reorganized the MicroPython code even more.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
566 | rtc.init(clock_time) |
6378da868bb0
Reorganized the MicroPython code even more.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
567 | """ |
6378da868bb0
Reorganized the MicroPython code even more.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
568 | |
9795 | 569 | ################################################################## |
570 | ## Methods below implement WiFi related methods | |
571 | ################################################################## | |
572 | ||
573 | def hasWifi(self): | |
574 | """ | |
575 | Public method to check the availability of WiFi. | |
576 | ||
577 | @return tuple containing a flag indicating the availability of WiFi | |
578 | and the WiFi type (esp32) | |
579 | @rtype tuple of (bool, str) | |
580 | """ | |
581 | return True, "esp32" | |
582 | ||
583 | def getWifiData(self): | |
584 | """ | |
585 | Public method to get data related to the current WiFi status. | |
586 | ||
9798 | 587 | @return tuple of three dictionaries containing the WiFi status data |
588 | for the WiFi client, access point and overall data | |
589 | @rtype tuple of (dict, dict, dict) | |
9795 | 590 | @exception OSError raised to indicate an issue with the device |
591 | """ | |
592 | command = """ | |
593 | def wifi_status(): | |
594 | import ubinascii | |
595 | import ujson | |
596 | import network | |
597 | ||
598 | wifi = network.WLAN(network.STA_IF) | |
599 | station = { | |
600 | 'active': wifi.active(), | |
601 | 'connected': wifi.isconnected(), | |
602 | 'status': wifi.status(), | |
603 | 'ifconfig': wifi.ifconfig(), | |
604 | 'mac': ubinascii.hexlify(wifi.config('mac'), ':').decode(), | |
605 | } | |
606 | if wifi.active(): | |
9797 | 607 | try: |
608 | station['txpower'] = wifi.config('txpower') | |
609 | except ValueError: | |
610 | pass | |
9795 | 611 | print(ujson.dumps(station)) |
612 | ||
613 | wifi = network.WLAN(network.AP_IF) | |
614 | ap = { | |
615 | 'active': wifi.active(), | |
616 | 'connected': wifi.isconnected(), | |
617 | 'status': wifi.status(), | |
618 | 'ifconfig': wifi.ifconfig(), | |
619 | 'mac': ubinascii.hexlify(wifi.config('mac'), ':').decode(), | |
620 | 'channel': wifi.config('channel'), | |
621 | 'essid': wifi.config('essid'), | |
622 | } | |
623 | if wifi.active(): | |
9797 | 624 | try: |
625 | ap['txpower'] = wifi.config('txpower') | |
626 | except ValueError: | |
627 | pass | |
9795 | 628 | print(ujson.dumps(ap)) |
629 | ||
9798 | 630 | overall = { |
631 | 'active': station['active'] or ap['active'] | |
632 | } | |
633 | print(ujson.dumps(overall)) | |
634 | ||
9795 | 635 | wifi_status() |
636 | del wifi_status | |
637 | """ | |
638 | ||
9827 | 639 | out, err = self._interface.execute(command, mode=self._submitMode) |
9795 | 640 | if err: |
641 | raise OSError(self._shortError(err)) | |
642 | ||
9798 | 643 | stationStr, apStr, overallStr = out.decode("utf-8").splitlines() |
9795 | 644 | station = json.loads(stationStr) |
645 | ap = json.loads(apStr) | |
9798 | 646 | overall = json.loads(overallStr) |
9795 | 647 | try: |
648 | station["status"] = self.__statusTranslations[station["status"]] | |
649 | except KeyError: | |
650 | station["status"] = str(station["status"]) | |
651 | try: | |
652 | ap["status"] = self.__statusTranslations[ap["status"]] | |
653 | except KeyError: | |
654 | ap["status"] = str(ap["status"]) | |
9798 | 655 | return station, ap, overall |
9795 | 656 | |
657 | def connectWifi(self, ssid, password): | |
658 | """ | |
659 | Public method to connect a device to a WiFi network. | |
660 | ||
661 | @param ssid name (SSID) of the WiFi network | |
662 | @type str | |
663 | @param password password needed to connect | |
664 | @type str | |
665 | @return tuple containing the connection status and an error string | |
666 | @rtype tuple of (bool, str) | |
667 | """ | |
668 | command = """ | |
669 | def connect_wifi(ssid, password): | |
670 | import network | |
671 | import ujson | |
672 | from time import sleep | |
673 | ||
674 | wifi = network.WLAN(network.STA_IF) | |
675 | wifi.active(False) | |
676 | wifi.active(True) | |
677 | wifi.connect(ssid, password) | |
678 | max_wait = 140 | |
679 | while max_wait and wifi.status() == network.STAT_CONNECTING: | |
680 | max_wait -= 1 | |
681 | sleep(0.1) | |
682 | status = wifi.status() | |
683 | print(ujson.dumps({{'connected': wifi.isconnected(), 'status': status}})) | |
684 | ||
685 | connect_wifi({0}, {1}) | |
686 | del connect_wifi | |
687 | """.format( | |
9798 | 688 | repr(ssid), |
689 | repr(password if password else ""), | |
690 | ) | |
9795 | 691 | |
692 | with EricOverrideCursor(): | |
9799 | 693 | out, err = self._interface.execute( |
9827 | 694 | command, mode=self._submitMode, timeout=15000 |
9799 | 695 | ) |
9795 | 696 | if err: |
697 | return False, err | |
698 | ||
699 | result = json.loads(out.decode("utf-8").strip()) | |
700 | if result["connected"]: | |
701 | error = "" | |
702 | else: | |
703 | try: | |
704 | error = self.__statusTranslations[result["status"]] | |
705 | except KeyError: | |
706 | error = str(result["status"]) | |
707 | ||
708 | return result["connected"], error | |
709 | ||
710 | def disconnectWifi(self): | |
711 | """ | |
712 | Public method to disconnect a device from the WiFi network. | |
713 | ||
714 | @return tuple containing a flag indicating success and an error string | |
715 | @rtype tuple of (bool, str) | |
716 | """ | |
717 | command = """ | |
718 | def disconnect_wifi(): | |
719 | import network | |
720 | from time import sleep | |
721 | ||
722 | wifi = network.WLAN(network.STA_IF) | |
723 | wifi.disconnect() | |
724 | wifi.active(False) | |
725 | sleep(0.1) | |
726 | print(not wifi.isconnected()) | |
727 | ||
728 | disconnect_wifi() | |
729 | del disconnect_wifi | |
730 | """ | |
731 | ||
9827 | 732 | out, err = self._interface.execute(command, mode=self._submitMode) |
9795 | 733 | if err: |
734 | return False, err | |
735 | ||
736 | return out.decode("utf-8").strip() == "True", "" | |
737 | ||
738 | def writeCredentials(self, ssid, password): | |
739 | """ | |
740 | Public method to write the given credentials to the connected device and modify | |
741 | the start script to connect automatically. | |
742 | ||
743 | @param ssid SSID of the network to connect to | |
744 | @type str | |
745 | @param password password needed to authenticate | |
746 | @type str | |
747 | @return tuple containing a flag indicating success and an error message | |
748 | @rtype tuple of (bool, str) | |
749 | """ | |
750 | nvsCommand = """ | |
751 | def save_wifi_creds(ssid, password): | |
752 | import esp32 | |
753 | ||
754 | nvs = esp32.NVS('wifi_creds') | |
755 | nvs.set_blob('ssid', ssid) | |
756 | nvs.set_blob('password', password) | |
757 | nvs.commit() | |
758 | ||
759 | save_wifi_creds({0}, {1}) | |
760 | del save_wifi_creds | |
9798 | 761 | """.format( |
762 | repr(ssid), repr(password) if password else "''" | |
763 | ) | |
9795 | 764 | bootCommand = """ |
765 | def modify_boot(): | |
766 | add = True | |
767 | try: | |
768 | with open('/boot.py', 'r') as f: | |
769 | for ln in f.readlines(): | |
770 | if 'wifi_connect' in ln: | |
771 | add = False | |
772 | break | |
773 | except: | |
774 | pass | |
775 | if add: | |
776 | with open('/boot.py', 'a') as f: | |
777 | f.write('\\nimport wifi_connect\\n') | |
778 | print(True) | |
779 | ||
780 | modify_boot() | |
781 | del modify_boot | |
782 | """ | |
783 | ||
9827 | 784 | out, err = self._interface.execute(nvsCommand, mode=self._submitMode) |
9795 | 785 | if err: |
786 | return False, self.tr("Error saving credentials: {0}").format(err) | |
787 | ||
788 | try: | |
789 | # copy auto-connect file | |
790 | self.put( | |
791 | os.path.join( | |
792 | os.path.dirname(__file__), "MCUScripts", "esp32WiFiConnect.py" | |
793 | ), | |
794 | "/wifi_connect.py", | |
795 | ) | |
796 | except OSError as err: | |
797 | return False, self.tr("Error saving auto-connect script: {0}").format(err) | |
798 | ||
9827 | 799 | out, err = self._interface.execute(bootCommand, mode=self._submitMode) |
9795 | 800 | if err: |
801 | return False, self.tr("Error modifying 'boot.py': {0}").format(err) | |
802 | ||
803 | return True, "" | |
804 | ||
805 | def removeCredentials(self): | |
806 | """ | |
807 | Public method to remove the saved credentials from the connected device. | |
808 | ||
809 | @return tuple containing a flag indicating success and an error message | |
810 | @rtype tuple of (bool, str) | |
811 | """ | |
812 | nvsCommand = """ | |
813 | def delete_wifi_creds(): | |
814 | import esp32 | |
815 | ||
816 | nvs = esp32.NVS('wifi_creds') | |
817 | try: | |
818 | nvs.erase_key('ssid') | |
819 | nvs.erase_key('password') | |
820 | nvs.commit() | |
821 | except OSError: | |
822 | pass | |
823 | ||
824 | delete_wifi_creds() | |
825 | del delete_wifi_creds | |
826 | """ | |
827 | ||
9827 | 828 | out, err = self._interface.execute(nvsCommand, mode=self._submitMode) |
9795 | 829 | if err: |
830 | return False, self.tr("Error deleting credentials: {0}").format(err) | |
831 | ||
832 | return True, "" | |
833 | ||
834 | def checkInternet(self): | |
835 | """ | |
836 | Public method to check, if the internet can be reached. | |
837 | ||
838 | @return tuple containing a flag indicating reachability and an error string | |
839 | @rtype tuple of (bool, str) | |
840 | """ | |
841 | command = """ | |
842 | def check_internet(): | |
843 | import network | |
844 | import socket | |
845 | ||
846 | wifi = network.WLAN(network.STA_IF) | |
847 | if wifi.isconnected(): | |
848 | s = socket.socket() | |
849 | try: | |
850 | s.connect(socket.getaddrinfo('google.com', 80)[0][-1]) | |
851 | s.close() | |
852 | print(True) | |
853 | except: | |
854 | print(False) | |
855 | else: | |
856 | print(False) | |
857 | ||
858 | check_internet() | |
859 | del check_internet | |
860 | """ | |
861 | ||
9827 | 862 | out, err = self._interface.execute(command, mode=self._submitMode) |
9795 | 863 | if err: |
864 | return False, err | |
865 | ||
866 | return out.decode("utf-8").strip() == "True", "" | |
867 | ||
868 | def scanNetworks(self): | |
869 | """ | |
870 | Public method to scan for available WiFi networks. | |
871 | ||
872 | @return tuple containing the list of available networks as a tuple of 'Name', | |
873 | 'MAC-Address', 'channel', 'RSSI' and 'security' and an error string | |
874 | @rtype tuple of (list of tuple of (str, str, int, int, str), str) | |
875 | """ | |
876 | command = """ | |
877 | def scan_networks(): | |
878 | import network | |
879 | ||
880 | wifi = network.WLAN(network.STA_IF) | |
881 | active = wifi.active() | |
882 | if not active: | |
883 | wifi.active(True) | |
884 | network_list = wifi.scan() | |
885 | if not active: | |
886 | wifi.active(False) | |
887 | print(network_list) | |
888 | ||
889 | scan_networks() | |
890 | del scan_networks | |
891 | """ | |
892 | ||
9828 | 893 | out, err = self._interface.execute( |
894 | command, mode=self._submitMode, timeout=15000 | |
895 | ) | |
9795 | 896 | if err: |
897 | return [], err | |
898 | ||
899 | networksList = ast.literal_eval(out.decode("utf-8")) | |
900 | networks = [] | |
901 | for network in networksList: | |
902 | if network[0]: | |
903 | ssid = network[0].decode("utf-8") | |
904 | mac = binascii.hexlify(network[1], ":").decode("utf-8") | |
905 | channel = network[2] | |
906 | rssi = network[3] | |
907 | try: | |
908 | security = self.__securityTranslations[network[4]] | |
909 | except KeyError: | |
910 | security = self.tr("unknown ({0})").format(network[4]) | |
911 | networks.append((ssid, mac, channel, rssi, security)) | |
912 | ||
913 | return networks, "" | |
914 | ||
915 | def deactivateInterface(self, interface): | |
916 | """ | |
917 | Public method to deactivate a given WiFi interface of the connected device. | |
918 | ||
919 | @param interface designation of the interface to be deactivated (one of 'AP' | |
920 | or 'STA') | |
921 | @type str | |
922 | @return tuple containg a flag indicating success and an error message | |
923 | @rtype tuple of (bool, str) | |
924 | @exception ValueError raised to indicate a wrong value for the interface type | |
925 | """ | |
926 | if interface not in ("STA", "AP"): | |
927 | raise ValueError( | |
928 | "interface must be 'AP' or 'STA', got '{0}'".format(interface) | |
929 | ) | |
930 | ||
931 | command = """ | |
932 | def deactivate(): | |
933 | import network | |
934 | from time import sleep | |
935 | ||
936 | wifi = network.WLAN(network.{0}_IF) | |
937 | wifi.active(False) | |
938 | sleep(0.1) | |
939 | print(not wifi.active()) | |
940 | ||
941 | deactivate() | |
942 | del deactivate | |
943 | """.format( | |
9798 | 944 | interface |
945 | ) | |
9795 | 946 | |
9827 | 947 | out, err = self._interface.execute(command, mode=self._submitMode) |
9795 | 948 | if err: |
949 | return False, err | |
950 | else: | |
951 | return out.decode("utf-8").strip() == "True", "" | |
952 | ||
9797 | 953 | def startAccessPoint(self, ssid, security=None, password=None, ifconfig=None): |
9795 | 954 | """ |
955 | Public method to start the access point interface. | |
956 | ||
957 | @param ssid SSID of the access point | |
958 | @type str | |
959 | @param security security method (defaults to None) | |
960 | @type int (optional) | |
961 | @param password password (defaults to None) | |
962 | @type str (optional) | |
9797 | 963 | @param ifconfig IPv4 configuration for the access point if not default |
964 | (IPv4 address, netmask, gateway address, DNS server address) | |
965 | @type tuple of (str, str, str, str) | |
9795 | 966 | @return tuple containing a flag indicating success and an error message |
967 | @rtype tuple of (bool, str) | |
968 | """ | |
969 | if security is None or password is None: | |
970 | security = 0 | |
971 | password = "" | |
972 | if security > 4: | |
973 | security = 4 # security >4 cause an error thrown by the ESP32 | |
974 | ||
975 | command = """ | |
9797 | 976 | def start_ap(ssid, authmode, password, ifconfig): |
9795 | 977 | import network |
978 | ||
979 | ap = network.WLAN(network.AP_IF) | |
980 | ap.active(False) | |
9797 | 981 | if ifconfig: |
982 | ap.ifconfig(ifconfig) | |
9795 | 983 | ap.active(True) |
984 | try: | |
9797 | 985 | ap.config(ssid=ssid, authmode=authmode, password=password) |
9795 | 986 | except: |
9797 | 987 | ap.config(essid=ssid, authmode=authmode, password=password) |
9795 | 988 | |
9797 | 989 | start_ap({0}, {1}, {2}, {3}) |
9795 | 990 | del start_ap |
991 | """.format( | |
9798 | 992 | repr(ssid), security, repr(password), ifconfig |
993 | ) | |
9795 | 994 | |
9828 | 995 | out, err = self._interface.execute( |
996 | command, mode=self._submitMode, timeout=15000 | |
997 | ) | |
9795 | 998 | if err: |
999 | return False, err | |
1000 | else: | |
1001 | return True, "" | |
1002 | ||
1003 | def stopAccessPoint(self): | |
1004 | """ | |
1005 | Public method to stop the access point interface. | |
1006 | ||
1007 | @return tuple containg a flag indicating success and an error message | |
1008 | @rtype tuple of (bool, str) | |
1009 | """ | |
1010 | return self.deactivateInterface("AP") | |
1011 | ||
1012 | def getConnectedClients(self): | |
1013 | """ | |
1014 | Public method to get a list of connected clients. | |
1015 | ||
1016 | @return a tuple containing a list of tuples containing the client MAC-Address | |
1017 | and the RSSI (if supported and available) and an error message | |
1018 | @rtype tuple of ([(bytes, int)], str) | |
1019 | """ | |
1020 | command = """ | |
1021 | def get_stations(): | |
1022 | import network | |
1023 | ||
1024 | ap = network.WLAN(network.AP_IF) | |
1025 | stations = ap.status('stations') | |
1026 | print(stations) | |
1027 | ||
1028 | get_stations() | |
1029 | del get_stations | |
1030 | """ | |
1031 | ||
9828 | 1032 | out, err = self._interface.execute( |
1033 | command, mode=self._submitMode, timeout=10000 | |
1034 | ) | |
9795 | 1035 | if err: |
1036 | return [], err | |
1037 | ||
1038 | clientsList = ast.literal_eval(out.decode("utf-8")) | |
1039 | return clientsList, "" | |
1040 | ||
9496
05017f795c24
Changed MicroPython device imports to use importlib.import_module().
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9473
diff
changeset
|
1041 | |
9751
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9749
diff
changeset
|
1042 | 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
|
1043 | """ |
05017f795c24
Changed MicroPython device imports to use importlib.import_module().
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9473
diff
changeset
|
1044 | 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
|
1045 | |
05017f795c24
Changed MicroPython device imports to use importlib.import_module().
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9473
diff
changeset
|
1046 | @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
|
1047 | @type MicroPythonWidget |
05017f795c24
Changed MicroPython device imports to use importlib.import_module().
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9473
diff
changeset
|
1048 | @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
|
1049 | @type str |
05017f795c24
Changed MicroPython device imports to use importlib.import_module().
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9473
diff
changeset
|
1050 | @param vid vendor ID |
05017f795c24
Changed MicroPython device imports to use importlib.import_module().
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9473
diff
changeset
|
1051 | @type int |
05017f795c24
Changed MicroPython device imports to use importlib.import_module().
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9473
diff
changeset
|
1052 | @param pid product ID |
05017f795c24
Changed MicroPython device imports to use importlib.import_module().
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9473
diff
changeset
|
1053 | @type int |
9738 | 1054 | @param boardName name of the board |
1055 | @type str | |
9751
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9749
diff
changeset
|
1056 | @param serialNumber serial number of the board |
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9749
diff
changeset
|
1057 | @type str |
9496
05017f795c24
Changed MicroPython device imports to use importlib.import_module().
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9473
diff
changeset
|
1058 | @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
|
1059 | @rtype EspDevice |
05017f795c24
Changed MicroPython device imports to use importlib.import_module().
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9473
diff
changeset
|
1060 | """ |
05017f795c24
Changed MicroPython device imports to use importlib.import_module().
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9473
diff
changeset
|
1061 | return EspDevice(microPythonWidget, deviceType) |
9820 | 1062 | |
1063 | ||
1064 | ################################################################################ | |
1065 | ## Functions below implement flashing related functionality needed elsewhere ## | |
1066 | ## as well. ## | |
1067 | ################################################################################ | |
1068 | ||
1069 | ||
1070 | @pyqtSlot() | |
1071 | def eraseFlash(port): | |
1072 | """ | |
1073 | Slot to erase the device flash memory. | |
1074 | ||
1075 | @param port name of the serial port device to be used | |
1076 | @type str | |
1077 | """ | |
1078 | ok = EricMessageBox.yesNo( | |
1079 | None, | |
1080 | QCoreApplication.translate("EspDevice", "Erase Flash"), | |
1081 | QCoreApplication.translate( | |
1082 | "EspDevice", """Shall the flash of the selected device really be erased?""" | |
1083 | ), | |
1084 | ) | |
1085 | if ok: | |
1086 | flashArgs = [ | |
1087 | "-u", | |
1088 | "-m", | |
1089 | "esptool", | |
1090 | "--port", | |
1091 | port, | |
1092 | "erase_flash", | |
1093 | ] | |
1094 | dlg = EricProcessDialog( | |
1095 | QCoreApplication.translate("EspDevice", "'esptool erase_flash' Output"), | |
1096 | QCoreApplication.translate("EspDevice", "Erase Flash"), | |
1097 | showProgress=True, | |
1098 | ) | |
1099 | res = dlg.startProcess(PythonUtilities.getPythonExecutable(), flashArgs) | |
1100 | if res: | |
1101 | dlg.exec() | |
1102 | ||
1103 | ||
1104 | @pyqtSlot() | |
1105 | def flashPythonFirmware(port): | |
1106 | """ | |
1107 | Slot to flash a MicroPython firmware to the device. | |
1108 | ||
1109 | @param port name of the serial port device to be used | |
1110 | @type str | |
1111 | """ | |
1112 | from .EspDialogs.EspFirmwareSelectionDialog import EspFirmwareSelectionDialog | |
1113 | ||
1114 | dlg = EspFirmwareSelectionDialog() | |
1115 | if dlg.exec() == QDialog.DialogCode.Accepted: | |
1116 | chip, firmware, baudRate, flashMode, flashAddress = dlg.getData() | |
1117 | flashArgs = [ | |
1118 | "-u", | |
1119 | "-m", | |
1120 | "esptool", | |
1121 | "--chip", | |
1122 | chip, | |
1123 | "--port", | |
1124 | port, | |
1125 | ] | |
1126 | if baudRate != "115200": | |
1127 | flashArgs += ["--baud", baudRate] | |
1128 | flashArgs.append("write_flash") | |
1129 | if flashMode: | |
1130 | flashArgs += ["--flash_mode", flashMode] | |
1131 | flashArgs += [ | |
1132 | flashAddress, | |
1133 | firmware, | |
1134 | ] | |
1135 | dlg = EricProcessDialog( | |
1136 | QCoreApplication.translate("EspDevice", "'esptool write_flash' Output"), | |
1137 | QCoreApplication.translate("EspDevice", "Flash µPy/CPy Firmware"), | |
1138 | showProgress=True, | |
1139 | ) | |
1140 | res = dlg.startProcess(PythonUtilities.getPythonExecutable(), flashArgs) | |
1141 | if res: | |
1142 | dlg.exec() | |
1143 | ||
1144 | ||
1145 | @pyqtSlot() | |
1146 | def flashAddonFirmware(port): | |
1147 | """ | |
1148 | Slot to flash some additional firmware images. | |
1149 | ||
1150 | @param port name of the serial port device to be used | |
1151 | @type str | |
1152 | """ | |
1153 | from .EspDialogs.EspFirmwareSelectionDialog import EspFirmwareSelectionDialog | |
1154 | ||
1155 | dlg = EspFirmwareSelectionDialog(addon=True) | |
1156 | if dlg.exec() == QDialog.DialogCode.Accepted: | |
1157 | chip, firmware, baudRate, flashMode, flashAddress = dlg.getData() | |
1158 | flashArgs = [ | |
1159 | "-u", | |
1160 | "-m", | |
1161 | "esptool", | |
1162 | "--chip", | |
1163 | chip, | |
1164 | "--port", | |
1165 | port, | |
1166 | ] | |
1167 | if baudRate != "115200": | |
1168 | flashArgs += ["--baud", baudRate] | |
1169 | flashArgs.append("write_flash") | |
1170 | if flashMode: | |
1171 | flashArgs += ["--flash_mode", flashMode] | |
1172 | flashArgs += [ | |
1173 | flashAddress.lower(), | |
1174 | firmware, | |
1175 | ] | |
1176 | dlg = EricProcessDialog( | |
1177 | QCoreApplication.translate("EspDevice", "'esptool write_flash' Output"), | |
1178 | QCoreApplication.translate("EspDevice", "Flash Additional Firmware"), | |
1179 | showProgress=True, | |
1180 | ) | |
1181 | res = dlg.startProcess(PythonUtilities.getPythonExecutable(), flashArgs) | |
1182 | if res: | |
1183 | dlg.exec() |