eric6/MicroPython/PyBoardDevices.py

Sat, 27 Feb 2021 12:08:23 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sat, 27 Feb 2021 12:08:23 +0100
changeset 8138
169e65a6787c
parent 8117
aaa5e0eacd4e
child 8143
2c730d5fd177
permissions
-rw-r--r--

Shell: added functionality to show a prompt when the main client process has exited (e.g. a script ended).

7295
cf50045a7c0f MicroPython: added support for PyBoard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
cf50045a7c0f MicroPython: added support for PyBoard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
2
7923
91e843545d9a Updated copyright for 2021.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7759
diff changeset
3 # Copyright (c) 2019 - 2021 Detlev Offenbach <detlev@die-offenbachs.de>
7295
cf50045a7c0f MicroPython: added support for PyBoard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
4 #
cf50045a7c0f MicroPython: added support for PyBoard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
5
cf50045a7c0f MicroPython: added support for PyBoard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
6 """
cf50045a7c0f MicroPython: added support for PyBoard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
7 Module implementing the device interface class for PyBoard boards.
cf50045a7c0f MicroPython: added support for PyBoard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
8 """
cf50045a7c0f MicroPython: added support for PyBoard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
9
7327
71883ddcb762 MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7321
diff changeset
10 import os
71883ddcb762 MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7321
diff changeset
11
71883ddcb762 MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7321
diff changeset
12 from PyQt5.QtCore import pyqtSlot, QStandardPaths
71883ddcb762 MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7321
diff changeset
13
71883ddcb762 MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7321
diff changeset
14 from E5Gui import E5MessageBox, E5FileDialog
7295
cf50045a7c0f MicroPython: added support for PyBoard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
15 from E5Gui.E5Application import e5App
7327
71883ddcb762 MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7321
diff changeset
16 from E5Gui.E5ProcessDialog import E5ProcessDialog
7295
cf50045a7c0f MicroPython: added support for PyBoard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
17
cf50045a7c0f MicroPython: added support for PyBoard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
18 from .MicroPythonDevices import MicroPythonDevice
cf50045a7c0f MicroPython: added support for PyBoard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
19 from .MicroPythonWidget import HAS_QTCHART
cf50045a7c0f MicroPython: added support for PyBoard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
20
cf50045a7c0f MicroPython: added support for PyBoard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
21 import Utilities
cf50045a7c0f MicroPython: added support for PyBoard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
22 import Preferences
cf50045a7c0f MicroPython: added support for PyBoard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
23
cf50045a7c0f MicroPython: added support for PyBoard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
24
cf50045a7c0f MicroPython: added support for PyBoard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
25 class PyBoardDevice(MicroPythonDevice):
cf50045a7c0f MicroPython: added support for PyBoard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
26 """
cf50045a7c0f MicroPython: added support for PyBoard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
27 Class implementing the device for PyBoard boards.
cf50045a7c0f MicroPython: added support for PyBoard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
28 """
cf50045a7c0f MicroPython: added support for PyBoard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
29 DeviceVolumeName = "PYBFLASH"
cf50045a7c0f MicroPython: added support for PyBoard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
30
cf50045a7c0f MicroPython: added support for PyBoard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
31 FlashInstructionsURL = (
cf50045a7c0f MicroPython: added support for PyBoard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
32 "https://github.com/micropython/micropython/wiki/"
cf50045a7c0f MicroPython: added support for PyBoard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
33 "Pyboard-Firmware-Update"
cf50045a7c0f MicroPython: added support for PyBoard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
34 )
cf50045a7c0f MicroPython: added support for PyBoard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
35
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
36 def __init__(self, microPythonWidget, deviceType, parent=None):
7295
cf50045a7c0f MicroPython: added support for PyBoard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
37 """
cf50045a7c0f MicroPython: added support for PyBoard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
38 Constructor
cf50045a7c0f MicroPython: added support for PyBoard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
39
cf50045a7c0f MicroPython: added support for PyBoard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
40 @param microPythonWidget reference to the main MicroPython widget
cf50045a7c0f MicroPython: added support for PyBoard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
41 @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
42 @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
43 @type str
7295
cf50045a7c0f MicroPython: added support for PyBoard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
44 @param parent reference to the parent object
cf50045a7c0f MicroPython: added support for PyBoard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
45 @type QObject
cf50045a7c0f MicroPython: added support for PyBoard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
46 """
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
47 super(PyBoardDevice, self).__init__(microPythonWidget, deviceType,
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
48 parent)
8062
8dc5acb30a8b MicroPython: implemented code to deal with multiple devices attached to the computer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
49
8dc5acb30a8b MicroPython: implemented code to deal with multiple devices attached to the computer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
50 self.__workspace = self.__findWorkspace()
7295
cf50045a7c0f MicroPython: added support for PyBoard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
51
cf50045a7c0f MicroPython: added support for PyBoard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
52 def setButtons(self):
cf50045a7c0f MicroPython: added support for PyBoard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
53 """
cf50045a7c0f MicroPython: added support for PyBoard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
54 Public method to enable the supported action buttons.
cf50045a7c0f MicroPython: added support for PyBoard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
55 """
cf50045a7c0f MicroPython: added support for PyBoard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
56 super(PyBoardDevice, self).setButtons()
cf50045a7c0f MicroPython: added support for PyBoard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
57 self.microPython.setActionButtons(
cf50045a7c0f MicroPython: added support for PyBoard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
58 run=True, repl=True, files=True, chart=HAS_QTCHART)
cf50045a7c0f MicroPython: added support for PyBoard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
59
cf50045a7c0f MicroPython: added support for PyBoard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
60 if self.__deviceVolumeMounted():
cf50045a7c0f MicroPython: added support for PyBoard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
61 self.microPython.setActionButtons(open=True, save=True)
cf50045a7c0f MicroPython: added support for PyBoard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
62
cf50045a7c0f MicroPython: added support for PyBoard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
63 def forceInterrupt(self):
cf50045a7c0f MicroPython: added support for PyBoard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
64 """
cf50045a7c0f MicroPython: added support for PyBoard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
65 Public method to determine the need for an interrupt when opening the
cf50045a7c0f MicroPython: added support for PyBoard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
66 serial connection.
cf50045a7c0f MicroPython: added support for PyBoard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
67
cf50045a7c0f MicroPython: added support for PyBoard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
68 @return flag indicating an interrupt is needed
cf50045a7c0f MicroPython: added support for PyBoard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
69 @rtype bool
cf50045a7c0f MicroPython: added support for PyBoard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
70 """
cf50045a7c0f MicroPython: added support for PyBoard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
71 return False
cf50045a7c0f MicroPython: added support for PyBoard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
72
cf50045a7c0f MicroPython: added support for PyBoard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
73 def deviceName(self):
cf50045a7c0f MicroPython: added support for PyBoard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
74 """
cf50045a7c0f MicroPython: added support for PyBoard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
75 Public method to get the name of the device.
cf50045a7c0f MicroPython: added support for PyBoard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
76
cf50045a7c0f MicroPython: added support for PyBoard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
77 @return name of the device
cf50045a7c0f MicroPython: added support for PyBoard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
78 @rtype str
cf50045a7c0f MicroPython: added support for PyBoard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
79 """
cf50045a7c0f MicroPython: added support for PyBoard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
80 return self.tr("PyBoard")
cf50045a7c0f MicroPython: added support for PyBoard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
81
cf50045a7c0f MicroPython: added support for PyBoard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
82 def canStartRepl(self):
cf50045a7c0f MicroPython: added support for PyBoard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
83 """
cf50045a7c0f MicroPython: added support for PyBoard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
84 Public method to determine, if a REPL can be started.
cf50045a7c0f MicroPython: added support for PyBoard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
85
cf50045a7c0f MicroPython: added support for PyBoard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
86 @return tuple containing a flag indicating it is safe to start a REPL
cf50045a7c0f MicroPython: added support for PyBoard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
87 and a reason why it cannot.
cf50045a7c0f MicroPython: added support for PyBoard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
88 @rtype tuple of (bool, str)
cf50045a7c0f MicroPython: added support for PyBoard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
89 """
cf50045a7c0f MicroPython: added support for PyBoard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
90 return True, ""
cf50045a7c0f MicroPython: added support for PyBoard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
91
cf50045a7c0f MicroPython: added support for PyBoard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
92 def canStartPlotter(self):
cf50045a7c0f MicroPython: added support for PyBoard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
93 """
cf50045a7c0f MicroPython: added support for PyBoard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
94 Public method to determine, if a Plotter can be started.
cf50045a7c0f MicroPython: added support for PyBoard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
95
cf50045a7c0f MicroPython: added support for PyBoard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
96 @return tuple containing a flag indicating it is safe to start a
cf50045a7c0f MicroPython: added support for PyBoard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
97 Plotter and a reason why it cannot.
cf50045a7c0f MicroPython: added support for PyBoard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
98 @rtype tuple of (bool, str)
cf50045a7c0f MicroPython: added support for PyBoard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
99 """
cf50045a7c0f MicroPython: added support for PyBoard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
100 return True, ""
cf50045a7c0f MicroPython: added support for PyBoard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
101
cf50045a7c0f MicroPython: added support for PyBoard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
102 def canRunScript(self):
cf50045a7c0f MicroPython: added support for PyBoard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
103 """
cf50045a7c0f MicroPython: added support for PyBoard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
104 Public method to determine, if a script can be executed.
cf50045a7c0f MicroPython: added support for PyBoard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
105
cf50045a7c0f MicroPython: added support for PyBoard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
106 @return tuple containing a flag indicating it is safe to start a
cf50045a7c0f MicroPython: added support for PyBoard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
107 Plotter and a reason why it cannot.
cf50045a7c0f MicroPython: added support for PyBoard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
108 @rtype tuple of (bool, str)
cf50045a7c0f MicroPython: added support for PyBoard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
109 """
cf50045a7c0f MicroPython: added support for PyBoard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
110 return True, ""
cf50045a7c0f MicroPython: added support for PyBoard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
111
cf50045a7c0f MicroPython: added support for PyBoard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
112 def runScript(self, script):
cf50045a7c0f MicroPython: added support for PyBoard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
113 """
cf50045a7c0f MicroPython: added support for PyBoard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
114 Public method to run the given Python script.
cf50045a7c0f MicroPython: added support for PyBoard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
115
cf50045a7c0f MicroPython: added support for PyBoard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
116 @param script script to be executed
cf50045a7c0f MicroPython: added support for PyBoard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
117 @type str
cf50045a7c0f MicroPython: added support for PyBoard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
118 """
cf50045a7c0f MicroPython: added support for PyBoard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
119 pythonScript = script.split("\n")
cf50045a7c0f MicroPython: added support for PyBoard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
120 self.sendCommands(pythonScript)
cf50045a7c0f MicroPython: added support for PyBoard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
121
cf50045a7c0f MicroPython: added support for PyBoard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
122 def canStartFileManager(self):
cf50045a7c0f MicroPython: added support for PyBoard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
123 """
cf50045a7c0f MicroPython: added support for PyBoard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
124 Public method to determine, if a File Manager can be started.
cf50045a7c0f MicroPython: added support for PyBoard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
125
cf50045a7c0f MicroPython: added support for PyBoard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
126 @return tuple containing a flag indicating it is safe to start a
cf50045a7c0f MicroPython: added support for PyBoard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
127 File Manager and a reason why it cannot.
cf50045a7c0f MicroPython: added support for PyBoard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
128 @rtype tuple of (bool, str)
cf50045a7c0f MicroPython: added support for PyBoard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
129 """
cf50045a7c0f MicroPython: added support for PyBoard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
130 return True, ""
cf50045a7c0f MicroPython: added support for PyBoard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
131
cf50045a7c0f MicroPython: added support for PyBoard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
132 def supportsLocalFileAccess(self):
cf50045a7c0f MicroPython: added support for PyBoard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
133 """
cf50045a7c0f MicroPython: added support for PyBoard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
134 Public method to indicate file access via a local directory.
cf50045a7c0f MicroPython: added support for PyBoard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
135
cf50045a7c0f MicroPython: added support for PyBoard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
136 @return flag indicating file access via local directory
cf50045a7c0f MicroPython: added support for PyBoard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
137 @rtype bool
cf50045a7c0f MicroPython: added support for PyBoard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
138 """
cf50045a7c0f MicroPython: added support for PyBoard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
139 return self.__deviceVolumeMounted()
cf50045a7c0f MicroPython: added support for PyBoard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
140
cf50045a7c0f MicroPython: added support for PyBoard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
141 def __deviceVolumeMounted(self):
cf50045a7c0f MicroPython: added support for PyBoard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
142 """
cf50045a7c0f MicroPython: added support for PyBoard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
143 Private method to check, if the device volume is mounted.
cf50045a7c0f MicroPython: added support for PyBoard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
144
cf50045a7c0f MicroPython: added support for PyBoard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
145 @return flag indicated a mounted device
cf50045a7c0f MicroPython: added support for PyBoard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
146 @rtype bool
cf50045a7c0f MicroPython: added support for PyBoard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
147 """
8081
e0087e542717 PyBoardDevices: fixed a little omission.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8067
diff changeset
148 if self.__workspace and not os.path.exists(self.__workspace):
e0087e542717 PyBoardDevices: fixed a little omission.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8067
diff changeset
149 self.__workspace = "" # reset
e0087e542717 PyBoardDevices: fixed a little omission.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8067
diff changeset
150
8062
8dc5acb30a8b MicroPython: implemented code to deal with multiple devices attached to the computer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
151 return self.DeviceVolumeName in self.getWorkspace(silent=True)
7295
cf50045a7c0f MicroPython: added support for PyBoard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
152
cf50045a7c0f MicroPython: added support for PyBoard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
153 def getWorkspace(self, silent=False):
cf50045a7c0f MicroPython: added support for PyBoard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
154 """
cf50045a7c0f MicroPython: added support for PyBoard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
155 Public method to get the workspace directory.
cf50045a7c0f MicroPython: added support for PyBoard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
156
cf50045a7c0f MicroPython: added support for PyBoard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
157 @param silent flag indicating silent operations
cf50045a7c0f MicroPython: added support for PyBoard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
158 @type bool
cf50045a7c0f MicroPython: added support for PyBoard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
159 @return workspace directory used for saving files
cf50045a7c0f MicroPython: added support for PyBoard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
160 @rtype str
cf50045a7c0f MicroPython: added support for PyBoard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
161 """
8062
8dc5acb30a8b MicroPython: implemented code to deal with multiple devices attached to the computer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
162 if self.__workspace:
8dc5acb30a8b MicroPython: implemented code to deal with multiple devices attached to the computer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
163 # return cached entry
8dc5acb30a8b MicroPython: implemented code to deal with multiple devices attached to the computer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
164 return self.__workspace
8dc5acb30a8b MicroPython: implemented code to deal with multiple devices attached to the computer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
165 else:
8dc5acb30a8b MicroPython: implemented code to deal with multiple devices attached to the computer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
166 self.__workspace = self.__findWorkspace(silent=silent)
8dc5acb30a8b MicroPython: implemented code to deal with multiple devices attached to the computer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
167 return self.__workspace
8dc5acb30a8b MicroPython: implemented code to deal with multiple devices attached to the computer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
168
8dc5acb30a8b MicroPython: implemented code to deal with multiple devices attached to the computer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
169 def __findWorkspace(self, silent=False):
8dc5acb30a8b MicroPython: implemented code to deal with multiple devices attached to the computer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
170 """
8067
a467ab075be0 MicroPython: added buttons to go to the 'home' directory (local and on device) to the MicroPython file manager and improved the workspace handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8062
diff changeset
171 Private method to find the workspace directory.
8062
8dc5acb30a8b MicroPython: implemented code to deal with multiple devices attached to the computer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
172
8dc5acb30a8b MicroPython: implemented code to deal with multiple devices attached to the computer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
173 @param silent flag indicating silent operations
8dc5acb30a8b MicroPython: implemented code to deal with multiple devices attached to the computer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
174 @type bool
8dc5acb30a8b MicroPython: implemented code to deal with multiple devices attached to the computer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
175 @return workspace directory used for saving files
8dc5acb30a8b MicroPython: implemented code to deal with multiple devices attached to the computer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
176 @rtype str
8dc5acb30a8b MicroPython: implemented code to deal with multiple devices attached to the computer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
177 """
7295
cf50045a7c0f MicroPython: added support for PyBoard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
178 # Attempts to find the path on the filesystem that represents the
cf50045a7c0f MicroPython: added support for PyBoard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
179 # plugged in PyBoard board.
8062
8dc5acb30a8b MicroPython: implemented code to deal with multiple devices attached to the computer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
180 deviceDirectories = Utilities.findVolume(self.DeviceVolumeName,
8067
a467ab075be0 MicroPython: added buttons to go to the 'home' directory (local and on device) to the MicroPython file manager and improved the workspace handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8062
diff changeset
181 findAll=True)
7295
cf50045a7c0f MicroPython: added support for PyBoard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
182
8062
8dc5acb30a8b MicroPython: implemented code to deal with multiple devices attached to the computer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
183 if deviceDirectories:
8dc5acb30a8b MicroPython: implemented code to deal with multiple devices attached to the computer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
184 if len(deviceDirectories) == 1:
8dc5acb30a8b MicroPython: implemented code to deal with multiple devices attached to the computer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
185 return deviceDirectories[0]
8dc5acb30a8b MicroPython: implemented code to deal with multiple devices attached to the computer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
186 else:
8dc5acb30a8b MicroPython: implemented code to deal with multiple devices attached to the computer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
187 return self.selectDeviceDirectory(deviceDirectories)
7295
cf50045a7c0f MicroPython: added support for PyBoard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
188 else:
cf50045a7c0f MicroPython: added support for PyBoard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
189 # return the default workspace and give the user a warning (unless
cf50045a7c0f MicroPython: added support for PyBoard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
190 # silent mode is selected)
cf50045a7c0f MicroPython: added support for PyBoard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
191 if not silent:
cf50045a7c0f MicroPython: added support for PyBoard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
192 E5MessageBox.warning(
cf50045a7c0f MicroPython: added support for PyBoard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
193 self.microPython,
cf50045a7c0f MicroPython: added support for PyBoard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
194 self.tr("Workspace Directory"),
8067
a467ab075be0 MicroPython: added buttons to go to the 'home' directory (local and on device) to the MicroPython file manager and improved the workspace handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8062
diff changeset
195 self.tr("Python files for PyBoard can be edited in"
a467ab075be0 MicroPython: added buttons to go to the 'home' directory (local and on device) to the MicroPython file manager and improved the workspace handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8062
diff changeset
196 " place, if the device volume is locally"
a467ab075be0 MicroPython: added buttons to go to the 'home' directory (local and on device) to the MicroPython file manager and improved the workspace handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8062
diff changeset
197 " available. Such a volume was not found. In"
a467ab075be0 MicroPython: added buttons to go to the 'home' directory (local and on device) to the MicroPython file manager and improved the workspace handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8062
diff changeset
198 " place editing will not be available."
a467ab075be0 MicroPython: added buttons to go to the 'home' directory (local and on device) to the MicroPython file manager and improved the workspace handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8062
diff changeset
199 )
a467ab075be0 MicroPython: added buttons to go to the 'home' directory (local and on device) to the MicroPython file manager and improved the workspace handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8062
diff changeset
200 )
7295
cf50045a7c0f MicroPython: added support for PyBoard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
201
cf50045a7c0f MicroPython: added support for PyBoard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
202 return super(PyBoardDevice, self).getWorkspace()
cf50045a7c0f MicroPython: added support for PyBoard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
203
cf50045a7c0f MicroPython: added support for PyBoard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
204 def getDocumentationUrl(self):
cf50045a7c0f MicroPython: added support for PyBoard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
205 """
cf50045a7c0f MicroPython: added support for PyBoard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
206 Public method to get the device documentation URL.
cf50045a7c0f MicroPython: added support for PyBoard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
207
cf50045a7c0f MicroPython: added support for PyBoard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
208 @return documentation URL of the device
cf50045a7c0f MicroPython: added support for PyBoard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
209 @rtype str
cf50045a7c0f MicroPython: added support for PyBoard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
210 """
cf50045a7c0f MicroPython: added support for PyBoard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
211 return Preferences.getMicroPython("MicroPythonDocuUrl")
7328
e2d85ef3fadb MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7327
diff changeset
212
e2d85ef3fadb MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7327
diff changeset
213 def getFirmwareUrl(self):
e2d85ef3fadb MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7327
diff changeset
214 """
e2d85ef3fadb MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7327
diff changeset
215 Public method to get the device firmware download URL.
e2d85ef3fadb MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7327
diff changeset
216
e2d85ef3fadb MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7327
diff changeset
217 @return firmware download URL of the device
e2d85ef3fadb MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7327
diff changeset
218 @rtype str
e2d85ef3fadb MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7327
diff changeset
219 """
e2d85ef3fadb MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7327
diff changeset
220 return Preferences.getMicroPython("MicroPythonFirmwareUrl")
e2d85ef3fadb MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7327
diff changeset
221
7295
cf50045a7c0f MicroPython: added support for PyBoard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
222 def addDeviceMenuEntries(self, menu):
cf50045a7c0f MicroPython: added support for PyBoard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
223 """
cf50045a7c0f MicroPython: added support for PyBoard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
224 Public method to add device specific entries to the given menu.
cf50045a7c0f MicroPython: added support for PyBoard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
225
cf50045a7c0f MicroPython: added support for PyBoard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
226 @param menu reference to the context menu
cf50045a7c0f MicroPython: added support for PyBoard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
227 @type QMenu
cf50045a7c0f MicroPython: added support for PyBoard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
228 """
7327
71883ddcb762 MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7321
diff changeset
229 connected = self.microPython.isConnected()
71883ddcb762 MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7321
diff changeset
230
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
231 act = menu.addAction(self.tr("Activate Bootloader"),
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
232 self.__activateBootloader)
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
233 act.setEnabled(connected)
7327
71883ddcb762 MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7321
diff changeset
234 act = menu.addAction(self.tr("List DFU-capable Devices"),
71883ddcb762 MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7321
diff changeset
235 self.__listDfuCapableDevices)
71883ddcb762 MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7321
diff changeset
236 act.setEnabled(not connected)
71883ddcb762 MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7321
diff changeset
237 act = menu.addAction(self.tr("Flash MicroPython Firmware"),
71883ddcb762 MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7321
diff changeset
238 self.__flashMicroPython)
71883ddcb762 MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7321
diff changeset
239 act.setEnabled(not connected)
71883ddcb762 MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7321
diff changeset
240 menu.addSeparator()
71883ddcb762 MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7321
diff changeset
241 menu.addAction(self.tr("MicroPython Flash Instructions"),
71883ddcb762 MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7321
diff changeset
242 self.__showFlashInstructions)
7295
cf50045a7c0f MicroPython: added support for PyBoard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
243
8096
5425a9072300 MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8081
diff changeset
244 def hasFlashMenuEntry(self):
5425a9072300 MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8081
diff changeset
245 """
5425a9072300 MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8081
diff changeset
246 Public method to check, if the device has its own flash menu entry.
5425a9072300 MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8081
diff changeset
247
5425a9072300 MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8081
diff changeset
248 @return flag indicating a specific flash menu entry
5425a9072300 MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8081
diff changeset
249 @rtype bool
5425a9072300 MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8081
diff changeset
250 """
5425a9072300 MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8081
diff changeset
251 return True
5425a9072300 MicroPython
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8081
diff changeset
252
7327
71883ddcb762 MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7321
diff changeset
253 @pyqtSlot()
71883ddcb762 MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7321
diff changeset
254 def __showFlashInstructions(self):
7295
cf50045a7c0f MicroPython: added support for PyBoard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
255 """
cf50045a7c0f MicroPython: added support for PyBoard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
256 Private slot to open the URL containing instructions for installing
cf50045a7c0f MicroPython: added support for PyBoard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
257 MicroPython on the pyboard.
cf50045a7c0f MicroPython: added support for PyBoard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
258 """
cf50045a7c0f MicroPython: added support for PyBoard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
259 e5App().getObject("UserInterface").launchHelpViewer(
cf50045a7c0f MicroPython: added support for PyBoard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
260 PyBoardDevice.FlashInstructionsURL)
7327
71883ddcb762 MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7321
diff changeset
261
71883ddcb762 MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7321
diff changeset
262 def __dfuUtilAvailable(self):
71883ddcb762 MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7321
diff changeset
263 """
71883ddcb762 MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7321
diff changeset
264 Private method to check the availability of dfu-util.
71883ddcb762 MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7321
diff changeset
265
71883ddcb762 MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7321
diff changeset
266 @return flag indicating the availability of dfu-util
71883ddcb762 MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7321
diff changeset
267 @rtype bool
71883ddcb762 MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7321
diff changeset
268 """
71883ddcb762 MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7321
diff changeset
269 available = False
71883ddcb762 MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7321
diff changeset
270 program = Preferences.getMicroPython("DfuUtilPath")
71883ddcb762 MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7321
diff changeset
271 if not program:
71883ddcb762 MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7321
diff changeset
272 program = "dfu-util"
71883ddcb762 MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7321
diff changeset
273 if Utilities.isinpath(program):
71883ddcb762 MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7321
diff changeset
274 available = True
71883ddcb762 MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7321
diff changeset
275 else:
71883ddcb762 MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7321
diff changeset
276 if Utilities.isExecutable(program):
71883ddcb762 MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7321
diff changeset
277 available = True
71883ddcb762 MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7321
diff changeset
278
71883ddcb762 MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7321
diff changeset
279 if not available:
71883ddcb762 MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7321
diff changeset
280 E5MessageBox.critical(
71883ddcb762 MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7321
diff changeset
281 self.microPython,
71883ddcb762 MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7321
diff changeset
282 self.tr("dfu-util not available"),
71883ddcb762 MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7321
diff changeset
283 self.tr("""The dfu-util firmware flashing tool"""
71883ddcb762 MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7321
diff changeset
284 """ <b>dfu-util</b> cannot be found or is not"""
71883ddcb762 MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7321
diff changeset
285 """ executable. Ensure it is in the search path"""
71883ddcb762 MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7321
diff changeset
286 """ or configure it on the MicroPython"""
71883ddcb762 MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7321
diff changeset
287 """ configuration page.""")
71883ddcb762 MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7321
diff changeset
288 )
71883ddcb762 MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7321
diff changeset
289
71883ddcb762 MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7321
diff changeset
290 return available
71883ddcb762 MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7321
diff changeset
291
71883ddcb762 MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7321
diff changeset
292 def __showDfuEnableInstructions(self, flash=True):
71883ddcb762 MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7321
diff changeset
293 """
71883ddcb762 MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7321
diff changeset
294 Private method to show some instructions to enable the DFU mode.
71883ddcb762 MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7321
diff changeset
295
71883ddcb762 MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7321
diff changeset
296 @param flash flag indicating to show a warning message for flashing
71883ddcb762 MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7321
diff changeset
297 @type bool
71883ddcb762 MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7321
diff changeset
298 @return flag indicating OK to continue or abort
71883ddcb762 MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7321
diff changeset
299 @rtype bool
71883ddcb762 MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7321
diff changeset
300 """
71883ddcb762 MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7321
diff changeset
301 msg = self.tr(
71883ddcb762 MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7321
diff changeset
302 "<h3>Enable DFU Mode</h3>"
71883ddcb762 MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7321
diff changeset
303 "<p>1. Disconnect everything from your board</p>"
71883ddcb762 MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7321
diff changeset
304 "<p>2. Disconnect your board</p>"
71883ddcb762 MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7321
diff changeset
305 "<p>3. Connect the DFU/BOOT0 pin with a 3.3V pin</p>"
71883ddcb762 MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7321
diff changeset
306 "<p>4. Re-connect your board</p>"
71883ddcb762 MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7321
diff changeset
307 "<hr />"
71883ddcb762 MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7321
diff changeset
308 )
71883ddcb762 MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7321
diff changeset
309
71883ddcb762 MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7321
diff changeset
310 if flash:
71883ddcb762 MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7321
diff changeset
311 msg += self.tr(
71883ddcb762 MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7321
diff changeset
312 "<p><b>Warning:</b> Make sure that all other DFU capable"
71883ddcb762 MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7321
diff changeset
313 " devices except your PyBoard are disconnected."
71883ddcb762 MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7321
diff changeset
314 "<hr />"
71883ddcb762 MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7321
diff changeset
315 )
71883ddcb762 MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7321
diff changeset
316
71883ddcb762 MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7321
diff changeset
317 msg += self.tr(
71883ddcb762 MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7321
diff changeset
318 "<p>Press <b>OK</b> to continue...</p>"
71883ddcb762 MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7321
diff changeset
319 )
71883ddcb762 MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7321
diff changeset
320 res = E5MessageBox.information(
71883ddcb762 MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7321
diff changeset
321 self.microPython,
71883ddcb762 MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7321
diff changeset
322 self.tr("Enable DFU mode"),
71883ddcb762 MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7321
diff changeset
323 msg,
71883ddcb762 MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7321
diff changeset
324 E5MessageBox.StandardButtons(
71883ddcb762 MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7321
diff changeset
325 E5MessageBox.Abort |
71883ddcb762 MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7321
diff changeset
326 E5MessageBox.Ok))
71883ddcb762 MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7321
diff changeset
327
71883ddcb762 MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7321
diff changeset
328 return res == E5MessageBox.Ok
71883ddcb762 MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7321
diff changeset
329
71883ddcb762 MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7321
diff changeset
330 def __showDfuDisableInstructions(self):
71883ddcb762 MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7321
diff changeset
331 """
71883ddcb762 MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7321
diff changeset
332 Private method to show some instructions to disable the DFU mode.
71883ddcb762 MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7321
diff changeset
333 """
71883ddcb762 MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7321
diff changeset
334 msg = self.tr(
71883ddcb762 MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7321
diff changeset
335 "<h3>Disable DFU Mode</h3>"
71883ddcb762 MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7321
diff changeset
336 "<p>1. Disconnect your board</p>"
71883ddcb762 MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7321
diff changeset
337 "<p>2. Remove the DFU jumper</p>"
71883ddcb762 MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7321
diff changeset
338 "<p>3. Re-connect your board</p>"
71883ddcb762 MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7321
diff changeset
339 "<hr />"
71883ddcb762 MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7321
diff changeset
340 "<p>Press <b>OK</b> to continue...</p>"
71883ddcb762 MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7321
diff changeset
341 )
71883ddcb762 MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7321
diff changeset
342 E5MessageBox.information(
71883ddcb762 MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7321
diff changeset
343 self.microPython,
71883ddcb762 MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7321
diff changeset
344 self.tr("Disable DFU mode"),
71883ddcb762 MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7321
diff changeset
345 msg
71883ddcb762 MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7321
diff changeset
346 )
71883ddcb762 MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7321
diff changeset
347
71883ddcb762 MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7321
diff changeset
348 @pyqtSlot()
71883ddcb762 MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7321
diff changeset
349 def __listDfuCapableDevices(self):
71883ddcb762 MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7321
diff changeset
350 """
71883ddcb762 MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7321
diff changeset
351 Private slot to list all DFU-capable devices.
71883ddcb762 MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7321
diff changeset
352 """
71883ddcb762 MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7321
diff changeset
353 if self.__dfuUtilAvailable():
71883ddcb762 MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7321
diff changeset
354 ok2continue = self.__showDfuEnableInstructions(flash=False)
71883ddcb762 MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7321
diff changeset
355 if ok2continue:
71883ddcb762 MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7321
diff changeset
356 program = Preferences.getMicroPython("DfuUtilPath")
71883ddcb762 MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7321
diff changeset
357 if not program:
71883ddcb762 MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7321
diff changeset
358 program = "dfu-util"
71883ddcb762 MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7321
diff changeset
359
71883ddcb762 MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7321
diff changeset
360 args = [
71883ddcb762 MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7321
diff changeset
361 "--list",
71883ddcb762 MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7321
diff changeset
362 ]
71883ddcb762 MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7321
diff changeset
363 dlg = E5ProcessDialog(
71883ddcb762 MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7321
diff changeset
364 self.tr("'dfu-util' Output"),
71883ddcb762 MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7321
diff changeset
365 self.tr("List DFU capable Devices")
71883ddcb762 MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7321
diff changeset
366 )
71883ddcb762 MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7321
diff changeset
367 res = dlg.startProcess(program, args)
71883ddcb762 MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7321
diff changeset
368 if res:
7759
51aa6c6b66f7 Changed calls to exec_() into exec() (remainder of Python2 elimination).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
369 dlg.exec()
7327
71883ddcb762 MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7321
diff changeset
370
71883ddcb762 MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7321
diff changeset
371 @pyqtSlot()
71883ddcb762 MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7321
diff changeset
372 def __flashMicroPython(self):
71883ddcb762 MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7321
diff changeset
373 """
71883ddcb762 MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7321
diff changeset
374 Private slot to flash a MicroPython firmware.
71883ddcb762 MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7321
diff changeset
375 """
71883ddcb762 MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7321
diff changeset
376 if self.__dfuUtilAvailable():
71883ddcb762 MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7321
diff changeset
377 ok2continue = self.__showDfuEnableInstructions()
71883ddcb762 MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7321
diff changeset
378 if ok2continue:
71883ddcb762 MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7321
diff changeset
379 program = Preferences.getMicroPython("DfuUtilPath")
71883ddcb762 MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7321
diff changeset
380 if not program:
71883ddcb762 MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7321
diff changeset
381 program = "dfu-util"
71883ddcb762 MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7321
diff changeset
382
71883ddcb762 MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7321
diff changeset
383 downloadsPath = QStandardPaths.standardLocations(
71883ddcb762 MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7321
diff changeset
384 QStandardPaths.DownloadLocation)[0]
71883ddcb762 MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7321
diff changeset
385 firmware = E5FileDialog.getOpenFileName(
71883ddcb762 MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7321
diff changeset
386 self.microPython,
71883ddcb762 MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7321
diff changeset
387 self.tr("Flash MicroPython Firmware"),
71883ddcb762 MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7321
diff changeset
388 downloadsPath,
71883ddcb762 MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7321
diff changeset
389 self.tr(
71883ddcb762 MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7321
diff changeset
390 "MicroPython Firmware Files (*.dfu);;All Files (*)")
71883ddcb762 MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7321
diff changeset
391 )
71883ddcb762 MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7321
diff changeset
392 if firmware and os.path.exists(firmware):
71883ddcb762 MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7321
diff changeset
393 args = [
71883ddcb762 MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7321
diff changeset
394 "--alt", "0",
71883ddcb762 MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7321
diff changeset
395 "--download", firmware,
71883ddcb762 MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7321
diff changeset
396 ]
71883ddcb762 MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7321
diff changeset
397 dlg = E5ProcessDialog(
71883ddcb762 MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7321
diff changeset
398 self.tr("'dfu-util' Output"),
71883ddcb762 MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7321
diff changeset
399 self.tr("Flash MicroPython Firmware")
71883ddcb762 MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7321
diff changeset
400 )
71883ddcb762 MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7321
diff changeset
401 res = dlg.startProcess(program, args)
71883ddcb762 MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7321
diff changeset
402 if res:
7759
51aa6c6b66f7 Changed calls to exec_() into exec() (remainder of Python2 elimination).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
403 dlg.exec()
7327
71883ddcb762 MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7321
diff changeset
404 self.__showDfuDisableInstructions()
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
405
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
406 @pyqtSlot()
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
407 def __activateBootloader(self):
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
408 """
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
409 Private slot to activate the bootloader and disconnect.
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
410 """
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
411 if self.microPython.isConnected():
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
412 self.microPython.commandsInterface().execute([
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
413 "import pyb",
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
414 "pyb.bootloader()",
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
415 ])
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
416 # simulate pressing the disconnect button
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
417 self.microPython.on_connectButton_clicked()

eric ide

mercurial