eric6/MicroPython/MicrobitDevices.py

Sat, 30 Jan 2021 19:11:02 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sat, 30 Jan 2021 19:11:02 +0100
changeset 8032
76375aa6bc04
parent 7923
91e843545d9a
child 8038
73ec029d4107
permissions
-rw-r--r--

Corrected the support code for the "BBC micro:bit" MicroPython device.

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
7923
91e843545d9a Updated copyright for 2021.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7780
diff changeset
3 # Copyright (c) 2019 - 2021 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 """
7549
fcfbb9e94471 MicroPython: continued implementing support for the "Calliope mini".
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7548
diff changeset
7 Module implementing the device interface class for BBC micro:bit and
fcfbb9e94471 MicroPython: continued implementing support for the "Calliope mini".
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7548
diff changeset
8 Calliope mini 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
7123
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
11 import os
7299
a22b87b46128 MicrobitDevices: modified the MicroPython flashing routine and the saving of scripts to the device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
12 import shutil
7123
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
13
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
14 from PyQt5.QtCore import pyqtSlot, QStandardPaths
7299
a22b87b46128 MicrobitDevices: modified the MicroPython flashing routine and the saving of scripts to the device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
15 from PyQt5.QtWidgets import QInputDialog, QLineEdit
7123
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
16
7059
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
17 from .MicroPythonDevices import MicroPythonDevice
7134
21d23ca51680 Renamed "MicroPythonReplWidget" to "MicroPythonWidget".
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7126
diff changeset
18 from .MicroPythonWidget import HAS_QTCHART
7059
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
19
7123
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
20 from E5Gui import E5MessageBox, E5FileDialog
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
21 from E5Gui.E5Application import e5App
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
22
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
23 import Utilities
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
24 import Preferences
7123
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
25
7059
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
26
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
27 class MicrobitDevice(MicroPythonDevice):
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
28 """
7549
fcfbb9e94471 MicroPython: continued implementing support for the "Calliope mini".
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7548
diff changeset
29 Class implementing the device for BBC micro:bit and Calliope mini boards.
7059
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
30 """
7549
fcfbb9e94471 MicroPython: continued implementing support for the "Calliope mini".
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7548
diff changeset
31 def __init__(self, microPythonWidget, deviceType, parent=None):
7059
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
32 """
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
33 Constructor
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
34
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
35 @param microPythonWidget reference to the main MicroPython widget
7134
21d23ca51680 Renamed "MicroPythonReplWidget" to "MicroPythonWidget".
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7126
diff changeset
36 @type MicroPythonWidget
7549
fcfbb9e94471 MicroPython: continued implementing support for the "Calliope mini".
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7548
diff changeset
37 @param deviceType type of the device
fcfbb9e94471 MicroPython: continued implementing support for the "Calliope mini".
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7548
diff changeset
38 @type str
7059
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
39 @param parent reference to the parent object
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
40 @type QObject
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
41 """
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
42 super(MicrobitDevice, self).__init__(microPythonWidget, parent)
7549
fcfbb9e94471 MicroPython: continued implementing support for the "Calliope mini".
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7548
diff changeset
43
fcfbb9e94471 MicroPython: continued implementing support for the "Calliope mini".
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7548
diff changeset
44 self.__deviceType = deviceType
7059
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
45
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
46 def setButtons(self):
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
47 """
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
48 Public method to enable the supported action buttons.
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
49 """
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
50 super(MicrobitDevice, self).setButtons()
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
51 self.microPython.setActionButtons(
7126
376deb7fefe7 microbit: added the minimal filesystem commands which are supported by the BBC micro:bit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7123
diff changeset
52 run=True, repl=True, files=True, chart=HAS_QTCHART)
7059
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
53
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
54 def forceInterrupt(self):
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
55 """
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
56 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
57 serial connection.
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
58
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
59 @return flag indicating an interrupt is needed
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
60 @rtype bool
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
61 """
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
62 return True
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
63
7126
376deb7fefe7 microbit: added the minimal filesystem commands which are supported by the BBC micro:bit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7123
diff changeset
64 def deviceName(self):
376deb7fefe7 microbit: added the minimal filesystem commands which are supported by the BBC micro:bit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7123
diff changeset
65 """
376deb7fefe7 microbit: added the minimal filesystem commands which are supported by the BBC micro:bit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7123
diff changeset
66 Public method to get the name of the device.
376deb7fefe7 microbit: added the minimal filesystem commands which are supported by the BBC micro:bit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7123
diff changeset
67
376deb7fefe7 microbit: added the minimal filesystem commands which are supported by the BBC micro:bit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7123
diff changeset
68 @return name of the device
376deb7fefe7 microbit: added the minimal filesystem commands which are supported by the BBC micro:bit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7123
diff changeset
69 @rtype str
376deb7fefe7 microbit: added the minimal filesystem commands which are supported by the BBC micro:bit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7123
diff changeset
70 """
7551
b159c55ea6dd MicroPython: continued implementing support for the "Calliope mini".
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7549
diff changeset
71 if self.__deviceType == "bbc_microbit":
b159c55ea6dd MicroPython: continued implementing support for the "Calliope mini".
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7549
diff changeset
72 # BBC micro:bit
b159c55ea6dd MicroPython: continued implementing support for the "Calliope mini".
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7549
diff changeset
73 return self.tr("BBC micro:bit")
b159c55ea6dd MicroPython: continued implementing support for the "Calliope mini".
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7549
diff changeset
74 else:
b159c55ea6dd MicroPython: continued implementing support for the "Calliope mini".
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7549
diff changeset
75 # Calliope mini
b159c55ea6dd MicroPython: continued implementing support for the "Calliope mini".
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7549
diff changeset
76 return self.tr("Calliope mini")
7126
376deb7fefe7 microbit: added the minimal filesystem commands which are supported by the BBC micro:bit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7123
diff changeset
77
7059
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
78 def canStartRepl(self):
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
79 """
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
80 Public method to determine, if a REPL can be started.
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
81
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
82 @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
83 and a reason why it cannot.
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
84 @rtype tuple of (bool, str)
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
85 """
7100
c4d9c28ebcd8 Devices.py files: removed some methods no longer needed after the recent improvements.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7082
diff changeset
86 return True, ""
7059
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
87
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
88 def canStartPlotter(self):
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
89 """
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
90 Public method to determine, if a Plotter can be started.
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
91
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
92 @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
93 Plotter and a reason why it cannot.
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
94 @rtype tuple of (bool, str)
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
95 """
7100
c4d9c28ebcd8 Devices.py files: removed some methods no longer needed after the recent improvements.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7082
diff changeset
96 return True, ""
7059
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
97
7126
376deb7fefe7 microbit: added the minimal filesystem commands which are supported by the BBC micro:bit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7123
diff changeset
98 def canRunScript(self):
376deb7fefe7 microbit: added the minimal filesystem commands which are supported by the BBC micro:bit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7123
diff changeset
99 """
376deb7fefe7 microbit: added the minimal filesystem commands which are supported by the BBC micro:bit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7123
diff changeset
100 Public method to determine, if a script can be executed.
376deb7fefe7 microbit: added the minimal filesystem commands which are supported by the BBC micro:bit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7123
diff changeset
101
376deb7fefe7 microbit: added the minimal filesystem commands which are supported by the BBC micro:bit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7123
diff changeset
102 @return tuple containing a flag indicating it is safe to start a
376deb7fefe7 microbit: added the minimal filesystem commands which are supported by the BBC micro:bit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7123
diff changeset
103 Plotter and a reason why it cannot.
376deb7fefe7 microbit: added the minimal filesystem commands which are supported by the BBC micro:bit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7123
diff changeset
104 @rtype tuple of (bool, str)
376deb7fefe7 microbit: added the minimal filesystem commands which are supported by the BBC micro:bit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7123
diff changeset
105 """
376deb7fefe7 microbit: added the minimal filesystem commands which are supported by the BBC micro:bit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7123
diff changeset
106 return True, ""
376deb7fefe7 microbit: added the minimal filesystem commands which are supported by the BBC micro:bit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7123
diff changeset
107
376deb7fefe7 microbit: added the minimal filesystem commands which are supported by the BBC micro:bit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7123
diff changeset
108 def runScript(self, script):
376deb7fefe7 microbit: added the minimal filesystem commands which are supported by the BBC micro:bit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7123
diff changeset
109 """
376deb7fefe7 microbit: added the minimal filesystem commands which are supported by the BBC micro:bit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7123
diff changeset
110 Public method to run the given Python script.
376deb7fefe7 microbit: added the minimal filesystem commands which are supported by the BBC micro:bit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7123
diff changeset
111
376deb7fefe7 microbit: added the minimal filesystem commands which are supported by the BBC micro:bit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7123
diff changeset
112 @param script script to be executed
376deb7fefe7 microbit: added the minimal filesystem commands which are supported by the BBC micro:bit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7123
diff changeset
113 @type str
376deb7fefe7 microbit: added the minimal filesystem commands which are supported by the BBC micro:bit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7123
diff changeset
114 """
376deb7fefe7 microbit: added the minimal filesystem commands which are supported by the BBC micro:bit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7123
diff changeset
115 pythonScript = script.split("\n")
376deb7fefe7 microbit: added the minimal filesystem commands which are supported by the BBC micro:bit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7123
diff changeset
116 self.sendCommands(pythonScript)
376deb7fefe7 microbit: added the minimal filesystem commands which are supported by the BBC micro:bit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7123
diff changeset
117
7059
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
118 def canStartFileManager(self):
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
119 """
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
120 Public method to determine, if a File Manager can be started.
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
121
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
122 @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
123 File Manager and a reason why it cannot.
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
124 @rtype tuple of (bool, str)
a8fad276cbd5 Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
125 """
7126
376deb7fefe7 microbit: added the minimal filesystem commands which are supported by the BBC micro:bit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7123
diff changeset
126 return True, ""
7123
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
127
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
128 def getWorkspace(self):
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
129 """
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
130 Public method to get the workspace directory.
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
131
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
132 @return workspace directory used for saving files
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
133 @rtype str
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
134 """
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
135 # Attempts to find the path on the filesystem that represents the
7551
b159c55ea6dd MicroPython: continued implementing support for the "Calliope mini".
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7549
diff changeset
136 # plugged in MICROBIT or MINI board.
b159c55ea6dd MicroPython: continued implementing support for the "Calliope mini".
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7549
diff changeset
137 if self.__deviceType == "bbc_microbit":
b159c55ea6dd MicroPython: continued implementing support for the "Calliope mini".
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7549
diff changeset
138 # BBC micro:bit
b159c55ea6dd MicroPython: continued implementing support for the "Calliope mini".
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7549
diff changeset
139 deviceDirectory = Utilities.findVolume("MICROBIT")
b159c55ea6dd MicroPython: continued implementing support for the "Calliope mini".
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7549
diff changeset
140 else:
b159c55ea6dd MicroPython: continued implementing support for the "Calliope mini".
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7549
diff changeset
141 # Calliope mini
b159c55ea6dd MicroPython: continued implementing support for the "Calliope mini".
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7549
diff changeset
142 deviceDirectory = Utilities.findVolume("MINI")
7123
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
143
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
144 if deviceDirectory:
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
145 return deviceDirectory
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
146 else:
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
147 # return the default workspace and give the user a warning
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
148 E5MessageBox.warning(
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
149 self.microPython,
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
150 self.tr("Workspace Directory"),
7551
b159c55ea6dd MicroPython: continued implementing support for the "Calliope mini".
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7549
diff changeset
151 self.tr("Could not find an attached {0}.\n\n"
7123
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
152 "Please make sure the device is plugged "
7551
b159c55ea6dd MicroPython: continued implementing support for the "Calliope mini".
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7549
diff changeset
153 "into this computer.").format(self.deviceName()))
7123
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
154
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
155 return super(MicrobitDevice, self).getWorkspace()
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
156
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
157 def hasTimeCommands(self):
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
158 """
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
159 Public method to check, if the device supports time commands.
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
160
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
161 The default returns True.
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
162
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
163 @return flag indicating support for time commands
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
164 @rtype bool
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
165 """
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
166 return False
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
167
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
168 def addDeviceMenuEntries(self, menu):
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
169 """
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
170 Public method to add device specific entries to the given menu.
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
171
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
172 @param menu reference to the context menu
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
173 @type QMenu
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
174 """
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
175 connected = self.microPython.isConnected()
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
176
8032
76375aa6bc04 Corrected the support code for the "BBC micro:bit" MicroPython device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
177 act = menu.addAction(self.tr("Flash MicroPython"),
7123
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
178 self.__flashMicroPython)
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
179 act.setEnabled(not connected)
8032
76375aa6bc04 Corrected the support code for the "BBC micro:bit" MicroPython device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
180 act = menu.addAction(self.tr("Flash Firmware"),
76375aa6bc04 Corrected the support code for the "BBC micro:bit" MicroPython device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
181 lambda: self.__flashMicroPython(firmware=True))
76375aa6bc04 Corrected the support code for the "BBC micro:bit" MicroPython device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
182 act.setEnabled(not connected)
7123
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
183 menu.addSeparator()
7299
a22b87b46128 MicrobitDevices: modified the MicroPython flashing routine and the saving of scripts to the device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
184 act = menu.addAction(self.tr("Save Script"), self.__saveScriptToDevice)
7123
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
185 act.setToolTip(self.tr(
7299
a22b87b46128 MicrobitDevices: modified the MicroPython flashing routine and the saving of scripts to the device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
186 "Save the current script to the selected device"))
a22b87b46128 MicrobitDevices: modified the MicroPython flashing routine and the saving of scripts to the device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
187 act.setEnabled(connected)
7123
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
188 act = menu.addAction(self.tr("Save Script as 'main.py'"),
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
189 self.__saveMain)
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
190 act.setToolTip(self.tr(
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
191 "Save the current script as 'main.py' on the connected device"))
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
192 act.setEnabled(connected)
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
193 menu.addSeparator()
7552
b62e73df71dd MicroPython: continued implementing support for the "Calliope mini".
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7551
diff changeset
194 act = menu.addAction(self.tr("Reset {0}").format(self.deviceName()),
b62e73df71dd MicroPython: continued implementing support for the "Calliope mini".
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7551
diff changeset
195 self.__resetDevice)
7123
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
196 act.setEnabled(connected)
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
197
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
198 @pyqtSlot()
8032
76375aa6bc04 Corrected the support code for the "BBC micro:bit" MicroPython device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
199 def __flashMicroPython(self, firmware=False):
7123
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
200 """
8032
76375aa6bc04 Corrected the support code for the "BBC micro:bit" MicroPython device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
201 Private slot to flash MicroPython or the DAPLink firmware to the
76375aa6bc04 Corrected the support code for the "BBC micro:bit" MicroPython device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
202 device.
76375aa6bc04 Corrected the support code for the "BBC micro:bit" MicroPython device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
203
76375aa6bc04 Corrected the support code for the "BBC micro:bit" MicroPython device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
204 @param firmware flag indicating to flash the DAPLink firmware
76375aa6bc04 Corrected the support code for the "BBC micro:bit" MicroPython device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
205 @type bool
76375aa6bc04 Corrected the support code for the "BBC micro:bit" MicroPython device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
206 """
76375aa6bc04 Corrected the support code for the "BBC micro:bit" MicroPython device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
207 # Attempts to find the path on the file system that represents the
76375aa6bc04 Corrected the support code for the "BBC micro:bit" MicroPython device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
208 # plugged in micro:bit board. To flash the DAPLink firmware, it must be
76375aa6bc04 Corrected the support code for the "BBC micro:bit" MicroPython device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
209 # in maintenance mode, for MicroPython in standard mode.
76375aa6bc04 Corrected the support code for the "BBC micro:bit" MicroPython device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
210 # The Calliope mini board must be in standard mode.
7552
b62e73df71dd MicroPython: continued implementing support for the "Calliope mini".
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7551
diff changeset
211 if self.__deviceType == "bbc_microbit":
b62e73df71dd MicroPython: continued implementing support for the "Calliope mini".
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7551
diff changeset
212 # BBC micro:bit
8032
76375aa6bc04 Corrected the support code for the "BBC micro:bit" MicroPython device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
213 if firmware:
76375aa6bc04 Corrected the support code for the "BBC micro:bit" MicroPython device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
214 deviceDirectory = Utilities.findVolume("MAINTENANCE")
76375aa6bc04 Corrected the support code for the "BBC micro:bit" MicroPython device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
215 else:
76375aa6bc04 Corrected the support code for the "BBC micro:bit" MicroPython device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
216 deviceDirectory = Utilities.findVolume("MICROBIT")
7552
b62e73df71dd MicroPython: continued implementing support for the "Calliope mini".
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7551
diff changeset
217 else:
b62e73df71dd MicroPython: continued implementing support for the "Calliope mini".
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7551
diff changeset
218 # Calliope mini
b62e73df71dd MicroPython: continued implementing support for the "Calliope mini".
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7551
diff changeset
219 deviceDirectory = Utilities.findVolume("MINI")
7299
a22b87b46128 MicrobitDevices: modified the MicroPython flashing routine and the saving of scripts to the device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
220 if not deviceDirectory:
7551
b159c55ea6dd MicroPython: continued implementing support for the "Calliope mini".
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7549
diff changeset
221 if self.__deviceType == "bbc_microbit":
b159c55ea6dd MicroPython: continued implementing support for the "Calliope mini".
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7549
diff changeset
222 # BBC micro:bit is not ready or not mounted
8032
76375aa6bc04 Corrected the support code for the "BBC micro:bit" MicroPython device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
223 if firmware:
76375aa6bc04 Corrected the support code for the "BBC micro:bit" MicroPython device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
224 E5MessageBox.critical(
76375aa6bc04 Corrected the support code for the "BBC micro:bit" MicroPython device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
225 self.microPython,
76375aa6bc04 Corrected the support code for the "BBC micro:bit" MicroPython device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
226 self.tr("Flash MicroPython/Firmware"),
76375aa6bc04 Corrected the support code for the "BBC micro:bit" MicroPython device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
227 self.tr(
76375aa6bc04 Corrected the support code for the "BBC micro:bit" MicroPython device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
228 '<p>The BBC micro:bit is not ready for flashing'
76375aa6bc04 Corrected the support code for the "BBC micro:bit" MicroPython device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
229 ' the DAPLink firmware. Follow these'
76375aa6bc04 Corrected the support code for the "BBC micro:bit" MicroPython device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
230 ' instructions. </p>'
76375aa6bc04 Corrected the support code for the "BBC micro:bit" MicroPython device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
231 '<ul>'
76375aa6bc04 Corrected the support code for the "BBC micro:bit" MicroPython device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
232 '<li>unplug USB cable and any batteries</li>'
76375aa6bc04 Corrected the support code for the "BBC micro:bit" MicroPython device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
233 '<li>keep RESET button pressed an plug USB cable'
76375aa6bc04 Corrected the support code for the "BBC micro:bit" MicroPython device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
234 ' back in</li>'
76375aa6bc04 Corrected the support code for the "BBC micro:bit" MicroPython device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
235 '<li>a drive called MAINTENANCE should be'
76375aa6bc04 Corrected the support code for the "BBC micro:bit" MicroPython device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
236 ' available</li>'
76375aa6bc04 Corrected the support code for the "BBC micro:bit" MicroPython device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
237 '</ul>'
76375aa6bc04 Corrected the support code for the "BBC micro:bit" MicroPython device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
238 '<p>See the '
76375aa6bc04 Corrected the support code for the "BBC micro:bit" MicroPython device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
239 '<a href="https://microbit.org/guide/firmware/">'
76375aa6bc04 Corrected the support code for the "BBC micro:bit" MicroPython device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
240 'micro:bit web site</a> for details.</p>'
76375aa6bc04 Corrected the support code for the "BBC micro:bit" MicroPython device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
241 )
76375aa6bc04 Corrected the support code for the "BBC micro:bit" MicroPython device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
242 )
76375aa6bc04 Corrected the support code for the "BBC micro:bit" MicroPython device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
243 else:
76375aa6bc04 Corrected the support code for the "BBC micro:bit" MicroPython device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
244 E5MessageBox.critical(
76375aa6bc04 Corrected the support code for the "BBC micro:bit" MicroPython device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
245 self.microPython,
76375aa6bc04 Corrected the support code for the "BBC micro:bit" MicroPython device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
246 self.tr("Flash MicroPython/Firmware"),
76375aa6bc04 Corrected the support code for the "BBC micro:bit" MicroPython device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
247 self.tr(
76375aa6bc04 Corrected the support code for the "BBC micro:bit" MicroPython device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
248 '<p>The BBC micro:bit is not ready for flashing'
76375aa6bc04 Corrected the support code for the "BBC micro:bit" MicroPython device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
249 ' the MicroPython firmware. Please make sure,'
76375aa6bc04 Corrected the support code for the "BBC micro:bit" MicroPython device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
250 ' that a drive called MICROBIT is available.'
76375aa6bc04 Corrected the support code for the "BBC micro:bit" MicroPython device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
251 '</p>'
76375aa6bc04 Corrected the support code for the "BBC micro:bit" MicroPython device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
252 )
76375aa6bc04 Corrected the support code for the "BBC micro:bit" MicroPython device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
253 )
7551
b159c55ea6dd MicroPython: continued implementing support for the "Calliope mini".
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7549
diff changeset
254 else:
b159c55ea6dd MicroPython: continued implementing support for the "Calliope mini".
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7549
diff changeset
255 # Calliope mini is not ready or not mounted
7552
b62e73df71dd MicroPython: continued implementing support for the "Calliope mini".
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7551
diff changeset
256 E5MessageBox.warning(
7551
b159c55ea6dd MicroPython: continued implementing support for the "Calliope mini".
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7549
diff changeset
257 self.microPython,
8032
76375aa6bc04 Corrected the support code for the "BBC micro:bit" MicroPython device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
258 self.tr("Flash MicroPython/Firmware"),
7552
b62e73df71dd MicroPython: continued implementing support for the "Calliope mini".
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7551
diff changeset
259 self.tr("Could not find an attached {0}.\n\n"
b62e73df71dd MicroPython: continued implementing support for the "Calliope mini".
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7551
diff changeset
260 "Please make sure the device is plugged "
b62e73df71dd MicroPython: continued implementing support for the "Calliope mini".
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7551
diff changeset
261 "into this computer.").format(self.deviceName()))
7299
a22b87b46128 MicrobitDevices: modified the MicroPython flashing routine and the saving of scripts to the device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
262 else:
a22b87b46128 MicrobitDevices: modified the MicroPython flashing routine and the saving of scripts to the device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
263 downloadsPath = QStandardPaths.standardLocations(
a22b87b46128 MicrobitDevices: modified the MicroPython flashing routine and the saving of scripts to the device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
264 QStandardPaths.DownloadLocation)[0]
a22b87b46128 MicrobitDevices: modified the MicroPython flashing routine and the saving of scripts to the device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
265 firmware = E5FileDialog.getOpenFileName(
7173
f611c3b7313f EspDevices, MicrobitDevices: fixed a few omissions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7161
diff changeset
266 self.microPython,
8032
76375aa6bc04 Corrected the support code for the "BBC micro:bit" MicroPython device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
267 self.tr("Flash MicroPython/Firmware"),
7299
a22b87b46128 MicrobitDevices: modified the MicroPython flashing routine and the saving of scripts to the device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
268 downloadsPath,
8032
76375aa6bc04 Corrected the support code for the "BBC micro:bit" MicroPython device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
269 self.tr("MicroPython/Firmware Files (*.hex);;All Files (*)"))
7299
a22b87b46128 MicrobitDevices: modified the MicroPython flashing routine and the saving of scripts to the device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
270 if firmware and os.path.exists(firmware):
a22b87b46128 MicrobitDevices: modified the MicroPython flashing routine and the saving of scripts to the device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
271 shutil.copy2(firmware, deviceDirectory)
7123
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
272
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
273 @pyqtSlot()
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
274 def __saveMain(self):
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
275 """
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
276 Private slot to copy the current script as 'main.py' onto the
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
277 connected device.
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
278 """
7299
a22b87b46128 MicrobitDevices: modified the MicroPython flashing routine and the saving of scripts to the device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
279 self.__saveScriptToDevice("main.py")
a22b87b46128 MicrobitDevices: modified the MicroPython flashing routine and the saving of scripts to the device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
280
a22b87b46128 MicrobitDevices: modified the MicroPython flashing routine and the saving of scripts to the device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
281 @pyqtSlot()
a22b87b46128 MicrobitDevices: modified the MicroPython flashing routine and the saving of scripts to the device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
282 def __saveScriptToDevice(self, scriptName=""):
a22b87b46128 MicrobitDevices: modified the MicroPython flashing routine and the saving of scripts to the device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
283 """
a22b87b46128 MicrobitDevices: modified the MicroPython flashing routine and the saving of scripts to the device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
284 Private method to save the current script onto the connected
a22b87b46128 MicrobitDevices: modified the MicroPython flashing routine and the saving of scripts to the device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
285 device.
a22b87b46128 MicrobitDevices: modified the MicroPython flashing routine and the saving of scripts to the device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
286
a22b87b46128 MicrobitDevices: modified the MicroPython flashing routine and the saving of scripts to the device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
287 @param scriptName name of the file on the device
a22b87b46128 MicrobitDevices: modified the MicroPython flashing routine and the saving of scripts to the device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
288 @type str
a22b87b46128 MicrobitDevices: modified the MicroPython flashing routine and the saving of scripts to the device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
289 """
7123
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
290 aw = e5App().getObject("ViewManager").activeWindow()
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
291 if not aw:
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
292 return
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
293
7299
a22b87b46128 MicrobitDevices: modified the MicroPython flashing routine and the saving of scripts to the device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
294 if scriptName:
a22b87b46128 MicrobitDevices: modified the MicroPython flashing routine and the saving of scripts to the device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
295 title = self.tr("Save Script as '{0}'").format(scriptName)
a22b87b46128 MicrobitDevices: modified the MicroPython flashing routine and the saving of scripts to the device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
296 else:
a22b87b46128 MicrobitDevices: modified the MicroPython flashing routine and the saving of scripts to the device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
297 title = self.tr("Save Script")
a22b87b46128 MicrobitDevices: modified the MicroPython flashing routine and the saving of scripts to the device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
298
7186
ccd55666e9d2 Utilities, MicrobitDevices: added MicroPython to the known Python Variants.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7173
diff changeset
299 if not (aw.isPyFile() or aw.isMicroPythonFile()):
7123
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
300 yes = E5MessageBox.yesNo(
7173
f611c3b7313f EspDevices, MicrobitDevices: fixed a few omissions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7161
diff changeset
301 self.microPython,
7299
a22b87b46128 MicrobitDevices: modified the MicroPython flashing routine and the saving of scripts to the device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
302 title,
7123
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
303 self.tr("""The current editor does not contain a Python"""
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
304 """ script. Write it anyway?"""))
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
305 if not yes:
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
306 return
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
307
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
308 script = aw.text().strip()
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
309 if not script:
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
310 E5MessageBox.warning(
7173
f611c3b7313f EspDevices, MicrobitDevices: fixed a few omissions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7161
diff changeset
311 self.microPython,
7299
a22b87b46128 MicrobitDevices: modified the MicroPython flashing routine and the saving of scripts to the device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
312 title,
7123
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
313 self.tr("""The script is empty. Aborting."""))
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
314 return
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
315
7299
a22b87b46128 MicrobitDevices: modified the MicroPython flashing routine and the saving of scripts to the device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
316 if not scriptName:
a22b87b46128 MicrobitDevices: modified the MicroPython flashing routine and the saving of scripts to the device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
317 scriptName = os.path.basename(aw.getFileName())
a22b87b46128 MicrobitDevices: modified the MicroPython flashing routine and the saving of scripts to the device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
318 scriptName, ok = QInputDialog.getText(
a22b87b46128 MicrobitDevices: modified the MicroPython flashing routine and the saving of scripts to the device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
319 self.microPython,
a22b87b46128 MicrobitDevices: modified the MicroPython flashing routine and the saving of scripts to the device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
320 title,
a22b87b46128 MicrobitDevices: modified the MicroPython flashing routine and the saving of scripts to the device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
321 self.tr("Enter a file name on the device:"),
a22b87b46128 MicrobitDevices: modified the MicroPython flashing routine and the saving of scripts to the device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
322 QLineEdit.Normal,
a22b87b46128 MicrobitDevices: modified the MicroPython flashing routine and the saving of scripts to the device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
323 scriptName)
a22b87b46128 MicrobitDevices: modified the MicroPython flashing routine and the saving of scripts to the device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
324 if not ok or not bool(scriptName):
a22b87b46128 MicrobitDevices: modified the MicroPython flashing routine and the saving of scripts to the device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
325 return
a22b87b46128 MicrobitDevices: modified the MicroPython flashing routine and the saving of scripts to the device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
326
a22b87b46128 MicrobitDevices: modified the MicroPython flashing routine and the saving of scripts to the device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
327 title = self.tr("Save Script as '{0}'").format(scriptName)
a22b87b46128 MicrobitDevices: modified the MicroPython flashing routine and the saving of scripts to the device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
328
7123
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
329 commands = [
7299
a22b87b46128 MicrobitDevices: modified the MicroPython flashing routine and the saving of scripts to the device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
330 "fd = open('{0}', 'wb')".format(scriptName),
7123
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
331 "f = fd.write",
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
332 ]
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
333 for line in script.splitlines():
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
334 commands.append("f(" + repr(line + "\n") + ")")
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
335 commands.append("fd.close()")
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
336 out, err = self.microPython.commandsInterface().execute(commands)
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
337 if err:
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
338 E5MessageBox.critical(
7173
f611c3b7313f EspDevices, MicrobitDevices: fixed a few omissions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7161
diff changeset
339 self.microPython,
7299
a22b87b46128 MicrobitDevices: modified the MicroPython flashing routine and the saving of scripts to the device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
340 title,
7123
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
341 self.tr("""<p>The script could not be saved to the"""
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
342 """ device.</p><p>Reason: {0}</p>""")
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
343 .format(err.decode("utf-8")))
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
344
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
345 # reset the device
7299
a22b87b46128 MicrobitDevices: modified the MicroPython flashing routine and the saving of scripts to the device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
346 self.__resetDevice()
7123
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
347
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
348 @pyqtSlot()
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
349 def __resetDevice(self):
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
350 """
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
351 Private slot to reset the connected device.
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
352 """
7551
b159c55ea6dd MicroPython: continued implementing support for the "Calliope mini".
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7549
diff changeset
353 if self.__deviceType == "bbc_microbit":
b159c55ea6dd MicroPython: continued implementing support for the "Calliope mini".
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7549
diff changeset
354 # BBC micro:bit
b159c55ea6dd MicroPython: continued implementing support for the "Calliope mini".
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7549
diff changeset
355 self.microPython.commandsInterface().execute([
b159c55ea6dd MicroPython: continued implementing support for the "Calliope mini".
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7549
diff changeset
356 "import microbit",
b159c55ea6dd MicroPython: continued implementing support for the "Calliope mini".
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7549
diff changeset
357 "microbit.reset()",
b159c55ea6dd MicroPython: continued implementing support for the "Calliope mini".
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7549
diff changeset
358 ])
b159c55ea6dd MicroPython: continued implementing support for the "Calliope mini".
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7549
diff changeset
359 else:
b159c55ea6dd MicroPython: continued implementing support for the "Calliope mini".
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7549
diff changeset
360 # Calliope mini
b159c55ea6dd MicroPython: continued implementing support for the "Calliope mini".
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7549
diff changeset
361 self.microPython.commandsInterface().execute([
b159c55ea6dd MicroPython: continued implementing support for the "Calliope mini".
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7549
diff changeset
362 "import calliope_mini",
b159c55ea6dd MicroPython: continued implementing support for the "Calliope mini".
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7549
diff changeset
363 "calliope_mini.reset()",
b159c55ea6dd MicroPython: continued implementing support for the "Calliope mini".
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7549
diff changeset
364 ])
7123
94948e2aa0a5 Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7114
diff changeset
365
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
366 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
367 """
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
368 Public method to get the device documentation URL.
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
369
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
370 @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
371 @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
372 """
7549
fcfbb9e94471 MicroPython: continued implementing support for the "Calliope mini".
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7548
diff changeset
373 if self.__deviceType == "bbc_microbit":
fcfbb9e94471 MicroPython: continued implementing support for the "Calliope mini".
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7548
diff changeset
374 # BBC micro:bit
fcfbb9e94471 MicroPython: continued implementing support for the "Calliope mini".
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7548
diff changeset
375 return Preferences.getMicroPython("MicrobitDocuUrl")
fcfbb9e94471 MicroPython: continued implementing support for the "Calliope mini".
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7548
diff changeset
376 else:
fcfbb9e94471 MicroPython: continued implementing support for the "Calliope mini".
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7548
diff changeset
377 # Calliope mini
fcfbb9e94471 MicroPython: continued implementing support for the "Calliope mini".
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7548
diff changeset
378 return Preferences.getMicroPython("CalliopeDocuUrl")
7328
e2d85ef3fadb MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7299
diff changeset
379
e2d85ef3fadb MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7299
diff changeset
380 def getFirmwareUrl(self):
e2d85ef3fadb MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7299
diff changeset
381 """
e2d85ef3fadb MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7299
diff changeset
382 Public method to get the device firmware download URL.
e2d85ef3fadb MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7299
diff changeset
383
e2d85ef3fadb MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7299
diff changeset
384 @return firmware download URL of the device
e2d85ef3fadb MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7299
diff changeset
385 @rtype str
e2d85ef3fadb MicroPython:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7299
diff changeset
386 """
7549
fcfbb9e94471 MicroPython: continued implementing support for the "Calliope mini".
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7548
diff changeset
387 if self.__deviceType == "bbc_microbit":
fcfbb9e94471 MicroPython: continued implementing support for the "Calliope mini".
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7548
diff changeset
388 # BBC micro:bit
fcfbb9e94471 MicroPython: continued implementing support for the "Calliope mini".
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7548
diff changeset
389 return Preferences.getMicroPython("MicrobitFirmwareUrl")
fcfbb9e94471 MicroPython: continued implementing support for the "Calliope mini".
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7548
diff changeset
390 else:
fcfbb9e94471 MicroPython: continued implementing support for the "Calliope mini".
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7548
diff changeset
391 # Calliope mini
fcfbb9e94471 MicroPython: continued implementing support for the "Calliope mini".
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7548
diff changeset
392 return Preferences.getMicroPython("CalliopeFirmwareUrl")

eric ide

mercurial