src/eric7/MicroPython/RP2040Devices.py

branch
eric7
changeset 9751
606ac0e26533
parent 9749
5d409223cf3f
child 9752
2b9546c0cbd9
equal deleted inserted replaced
9750:4958dd72c937 9751:606ac0e26533
173 """ 173 """
174 Private slot to show the firmware version of the connected device and the 174 Private slot to show the firmware version of the connected device and the
175 available firmware version. 175 available firmware version.
176 """ 176 """
177 if self.microPython.isConnected(): 177 if self.microPython.isConnected():
178 interface = self.microPython.commandsInterface() 178 if self._deviceData["mpy_name"] != "micropython":
179 if interface is not None: 179 EricMessageBox.critical(
180 impInfo = interface.getImplementation() 180 None,
181 if impInfo["name"] != "micropython": 181 self.tr("Show MicroPython Versions"),
182 EricMessageBox.critical( 182 self.tr(
183 None, 183 """The firmware of the connected device cannot be"""
184 self.tr("Show MicroPython Versions"), 184 """ determined or the board does not run MicroPython."""
185 self.tr( 185 """ Aborting..."""
186 """The firmware of the connected device cannot be""" 186 ),
187 """ determined or the board does not run MicroPython.""" 187 )
188 """ Aborting...""" 188 else:
189 ), 189 if self._deviceData["mpy_variant"] == "Pimoroni":
190 ) 190 # MicroPython with Pimoroni add-on libraries
191 url = QUrl(FirmwareGithubUrls["pimoroni_pico"])
191 else: 192 else:
192 if impInfo["variant"] == "Pimoroni": 193 url = QUrl(FirmwareGithubUrls["micropython"])
193 # MicroPython with Pimoroni add-on libraries 194 ui = ericApp().getObject("UserInterface")
194 url = QUrl(FirmwareGithubUrls["pimoroni_pico"]) 195 request = QNetworkRequest(url)
195 else: 196 reply = ui.networkAccessManager().head(request)
196 url = QUrl(FirmwareGithubUrls["micropython"]) 197 reply.finished.connect(lambda: self.__firmwareVersionResponse(reply))
197 ui = ericApp().getObject("UserInterface") 198
198 request = QNetworkRequest(url) 199 def __firmwareVersionResponse(self, reply):
199 reply = ui.networkAccessManager().head(request)
200 reply.finished.connect(
201 lambda: self.__firmwareVersionResponse(reply, impInfo)
202 )
203
204 def __firmwareVersionResponse(self, reply, implementation):
205 """ 200 """
206 Private method handling the response of the latest version request. 201 Private method handling the response of the latest version request.
207 202
208 @param reply reference to the reply object 203 @param reply reference to the reply object
209 @type QNetworkReply 204 @type QNetworkReply
210 @param implementation dictionary containing the implementation data of the
211 connected device
212 @type dict
213 """ 205 """
214 latestUrl = reply.url().toString() 206 latestUrl = reply.url().toString()
215 tag = latestUrl.rsplit("/", 1)[-1] 207 tag = latestUrl.rsplit("/", 1)[-1]
216 while tag and not tag[0].isdecimal(): 208 while tag and not tag[0].isdecimal():
217 # get rid of leading non-decimal characters 209 # get rid of leading non-decimal characters
218 tag = tag[1:] 210 tag = tag[1:]
219 latestVersion = Globals.versionToTuple(tag) 211 latestVersion = Globals.versionToTuple(tag)
220 212
221 if implementation["version"] == "unknown": 213 if self._deviceData["mpy_version"] == "unknown":
222 currentVersionStr = self.tr("unknown") 214 currentVersionStr = self.tr("unknown")
223 currentVersion = (0, 0, 0) 215 currentVersion = (0, 0, 0)
224 else: 216 else:
225 currentVersionStr = implementation["version"] 217 currentVersionStr = self._deviceData["mpy_version"]
226 currentVersion = Globals.versionToTuple(currentVersionStr) 218 currentVersion = Globals.versionToTuple(currentVersionStr)
227 219
228 msg = self.tr( 220 msg = self.tr(
229 "<h4>MicroPython Version Information</h4>" 221 "<h4>MicroPython Version Information</h4>"
230 "<table>" 222 "<table>"
232 "<tr><td>Available:</td><td>{1}</td><td>{2}</td></tr>" 224 "<tr><td>Available:</td><td>{1}</td><td>{2}</td></tr>"
233 "</table>" 225 "</table>"
234 ).format( 226 ).format(
235 currentVersionStr, 227 currentVersionStr,
236 tag, 228 tag,
237 self.tr("({0})").format(implementation["variant"]) 229 self.tr("({0})").format(self._deviceData["mpy_variant"])
238 if implementation["variant"] 230 if self._deviceData["mpy_variant"]
239 else "", 231 else "",
240 ) 232 )
241 if ( 233 if (
242 implementation["variant"] not in ["Pimoroni"] 234 self._deviceData["mpy_variant"] not in ["Pimoroni"]
243 and currentVersion < latestVersion 235 and currentVersion < latestVersion
244 ): 236 ):
245 # cannot derive that info for 'Pimoroni' variant 237 # cannot derive that info for 'Pimoroni' variant
246 msg += self.tr("<p><b>Update available!</b></p>") 238 msg += self.tr("<p><b>Update available!</b></p>")
247 239
285 Preferences.getMicroPython("CircuitPythonLibrariesUrl"), 277 Preferences.getMicroPython("CircuitPythonLibrariesUrl"),
286 ), 278 ),
287 ] 279 ]
288 280
289 281
290 def createDevice(microPythonWidget, deviceType, vid, pid, boardName): 282 def createDevice(microPythonWidget, deviceType, vid, pid, boardName, serialNumber):
291 """ 283 """
292 Function to instantiate a MicroPython device object. 284 Function to instantiate a MicroPython device object.
293 285
294 @param microPythonWidget reference to the main MicroPython widget 286 @param microPythonWidget reference to the main MicroPython widget
295 @type MicroPythonWidget 287 @type MicroPythonWidget
299 @type int 291 @type int
300 @param pid product ID 292 @param pid product ID
301 @type int 293 @type int
302 @param boardName name of the board 294 @param boardName name of the board
303 @type str 295 @type str
296 @param serialNumber serial number of the board
297 @type str
304 @return reference to the instantiated device object 298 @return reference to the instantiated device object
305 @rtype RP2040Device 299 @rtype RP2040Device
306 """ 300 """
307 return RP2040Device(microPythonWidget, deviceType) 301 return RP2040Device(microPythonWidget, deviceType)

eric ide

mercurial