src/eric7/MicroPython/RP2040Devices.py

branch
eric7
changeset 9221
bf71ee032bb4
parent 9209
b99e7fd55fd3
child 9413
80c06d472826
equal deleted inserted replaced
9220:e9e7eca7efee 9221:bf71ee032bb4
18 18
19 class RP2040Device(MicroPythonDevice): 19 class RP2040Device(MicroPythonDevice):
20 """ 20 """
21 Class implementing the device for RP2040 based boards. 21 Class implementing the device for RP2040 based boards.
22 """ 22 """
23
23 def __init__(self, microPythonWidget, deviceType, parent=None): 24 def __init__(self, microPythonWidget, deviceType, parent=None):
24 """ 25 """
25 Constructor 26 Constructor
26 27
27 @param microPythonWidget reference to the main MicroPython widget 28 @param microPythonWidget reference to the main MicroPython widget
28 @type MicroPythonWidget 29 @type MicroPythonWidget
29 @param deviceType device type assigned to this device interface 30 @param deviceType device type assigned to this device interface
30 @type str 31 @type str
31 @param parent reference to the parent object 32 @param parent reference to the parent object
32 @type QObject 33 @type QObject
33 """ 34 """
34 super().__init__( 35 super().__init__(microPythonWidget, deviceType, parent)
35 microPythonWidget, deviceType, parent) 36
36
37 def setButtons(self): 37 def setButtons(self):
38 """ 38 """
39 Public method to enable the supported action buttons. 39 Public method to enable the supported action buttons.
40 """ 40 """
41 super().setButtons() 41 super().setButtons()
42 self.microPython.setActionButtons( 42 self.microPython.setActionButtons(
43 run=True, repl=True, files=True, chart=HAS_QTCHART) 43 run=True, repl=True, files=True, chart=HAS_QTCHART
44 44 )
45
45 def forceInterrupt(self): 46 def forceInterrupt(self):
46 """ 47 """
47 Public method to determine the need for an interrupt when opening the 48 Public method to determine the need for an interrupt when opening the
48 serial connection. 49 serial connection.
49 50
50 @return flag indicating an interrupt is needed 51 @return flag indicating an interrupt is needed
51 @rtype bool 52 @rtype bool
52 """ 53 """
53 return False 54 return False
54 55
55 def deviceName(self): 56 def deviceName(self):
56 """ 57 """
57 Public method to get the name of the device. 58 Public method to get the name of the device.
58 59
59 @return name of the device 60 @return name of the device
60 @rtype str 61 @rtype str
61 """ 62 """
62 return self.tr("RP2040") 63 return self.tr("RP2040")
63 64
64 def canStartRepl(self): 65 def canStartRepl(self):
65 """ 66 """
66 Public method to determine, if a REPL can be started. 67 Public method to determine, if a REPL can be started.
67 68
68 @return tuple containing a flag indicating it is safe to start a REPL 69 @return tuple containing a flag indicating it is safe to start a REPL
69 and a reason why it cannot. 70 and a reason why it cannot.
70 @rtype tuple of (bool, str) 71 @rtype tuple of (bool, str)
71 """ 72 """
72 return True, "" 73 return True, ""
73 74
74 def canStartPlotter(self): 75 def canStartPlotter(self):
75 """ 76 """
76 Public method to determine, if a Plotter can be started. 77 Public method to determine, if a Plotter can be started.
77 78
78 @return tuple containing a flag indicating it is safe to start a 79 @return tuple containing a flag indicating it is safe to start a
79 Plotter and a reason why it cannot. 80 Plotter and a reason why it cannot.
80 @rtype tuple of (bool, str) 81 @rtype tuple of (bool, str)
81 """ 82 """
82 return True, "" 83 return True, ""
83 84
84 def canRunScript(self): 85 def canRunScript(self):
85 """ 86 """
86 Public method to determine, if a script can be executed. 87 Public method to determine, if a script can be executed.
87 88
88 @return tuple containing a flag indicating it is safe to start a 89 @return tuple containing a flag indicating it is safe to start a
89 Plotter and a reason why it cannot. 90 Plotter and a reason why it cannot.
90 @rtype tuple of (bool, str) 91 @rtype tuple of (bool, str)
91 """ 92 """
92 return True, "" 93 return True, ""
93 94
94 def runScript(self, script): 95 def runScript(self, script):
95 """ 96 """
96 Public method to run the given Python script. 97 Public method to run the given Python script.
97 98
98 @param script script to be executed 99 @param script script to be executed
99 @type str 100 @type str
100 """ 101 """
101 pythonScript = script.split("\n") 102 pythonScript = script.split("\n")
102 self.sendCommands(pythonScript) 103 self.sendCommands(pythonScript)
103 104
104 def canStartFileManager(self): 105 def canStartFileManager(self):
105 """ 106 """
106 Public method to determine, if a File Manager can be started. 107 Public method to determine, if a File Manager can be started.
107 108
108 @return tuple containing a flag indicating it is safe to start a 109 @return tuple containing a flag indicating it is safe to start a
109 File Manager and a reason why it cannot. 110 File Manager and a reason why it cannot.
110 @rtype tuple of (bool, str) 111 @rtype tuple of (bool, str)
111 """ 112 """
112 return True, "" 113 return True, ""
113 114
114 def addDeviceMenuEntries(self, menu): 115 def addDeviceMenuEntries(self, menu):
115 """ 116 """
116 Public method to add device specific entries to the given menu. 117 Public method to add device specific entries to the given menu.
117 118
118 @param menu reference to the context menu 119 @param menu reference to the context menu
119 @type QMenu 120 @type QMenu
120 """ 121 """
121 connected = self.microPython.isConnected() 122 connected = self.microPython.isConnected()
122 123
123 act = menu.addAction(self.tr("Activate Bootloader"), 124 act = menu.addAction(self.tr("Activate Bootloader"), self.__activateBootloader)
124 self.__activateBootloader)
125 act.setEnabled(connected) 125 act.setEnabled(connected)
126 act = menu.addAction(self.tr("Flash Firmware"), self.__flashPython) 126 act = menu.addAction(self.tr("Flash Firmware"), self.__flashPython)
127 act.setEnabled(not connected) 127 act.setEnabled(not connected)
128 128
129 def hasFlashMenuEntry(self): 129 def hasFlashMenuEntry(self):
130 """ 130 """
131 Public method to check, if the device has its own flash menu entry. 131 Public method to check, if the device has its own flash menu entry.
132 132
133 @return flag indicating a specific flash menu entry 133 @return flag indicating a specific flash menu entry
134 @rtype bool 134 @rtype bool
135 """ 135 """
136 return True 136 return True
137 137
138 @pyqtSlot() 138 @pyqtSlot()
139 def __flashPython(self): 139 def __flashPython(self):
140 """ 140 """
141 Private slot to flash a MicroPython firmware to the device. 141 Private slot to flash a MicroPython firmware to the device.
142 """ 142 """
143 from .UF2FlashDialog import UF2FlashDialog 143 from .UF2FlashDialog import UF2FlashDialog
144
144 dlg = UF2FlashDialog(boardType="rp2040") 145 dlg = UF2FlashDialog(boardType="rp2040")
145 dlg.exec() 146 dlg.exec()
146 147
147 def __activateBootloader(self): 148 def __activateBootloader(self):
148 """ 149 """
149 Private method to switch the board into 'bootloader' mode. 150 Private method to switch the board into 'bootloader' mode.
150 """ 151 """
151 if self.microPython.isConnected(): 152 if self.microPython.isConnected():
152 self.microPython.commandsInterface().execute([ 153 self.microPython.commandsInterface().execute(
153 "import machine", 154 [
154 "machine.bootloader()", 155 "import machine",
155 ]) 156 "machine.bootloader()",
157 ]
158 )
156 # simulate pressing the disconnect button 159 # simulate pressing the disconnect button
157 self.microPython.on_connectButton_clicked() 160 self.microPython.on_connectButton_clicked()
158 161
159 def getDocumentationUrl(self): 162 def getDocumentationUrl(self):
160 """ 163 """
161 Public method to get the device documentation URL. 164 Public method to get the device documentation URL.
162 165
163 @return documentation URL of the device 166 @return documentation URL of the device
164 @rtype str 167 @rtype str
165 """ 168 """
166 return Preferences.getMicroPython("MicroPythonDocuUrl") 169 return Preferences.getMicroPython("MicroPythonDocuUrl")
167 170
168 def getDownloadMenuEntries(self): 171 def getDownloadMenuEntries(self):
169 """ 172 """
170 Public method to retrieve the entries for the downloads menu. 173 Public method to retrieve the entries for the downloads menu.
171 174
172 @return list of tuples with menu text and URL to be opened for each 175 @return list of tuples with menu text and URL to be opened for each
173 entry 176 entry
174 @rtype list of tuple of (str, str) 177 @rtype list of tuple of (str, str)
175 """ 178 """
176 return [ 179 return [
177 (self.tr("MicroPython Firmware"), 180 (
178 Preferences.getMicroPython("MicroPythonFirmwareUrl")), 181 self.tr("MicroPython Firmware"),
182 Preferences.getMicroPython("MicroPythonFirmwareUrl"),
183 ),
179 ("<separator>", ""), 184 ("<separator>", ""),
180 (self.tr("CircuitPython Firmware"), 185 (
181 Preferences.getMicroPython("CircuitPythonFirmwareUrl")), 186 self.tr("CircuitPython Firmware"),
182 (self.tr("CircuitPython Libraries"), 187 Preferences.getMicroPython("CircuitPythonFirmwareUrl"),
183 Preferences.getMicroPython("CircuitPythonLibrariesUrl")) 188 ),
189 (
190 self.tr("CircuitPython Libraries"),
191 Preferences.getMicroPython("CircuitPythonLibrariesUrl"),
192 ),
184 ] 193 ]

eric ide

mercurial