67 Public method to get the name of the device. |
67 Public method to get the name of the device. |
68 |
68 |
69 @return name of the device |
69 @return name of the device |
70 @rtype str |
70 @rtype str |
71 """ |
71 """ |
72 # TODO: extend this to support Calliope mini |
72 if self.__deviceType == "bbc_microbit": |
73 return self.tr("BBC micro:bit") |
73 # BBC micro:bit |
|
74 return self.tr("BBC micro:bit") |
|
75 else: |
|
76 # Calliope mini |
|
77 return self.tr("Calliope mini") |
74 |
78 |
75 def canStartRepl(self): |
79 def canStartRepl(self): |
76 """ |
80 """ |
77 Public method to determine, if a REPL can be started. |
81 Public method to determine, if a REPL can be started. |
78 |
82 |
127 Public method to get the workspace directory. |
131 Public method to get the workspace directory. |
128 |
132 |
129 @return workspace directory used for saving files |
133 @return workspace directory used for saving files |
130 @rtype str |
134 @rtype str |
131 """ |
135 """ |
132 # TODO: extend this to support Calliope mini |
|
133 # Attempts to find the path on the filesystem that represents the |
136 # Attempts to find the path on the filesystem that represents the |
134 # plugged in MICROBIT board. |
137 # plugged in MICROBIT or MINI board. |
135 deviceDirectory = Utilities.findVolume("MICROBIT") |
138 if self.__deviceType == "bbc_microbit": |
|
139 # BBC micro:bit |
|
140 deviceDirectory = Utilities.findVolume("MICROBIT") |
|
141 else: |
|
142 # Calliope mini |
|
143 deviceDirectory = Utilities.findVolume("MINI") |
136 |
144 |
137 if deviceDirectory: |
145 if deviceDirectory: |
138 return deviceDirectory |
146 return deviceDirectory |
139 else: |
147 else: |
140 # return the default workspace and give the user a warning |
148 # return the default workspace and give the user a warning |
141 # TODO: extend this to support Calliope mini |
|
142 E5MessageBox.warning( |
149 E5MessageBox.warning( |
143 self.microPython, |
150 self.microPython, |
144 self.tr("Workspace Directory"), |
151 self.tr("Workspace Directory"), |
145 self.tr("Could not find an attached BBC micro:bit.\n\n" |
152 self.tr("Could not find an attached {0}.\n\n" |
146 "Please make sure the device is plugged " |
153 "Please make sure the device is plugged " |
147 "into this computer.")) |
154 "into this computer.").format(self.deviceName())) |
148 |
155 |
149 return super(MicrobitDevice, self).getWorkspace() |
156 return super(MicrobitDevice, self).getWorkspace() |
150 |
157 |
151 def hasTimeCommands(self): |
158 def hasTimeCommands(self): |
152 """ |
159 """ |
192 """ |
199 """ |
193 # Attempts to find the path on the filesystem that represents the |
200 # Attempts to find the path on the filesystem that represents the |
194 # plugged in micro:bit board in maintenance mode. |
201 # plugged in micro:bit board in maintenance mode. |
195 deviceDirectory = Utilities.findVolume("MAINTENANCE") |
202 deviceDirectory = Utilities.findVolume("MAINTENANCE") |
196 if not deviceDirectory: |
203 if not deviceDirectory: |
197 # TODO: extend this to support Calliope mini |
204 if self.__deviceType == "bbc_microbit": |
198 # BBC micro:bit is not ready or not mounted |
205 # BBC micro:bit is not ready or not mounted |
199 E5MessageBox.critical( |
206 E5MessageBox.critical( |
200 self.microPython, |
207 self.microPython, |
201 self.tr("Flash MicroPython Firmware"), |
208 self.tr("Flash MicroPython Firmware"), |
202 self.tr( |
209 self.tr( |
203 '<p>The BBC micro:bit is not ready for flashing. Follow' |
210 '<p>The BBC micro:bit is not ready for flashing.' |
204 ' these instructions.</p>' |
211 ' Follow these instructions.</p>' |
205 '<ul>' |
212 '<ul>' |
206 '<li>unplug USB cable and any batteries</li>' |
213 '<li>unplug USB cable and any batteries</li>' |
207 '<li>keep RESET pressed an plug USB cable back in</li>' |
214 '<li>keep RESET button pressed an plug USB cable back' |
208 '<li>a drive called MAINTENANCE should be available</li>' |
215 ' in</li>' |
209 '</ul>' |
216 '<li>a drive called MAINTENANCE should be available' |
210 '<p>See the ' |
217 '</li>' |
211 '<a href="https://microbit.org/guide/firmware/">' |
218 '</ul>' |
212 'micro:bit web site</a> for details.</p>' |
219 '<p>See the ' |
213 )) |
220 '<a href="https://microbit.org/guide/firmware/">' |
|
221 'micro:bit web site</a> for details.</p>' |
|
222 )) |
|
223 else: |
|
224 # Calliope mini is not ready or not mounted |
|
225 E5MessageBox.critical( |
|
226 self.microPython, |
|
227 self.tr("Flash MicroPython Firmware"), |
|
228 self.tr( |
|
229 '<p>The Calliope mini is not ready for flashing.' |
|
230 ' Follow these instructions.</p>' |
|
231 '<ul>' |
|
232 '<li>unplug USB cable and any batteries</li>' |
|
233 '<li>keep RESET button pressed an plug USB cable back' |
|
234 ' in</li>' |
|
235 '<li>a drive called MAINTENANCE should be available' |
|
236 '</li>' |
|
237 '</ul>' |
|
238 )) |
214 else: |
239 else: |
215 downloadsPath = QStandardPaths.standardLocations( |
240 downloadsPath = QStandardPaths.standardLocations( |
216 QStandardPaths.DownloadLocation)[0] |
241 QStandardPaths.DownloadLocation)[0] |
217 firmware = E5FileDialog.getOpenFileName( |
242 firmware = E5FileDialog.getOpenFileName( |
218 self.microPython, |
243 self.microPython, |
300 @pyqtSlot() |
325 @pyqtSlot() |
301 def __resetDevice(self): |
326 def __resetDevice(self): |
302 """ |
327 """ |
303 Private slot to reset the connected device. |
328 Private slot to reset the connected device. |
304 """ |
329 """ |
305 # TODO: extend this to support Calliope mini |
330 if self.__deviceType == "bbc_microbit": |
306 self.microPython.commandsInterface().execute([ |
331 # BBC micro:bit |
307 "import microbit", |
332 self.microPython.commandsInterface().execute([ |
308 "microbit.reset()", |
333 "import microbit", |
309 ]) |
334 "microbit.reset()", |
|
335 ]) |
|
336 else: |
|
337 # TODO: try this branch with a Calliope mini |
|
338 # Calliope mini |
|
339 self.microPython.commandsInterface().execute([ |
|
340 "import calliope_mini", |
|
341 "calliope_mini.reset()", |
|
342 ]) |
310 |
343 |
311 def getDocumentationUrl(self): |
344 def getDocumentationUrl(self): |
312 """ |
345 """ |
313 Public method to get the device documentation URL. |
346 Public method to get the device documentation URL. |
314 |
347 |