eric6/MicroPython/MicrobitDevices.py

changeset 7549
fcfbb9e94471
parent 7548
e1c6a2e32a38
child 7551
b159c55ea6dd
equal deleted inserted replaced
7548:e1c6a2e32a38 7549:fcfbb9e94471
2 2
3 # Copyright (c) 2019 - 2020 Detlev Offenbach <detlev@die-offenbachs.de> 3 # Copyright (c) 2019 - 2020 Detlev Offenbach <detlev@die-offenbachs.de>
4 # 4 #
5 5
6 """ 6 """
7 Module implementing the device interface class for BBC micro:bit boards. 7 Module implementing the device interface class for BBC micro:bit and
8 Calliope mini boards.
8 """ 9 """
9 10
10 11
11 import os 12 import os
12 import shutil 13 import shutil
24 import Preferences 25 import Preferences
25 26
26 27
27 class MicrobitDevice(MicroPythonDevice): 28 class MicrobitDevice(MicroPythonDevice):
28 """ 29 """
29 Class implementing the device for BBC micro:bit boards. 30 Class implementing the device for BBC micro:bit and Calliope mini boards.
30 """ 31 """
31 def __init__(self, microPythonWidget, parent=None): 32 def __init__(self, microPythonWidget, deviceType, parent=None):
32 """ 33 """
33 Constructor 34 Constructor
34 35
35 @param microPythonWidget reference to the main MicroPython widget 36 @param microPythonWidget reference to the main MicroPython widget
36 @type MicroPythonWidget 37 @type MicroPythonWidget
38 @param deviceType type of the device
39 @type str
37 @param parent reference to the parent object 40 @param parent reference to the parent object
38 @type QObject 41 @type QObject
39 """ 42 """
40 super(MicrobitDevice, self).__init__(microPythonWidget, parent) 43 super(MicrobitDevice, self).__init__(microPythonWidget, parent)
44
45 self.__deviceType = deviceType
41 46
42 def setButtons(self): 47 def setButtons(self):
43 """ 48 """
44 Public method to enable the supported action buttons. 49 Public method to enable the supported action buttons.
45 """ 50 """
62 Public method to get the name of the device. 67 Public method to get the name of the device.
63 68
64 @return name of the device 69 @return name of the device
65 @rtype str 70 @rtype str
66 """ 71 """
72 # TODO: extend this to support Calliope mini
67 return self.tr("BBC micro:bit") 73 return self.tr("BBC micro:bit")
68 74
69 def canStartRepl(self): 75 def canStartRepl(self):
70 """ 76 """
71 Public method to determine, if a REPL can be started. 77 Public method to determine, if a REPL can be started.
121 Public method to get the workspace directory. 127 Public method to get the workspace directory.
122 128
123 @return workspace directory used for saving files 129 @return workspace directory used for saving files
124 @rtype str 130 @rtype str
125 """ 131 """
132 # TODO: extend this to support Calliope mini
126 # Attempts to find the path on the filesystem that represents the 133 # Attempts to find the path on the filesystem that represents the
127 # plugged in MICROBIT board. 134 # plugged in MICROBIT board.
128 deviceDirectory = Utilities.findVolume("MICROBIT") 135 deviceDirectory = Utilities.findVolume("MICROBIT")
129 136
130 if deviceDirectory: 137 if deviceDirectory:
131 return deviceDirectory 138 return deviceDirectory
132 else: 139 else:
133 # return the default workspace and give the user a warning 140 # return the default workspace and give the user a warning
141 # TODO: extend this to support Calliope mini
134 E5MessageBox.warning( 142 E5MessageBox.warning(
135 self.microPython, 143 self.microPython,
136 self.tr("Workspace Directory"), 144 self.tr("Workspace Directory"),
137 self.tr("Could not find an attached BBC micro:bit.\n\n" 145 self.tr("Could not find an attached BBC micro:bit.\n\n"
138 "Please make sure the device is plugged " 146 "Please make sure the device is plugged "
184 """ 192 """
185 # Attempts to find the path on the filesystem that represents the 193 # Attempts to find the path on the filesystem that represents the
186 # plugged in micro:bit board in maintenance mode. 194 # plugged in micro:bit board in maintenance mode.
187 deviceDirectory = Utilities.findVolume("MAINTENANCE") 195 deviceDirectory = Utilities.findVolume("MAINTENANCE")
188 if not deviceDirectory: 196 if not deviceDirectory:
197 # TODO: extend this to support Calliope mini
189 # BBC micro:bit is not ready or not mounted 198 # BBC micro:bit is not ready or not mounted
190 E5MessageBox.critical( 199 E5MessageBox.critical(
191 self.microPython, 200 self.microPython,
192 self.tr("Flash MicroPython Firmware"), 201 self.tr("Flash MicroPython Firmware"),
193 self.tr( 202 self.tr(
291 @pyqtSlot() 300 @pyqtSlot()
292 def __resetDevice(self): 301 def __resetDevice(self):
293 """ 302 """
294 Private slot to reset the connected device. 303 Private slot to reset the connected device.
295 """ 304 """
305 # TODO: extend this to support Calliope mini
296 self.microPython.commandsInterface().execute([ 306 self.microPython.commandsInterface().execute([
297 "import microbit", 307 "import microbit",
298 "microbit.reset()", 308 "microbit.reset()",
299 ]) 309 ])
300 310
303 Public method to get the device documentation URL. 313 Public method to get the device documentation URL.
304 314
305 @return documentation URL of the device 315 @return documentation URL of the device
306 @rtype str 316 @rtype str
307 """ 317 """
308 return Preferences.getMicroPython("MicrobitDocuUrl") 318 if self.__deviceType == "bbc_microbit":
319 # BBC micro:bit
320 return Preferences.getMicroPython("MicrobitDocuUrl")
321 else:
322 # Calliope mini
323 return Preferences.getMicroPython("CalliopeDocuUrl")
309 324
310 def getFirmwareUrl(self): 325 def getFirmwareUrl(self):
311 """ 326 """
312 Public method to get the device firmware download URL. 327 Public method to get the device firmware download URL.
313 328
314 @return firmware download URL of the device 329 @return firmware download URL of the device
315 @rtype str 330 @rtype str
316 """ 331 """
317 return Preferences.getMicroPython("MicrobitFirmwareUrl") 332 if self.__deviceType == "bbc_microbit":
333 # BBC micro:bit
334 return Preferences.getMicroPython("MicrobitFirmwareUrl")
335 else:
336 # Calliope mini
337 return Preferences.getMicroPython("CalliopeFirmwareUrl")

eric ide

mercurial