Mon, 24 Mar 2025 14:16:32 +0100
Corrected some code in the MicrobitDevices module related to CircuitPython.
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 | |
11090
f5f5f5803935
Updated copyright for 2025.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11034
diff
changeset
|
3 | # Copyright (c) 2019 - 2025 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 | |
9765
6378da868bb0
Reorganized the MicroPython code even more.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
11 | import ast |
9751
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9750
diff
changeset
|
12 | import contextlib |
7123
94948e2aa0a5
Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7114
diff
changeset
|
13 | 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
|
14 | import shutil |
7123
94948e2aa0a5
Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7114
diff
changeset
|
15 | |
9749 | 16 | from PyQt6.QtCore import QStandardPaths, QUrl, pyqtSlot |
9820 | 17 | from PyQt6.QtNetwork import QNetworkReply, QNetworkRequest |
9766
f0e22f3a5878
Fixed a few issue introduced during the recent changes to the MicroPython package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9765
diff
changeset
|
18 | from PyQt6.QtWidgets import QMenu |
7123
94948e2aa0a5
Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7114
diff
changeset
|
19 | |
10806
2f6df822e3b9
Moved some functions to the EricUtilities package for consistency and adapted the code base accordingly.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10683
diff
changeset
|
20 | from eric7 import EricUtilities, Preferences |
9473
3f23dbf37dbe
Resorted the import statements using isort.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9413
diff
changeset
|
21 | from eric7.EricWidgets import EricFileDialog, EricMessageBox |
3f23dbf37dbe
Resorted the import statements using isort.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9413
diff
changeset
|
22 | from eric7.EricWidgets.EricApplication import ericApp |
9624
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9576
diff
changeset
|
23 | from eric7.SystemUtilities import FileSystemUtilities |
9473
3f23dbf37dbe
Resorted the import statements using isort.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9413
diff
changeset
|
24 | |
9765
6378da868bb0
Reorganized the MicroPython code even more.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
25 | from ..MicroPythonWidget import HAS_QTCHART |
9756
9854647c8c5c
Reorganized the MicroPython package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9752
diff
changeset
|
26 | from . import FirmwareGithubUrls |
9854647c8c5c
Reorganized the MicroPython package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9752
diff
changeset
|
27 | from .DeviceBase import BaseDevice |
7059
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
28 | |
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
29 | |
9756
9854647c8c5c
Reorganized the MicroPython package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9752
diff
changeset
|
30 | class MicrobitDevice(BaseDevice): |
7059
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
31 | """ |
7549
fcfbb9e94471
MicroPython: continued implementing support for the "Calliope mini".
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7548
diff
changeset
|
32 | 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
|
33 | """ |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
34 | |
9751
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9750
diff
changeset
|
35 | def __init__(self, microPythonWidget, deviceType, serialNumber, parent=None): |
7059
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
36 | """ |
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
37 | Constructor |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
38 | |
7059
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
39 | @param microPythonWidget reference to the main MicroPython widget |
7134
21d23ca51680
Renamed "MicroPythonReplWidget" to "MicroPythonWidget".
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7126
diff
changeset
|
40 | @type MicroPythonWidget |
7549
fcfbb9e94471
MicroPython: continued implementing support for the "Calliope mini".
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7548
diff
changeset
|
41 | @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
|
42 | @type str |
9751
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9750
diff
changeset
|
43 | @param serialNumber serial number of the board |
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9750
diff
changeset
|
44 | @type str |
7059
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
45 | @param parent reference to the parent object |
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
46 | @type QObject |
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
47 | """ |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
48 | super().__init__(microPythonWidget, deviceType, parent) |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
49 | |
9751
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9750
diff
changeset
|
50 | self.__boardId = 0 # illegal ID |
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9750
diff
changeset
|
51 | if serialNumber: |
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9750
diff
changeset
|
52 | with contextlib.suppress(ValueError): |
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9750
diff
changeset
|
53 | self.__boardId = int(serialNumber[:4], 16) |
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9750
diff
changeset
|
54 | |
9752
2b9546c0cbd9
Moved the MicroPython board specific functions to a separate submenu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9751
diff
changeset
|
55 | self.__createMicrobitMenu() |
2b9546c0cbd9
Moved the MicroPython board specific functions to a separate submenu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9751
diff
changeset
|
56 | |
9864 | 57 | self.__bleAddressType = { |
58 | 0: self.tr("Public"), | |
59 | 1: self.tr("Random Static"), | |
60 | 2: self.tr("Random Private Resolvable"), | |
61 | 3: self.tr("Random Private Non-Resolvable"), | |
62 | } | |
63 | ||
9803 | 64 | def setConnected(self, connected): |
65 | """ | |
66 | Public method to set the connection state. | |
67 | ||
68 | Note: This method can be overwritten to perform actions upon connect | |
69 | or disconnect of the device. | |
70 | ||
71 | @param connected connection state | |
72 | @type bool | |
73 | """ | |
74 | super().setConnected(connected) | |
75 | ||
11177
f511038a0061
Corrected some issues related to controllers with small RAM and limited numbers support (i.e. BBC micro:bit and Calliope mini).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11167
diff
changeset
|
76 | if self._deviceData: |
f511038a0061
Corrected some issues related to controllers with small RAM and limited numbers support (i.e. BBC micro:bit and Calliope mini).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11167
diff
changeset
|
77 | self._deviceData["local_mip"] = False |
9979 | 78 | |
7059
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
79 | def setButtons(self): |
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
80 | """ |
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
81 | Public method to enable the supported action buttons. |
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
82 | """ |
8218
7c09585bd960
Applied some more code simplifications suggested by the new Simplify checker (super(Foo, self) => super()).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8143
diff
changeset
|
83 | super().setButtons() |
9763
52f982c08301
Removed the 'Open' and 'Save' buttons from the MicroPython widget and made the repl and file manager start automatically upon connecting to the selected device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9756
diff
changeset
|
84 | |
7059
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
85 | self.microPython.setActionButtons( |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
86 | run=True, repl=True, files=True, chart=HAS_QTCHART |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
87 | ) |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
88 | |
7059
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
89 | def forceInterrupt(self): |
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
90 | """ |
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
91 | 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
|
92 | serial connection. |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
93 | |
7059
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
94 | @return flag indicating an interrupt is needed |
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
95 | @rtype bool |
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
96 | """ |
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
97 | return True |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
98 | |
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
|
99 | 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
|
100 | """ |
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 | Public method to get the name of the device. |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
102 | |
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
|
103 | @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
|
104 | @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
|
105 | """ |
8117
aaa5e0eacd4e
MicroPython: changed the logic to synchronize the time because some devices don't implement long integer and failed defining the 'set_time()' function.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8096
diff
changeset
|
106 | if self.getDeviceType() == "bbc_microbit": |
7551
b159c55ea6dd
MicroPython: continued implementing support for the "Calliope mini".
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7549
diff
changeset
|
107 | # BBC micro:bit |
b159c55ea6dd
MicroPython: continued implementing support for the "Calliope mini".
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7549
diff
changeset
|
108 | 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
|
109 | else: |
b159c55ea6dd
MicroPython: continued implementing support for the "Calliope mini".
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7549
diff
changeset
|
110 | # Calliope mini |
b159c55ea6dd
MicroPython: continued implementing support for the "Calliope mini".
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7549
diff
changeset
|
111 | return self.tr("Calliope mini") |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
112 | |
7059
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
113 | def canStartRepl(self): |
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
114 | """ |
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
115 | Public method to determine, if a REPL can be started. |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
116 | |
7059
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
117 | @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
|
118 | and a reason why it cannot. |
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
119 | @rtype tuple of (bool, str) |
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
120 | """ |
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
|
121 | return True, "" |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
122 | |
7059
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
123 | def canStartPlotter(self): |
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
124 | """ |
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
125 | Public method to determine, if a Plotter can be started. |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
126 | |
7059
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
127 | @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
|
128 | Plotter and a reason why it cannot. |
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
129 | @rtype tuple of (bool, str) |
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
130 | """ |
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
|
131 | return True, "" |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
132 | |
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
|
133 | 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
|
134 | """ |
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
|
135 | Public method to determine, if a script can be executed. |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
136 | |
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
|
137 | @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
|
138 | 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
|
139 | @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
|
140 | """ |
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
|
141 | return True, "" |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
142 | |
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
|
143 | 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
|
144 | """ |
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
|
145 | Public method to run the given Python script. |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
146 | |
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
|
147 | @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
|
148 | @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
|
149 | """ |
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
|
150 | 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
|
151 | self.sendCommands(pythonScript) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
152 | |
7059
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
153 | def canStartFileManager(self): |
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
154 | """ |
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
155 | Public method to determine, if a File Manager can be started. |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
156 | |
7059
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
157 | @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
|
158 | File Manager and a reason why it cannot. |
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
159 | @rtype tuple of (bool, str) |
a8fad276cbd5
Continued implementing the MicroPython support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
160 | """ |
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
|
161 | return True, "" |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
162 | |
7123
94948e2aa0a5
Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7114
diff
changeset
|
163 | def hasTimeCommands(self): |
94948e2aa0a5
Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7114
diff
changeset
|
164 | """ |
94948e2aa0a5
Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7114
diff
changeset
|
165 | Public method to check, if the device supports time commands. |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
166 | |
7123
94948e2aa0a5
Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7114
diff
changeset
|
167 | The default returns True. |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
168 | |
7123
94948e2aa0a5
Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7114
diff
changeset
|
169 | @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
|
170 | @rtype bool |
94948e2aa0a5
Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7114
diff
changeset
|
171 | """ |
9766
f0e22f3a5878
Fixed a few issue introduced during the recent changes to the MicroPython package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9765
diff
changeset
|
172 | if self.microPython.isConnected() and self.hasCircuitPython(): |
9751
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9750
diff
changeset
|
173 | return True |
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9750
diff
changeset
|
174 | |
7123
94948e2aa0a5
Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7114
diff
changeset
|
175 | return False |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
176 | |
9751
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9750
diff
changeset
|
177 | def __isMicroBitV1(self): |
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9750
diff
changeset
|
178 | """ |
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9750
diff
changeset
|
179 | Private method to check, if the device is a BBC micro:bit v1. |
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9750
diff
changeset
|
180 | |
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9750
diff
changeset
|
181 | @return falg indicating a BBC micro:bit v1 |
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9750
diff
changeset
|
182 | @rtype bool |
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9750
diff
changeset
|
183 | """ |
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9750
diff
changeset
|
184 | return self.__boardId in (0x9900, 0x9901) |
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9750
diff
changeset
|
185 | |
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9750
diff
changeset
|
186 | def __isMicroBitV2(self): |
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9750
diff
changeset
|
187 | """ |
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9750
diff
changeset
|
188 | Private method to check, if the device is a BBC micro:bit v2. |
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9750
diff
changeset
|
189 | |
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9750
diff
changeset
|
190 | @return falg indicating a BBC micro:bit v2 |
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9750
diff
changeset
|
191 | @rtype bool |
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9750
diff
changeset
|
192 | """ |
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9750
diff
changeset
|
193 | return self.__boardId in (0x9903, 0x9904, 0x9905, 0x9906) |
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9750
diff
changeset
|
194 | |
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9750
diff
changeset
|
195 | def __isCalliope(self): |
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9750
diff
changeset
|
196 | """ |
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9750
diff
changeset
|
197 | Private method to check, if the device is a Calliope mini. |
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9750
diff
changeset
|
198 | |
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9750
diff
changeset
|
199 | @return flag indicating a Calliope mini |
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9750
diff
changeset
|
200 | @rtype bool |
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9750
diff
changeset
|
201 | """ |
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9750
diff
changeset
|
202 | return self.__boardId in (0x12A0,) |
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9750
diff
changeset
|
203 | |
9752
2b9546c0cbd9
Moved the MicroPython board specific functions to a separate submenu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9751
diff
changeset
|
204 | def __createMicrobitMenu(self): |
2b9546c0cbd9
Moved the MicroPython board specific functions to a separate submenu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9751
diff
changeset
|
205 | """ |
2b9546c0cbd9
Moved the MicroPython board specific functions to a separate submenu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9751
diff
changeset
|
206 | Private method to create the microbit submenu. |
2b9546c0cbd9
Moved the MicroPython board specific functions to a separate submenu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9751
diff
changeset
|
207 | """ |
2b9546c0cbd9
Moved the MicroPython board specific functions to a separate submenu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9751
diff
changeset
|
208 | self.__microbitMenu = QMenu(self.tr("BBC micro:bit/Calliope Functions")) |
2b9546c0cbd9
Moved the MicroPython board specific functions to a separate submenu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9751
diff
changeset
|
209 | |
2b9546c0cbd9
Moved the MicroPython board specific functions to a separate submenu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9751
diff
changeset
|
210 | self.__showMpyAct = self.__microbitMenu.addAction( |
2b9546c0cbd9
Moved the MicroPython board specific functions to a separate submenu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9751
diff
changeset
|
211 | self.tr("Show MicroPython Versions"), self.__showFirmwareVersions |
2b9546c0cbd9
Moved the MicroPython board specific functions to a separate submenu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9751
diff
changeset
|
212 | ) |
2b9546c0cbd9
Moved the MicroPython board specific functions to a separate submenu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9751
diff
changeset
|
213 | self.__microbitMenu.addSeparator() |
2b9546c0cbd9
Moved the MicroPython board specific functions to a separate submenu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9751
diff
changeset
|
214 | self.__flashMpyAct = self.__microbitMenu.addAction( |
2b9546c0cbd9
Moved the MicroPython board specific functions to a separate submenu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9751
diff
changeset
|
215 | self.tr("Flash MicroPython"), self.__flashMicroPython |
2b9546c0cbd9
Moved the MicroPython board specific functions to a separate submenu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9751
diff
changeset
|
216 | ) |
2b9546c0cbd9
Moved the MicroPython board specific functions to a separate submenu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9751
diff
changeset
|
217 | self.__flashDAPLinkAct = self.__microbitMenu.addAction( |
2b9546c0cbd9
Moved the MicroPython board specific functions to a separate submenu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9751
diff
changeset
|
218 | self.tr("Flash Firmware"), lambda: self.__flashMicroPython(firmware=True) |
2b9546c0cbd9
Moved the MicroPython board specific functions to a separate submenu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9751
diff
changeset
|
219 | ) |
2b9546c0cbd9
Moved the MicroPython board specific functions to a separate submenu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9751
diff
changeset
|
220 | self.__microbitMenu.addSeparator() |
2b9546c0cbd9
Moved the MicroPython board specific functions to a separate submenu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9751
diff
changeset
|
221 | self.__saveMainScriptAct = self.__microbitMenu.addAction( |
2b9546c0cbd9
Moved the MicroPython board specific functions to a separate submenu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9751
diff
changeset
|
222 | self.tr("Save Script as 'main.py'"), self.__saveMain |
2b9546c0cbd9
Moved the MicroPython board specific functions to a separate submenu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9751
diff
changeset
|
223 | ) |
2b9546c0cbd9
Moved the MicroPython board specific functions to a separate submenu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9751
diff
changeset
|
224 | self.__saveMainScriptAct.setToolTip( |
2b9546c0cbd9
Moved the MicroPython board specific functions to a separate submenu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9751
diff
changeset
|
225 | self.tr("Save the current script as 'main.py' on the connected device") |
2b9546c0cbd9
Moved the MicroPython board specific functions to a separate submenu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9751
diff
changeset
|
226 | ) |
2b9546c0cbd9
Moved the MicroPython board specific functions to a separate submenu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9751
diff
changeset
|
227 | self.__microbitMenu.addSeparator() |
2b9546c0cbd9
Moved the MicroPython board specific functions to a separate submenu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9751
diff
changeset
|
228 | self.__resetAct = self.__microbitMenu.addAction( |
2b9546c0cbd9
Moved the MicroPython board specific functions to a separate submenu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9751
diff
changeset
|
229 | self.tr("Reset {0}").format(self.deviceName()), self.__resetDevice |
2b9546c0cbd9
Moved the MicroPython board specific functions to a separate submenu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9751
diff
changeset
|
230 | ) |
2b9546c0cbd9
Moved the MicroPython board specific functions to a separate submenu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9751
diff
changeset
|
231 | |
7123
94948e2aa0a5
Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7114
diff
changeset
|
232 | def addDeviceMenuEntries(self, menu): |
94948e2aa0a5
Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7114
diff
changeset
|
233 | """ |
94948e2aa0a5
Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7114
diff
changeset
|
234 | Public method to add device specific entries to the given menu. |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
235 | |
7123
94948e2aa0a5
Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7114
diff
changeset
|
236 | @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
|
237 | @type QMenu |
94948e2aa0a5
Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7114
diff
changeset
|
238 | """ |
94948e2aa0a5
Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7114
diff
changeset
|
239 | connected = self.microPython.isConnected() |
9749 | 240 | linkConnected = self.microPython.isLinkConnected() |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
241 | |
9766
f0e22f3a5878
Fixed a few issue introduced during the recent changes to the MicroPython package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9765
diff
changeset
|
242 | aw = ericApp().getObject("ViewManager").activeWindow() |
f0e22f3a5878
Fixed a few issue introduced during the recent changes to the MicroPython package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9765
diff
changeset
|
243 | canSaveMain = ( |
f0e22f3a5878
Fixed a few issue introduced during the recent changes to the MicroPython package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9765
diff
changeset
|
244 | aw is not None |
f0e22f3a5878
Fixed a few issue introduced during the recent changes to the MicroPython package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9765
diff
changeset
|
245 | and (aw.isPyFile() or aw.isMicroPythonFile()) |
f0e22f3a5878
Fixed a few issue introduced during the recent changes to the MicroPython package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9765
diff
changeset
|
246 | and bool(aw.text().strip()) |
f0e22f3a5878
Fixed a few issue introduced during the recent changes to the MicroPython package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9765
diff
changeset
|
247 | ) |
f0e22f3a5878
Fixed a few issue introduced during the recent changes to the MicroPython package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9765
diff
changeset
|
248 | |
9752
2b9546c0cbd9
Moved the MicroPython board specific functions to a separate submenu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9751
diff
changeset
|
249 | self.__showMpyAct.setEnabled(connected and self.getDeviceType() != "calliope") |
2b9546c0cbd9
Moved the MicroPython board specific functions to a separate submenu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9751
diff
changeset
|
250 | self.__flashMpyAct.setEnabled(not linkConnected) |
2b9546c0cbd9
Moved the MicroPython board specific functions to a separate submenu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9751
diff
changeset
|
251 | self.__flashDAPLinkAct.setEnabled(not linkConnected) |
9766
f0e22f3a5878
Fixed a few issue introduced during the recent changes to the MicroPython package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9765
diff
changeset
|
252 | self.__saveMainScriptAct.setEnabled(connected and canSaveMain) |
9752
2b9546c0cbd9
Moved the MicroPython board specific functions to a separate submenu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9751
diff
changeset
|
253 | self.__resetAct.setEnabled(connected) |
2b9546c0cbd9
Moved the MicroPython board specific functions to a separate submenu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9751
diff
changeset
|
254 | |
2b9546c0cbd9
Moved the MicroPython board specific functions to a separate submenu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9751
diff
changeset
|
255 | menu.addMenu(self.__microbitMenu) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
256 | |
8096 | 257 | def hasFlashMenuEntry(self): |
258 | """ | |
259 | Public method to check, if the device has its own flash menu entry. | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
260 | |
8096 | 261 | @return flag indicating a specific flash menu entry |
262 | @rtype bool | |
263 | """ | |
264 | return True | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
265 | |
7123
94948e2aa0a5
Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7114
diff
changeset
|
266 | @pyqtSlot() |
8032
76375aa6bc04
Corrected the support code for the "BBC micro:bit" MicroPython device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
267 | 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
|
268 | """ |
8032
76375aa6bc04
Corrected the support code for the "BBC micro:bit" MicroPython device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
269 | 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
|
270 | device. |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
271 | |
8032
76375aa6bc04
Corrected the support code for the "BBC micro:bit" MicroPython device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
272 | @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
|
273 | @type bool |
76375aa6bc04
Corrected the support code for the "BBC micro:bit" MicroPython device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
274 | """ |
76375aa6bc04
Corrected the support code for the "BBC micro:bit" MicroPython device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
275 | # 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
|
276 | # 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
|
277 | # in maintenance mode, for MicroPython in standard mode. |
8117
aaa5e0eacd4e
MicroPython: changed the logic to synchronize the time because some devices don't implement long integer and failed defining the 'set_time()' function.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8096
diff
changeset
|
278 | if self.getDeviceType() == "bbc_microbit": |
7552
b62e73df71dd
MicroPython: continued implementing support for the "Calliope mini".
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7551
diff
changeset
|
279 | # 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
|
280 | if firmware: |
9624
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9576
diff
changeset
|
281 | deviceDirectories = FileSystemUtilities.findVolume( |
11177
f511038a0061
Corrected some issues related to controllers with small RAM and limited numbers support (i.e. BBC micro:bit and Calliope mini).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11167
diff
changeset
|
282 | "MAINTENANCE", findAll=True, markerFile="DETAILS.TXT" |
9624
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9576
diff
changeset
|
283 | ) |
8032
76375aa6bc04
Corrected the support code for the "BBC micro:bit" MicroPython device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
284 | else: |
9624
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9576
diff
changeset
|
285 | deviceDirectories = FileSystemUtilities.findVolume( |
11177
f511038a0061
Corrected some issues related to controllers with small RAM and limited numbers support (i.e. BBC micro:bit and Calliope mini).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11167
diff
changeset
|
286 | "MICROBIT", findAll=True, markerFile="DETAILS.TXT" |
9624
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9576
diff
changeset
|
287 | ) |
7552
b62e73df71dd
MicroPython: continued implementing support for the "Calliope mini".
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7551
diff
changeset
|
288 | else: |
b62e73df71dd
MicroPython: continued implementing support for the "Calliope mini".
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7551
diff
changeset
|
289 | # Calliope mini |
8051
b78279548993
MicroPython: changed the handling of the download stuff and corrected/extended the Calliope mini path.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8038
diff
changeset
|
290 | if firmware: |
9624
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9576
diff
changeset
|
291 | deviceDirectories = FileSystemUtilities.findVolume( |
11177
f511038a0061
Corrected some issues related to controllers with small RAM and limited numbers support (i.e. BBC micro:bit and Calliope mini).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11167
diff
changeset
|
292 | "MAINTENANCE", findAll=True, markerFile="DETAILS.TXT" |
9624
b47dfa7a137d
Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9576
diff
changeset
|
293 | ) |
8051
b78279548993
MicroPython: changed the handling of the download stuff and corrected/extended the Calliope mini path.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8038
diff
changeset
|
294 | else: |
11177
f511038a0061
Corrected some issues related to controllers with small RAM and limited numbers support (i.e. BBC micro:bit and Calliope mini).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11167
diff
changeset
|
295 | deviceDirectories = FileSystemUtilities.findVolume( |
f511038a0061
Corrected some issues related to controllers with small RAM and limited numbers support (i.e. BBC micro:bit and Calliope mini).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11167
diff
changeset
|
296 | "MINI", findAll=True, markerFile="DETAILS.TXT" |
f511038a0061
Corrected some issues related to controllers with small RAM and limited numbers support (i.e. BBC micro:bit and Calliope mini).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11167
diff
changeset
|
297 | ) |
8062
8dc5acb30a8b
MicroPython: implemented code to deal with multiple devices attached to the computer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8051
diff
changeset
|
298 | if len(deviceDirectories) == 0: |
8117
aaa5e0eacd4e
MicroPython: changed the logic to synchronize the time because some devices don't implement long integer and failed defining the 'set_time()' function.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8096
diff
changeset
|
299 | if self.getDeviceType() == "bbc_microbit": |
7551
b159c55ea6dd
MicroPython: continued implementing support for the "Calliope mini".
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7549
diff
changeset
|
300 | # 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
|
301 | if firmware: |
8356
68ec9c3d4de5
Renamed the modules and classes of the E5Gui package to have the prefix 'Eric' instead of 'E5'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8318
diff
changeset
|
302 | EricMessageBox.critical( |
8032
76375aa6bc04
Corrected the support code for the "BBC micro:bit" MicroPython device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
303 | self.microPython, |
76375aa6bc04
Corrected the support code for the "BBC micro:bit" MicroPython device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
304 | 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
|
305 | self.tr( |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
306 | "<p>The BBC micro:bit is not ready for flashing" |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
307 | " the DAPLink firmware. Follow these" |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
308 | " instructions. </p>" |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
309 | "<ul>" |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
310 | "<li>unplug USB cable and any batteries</li>" |
9749 | 311 | "<li>keep RESET button pressed and plug USB cable" |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
312 | " back in</li>" |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
313 | "<li>a drive called MAINTENANCE should be" |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
314 | " available</li>" |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
315 | "</ul>" |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
316 | "<p>See the " |
8032
76375aa6bc04
Corrected the support code for the "BBC micro:bit" MicroPython device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
317 | '<a href="https://microbit.org/guide/firmware/">' |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
318 | "micro:bit web site</a> for details.</p>" |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
319 | ), |
8032
76375aa6bc04
Corrected the support code for the "BBC micro:bit" MicroPython device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
320 | ) |
76375aa6bc04
Corrected the support code for the "BBC micro:bit" MicroPython device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
321 | else: |
8356
68ec9c3d4de5
Renamed the modules and classes of the E5Gui package to have the prefix 'Eric' instead of 'E5'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8318
diff
changeset
|
322 | EricMessageBox.critical( |
8032
76375aa6bc04
Corrected the support code for the "BBC micro:bit" MicroPython device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
323 | self.microPython, |
76375aa6bc04
Corrected the support code for the "BBC micro:bit" MicroPython device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
324 | 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
|
325 | self.tr( |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
326 | "<p>The BBC micro:bit is not ready for flashing" |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
327 | " the MicroPython firmware. Please make sure," |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
328 | " that a drive called MICROBIT is available." |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
329 | "</p>" |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
330 | ), |
8032
76375aa6bc04
Corrected the support code for the "BBC micro:bit" MicroPython device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
331 | ) |
7551
b159c55ea6dd
MicroPython: continued implementing support for the "Calliope mini".
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7549
diff
changeset
|
332 | else: |
b159c55ea6dd
MicroPython: continued implementing support for the "Calliope mini".
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7549
diff
changeset
|
333 | # Calliope mini is not ready or not mounted |
8051
b78279548993
MicroPython: changed the handling of the download stuff and corrected/extended the Calliope mini path.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8038
diff
changeset
|
334 | if firmware: |
8356
68ec9c3d4de5
Renamed the modules and classes of the E5Gui package to have the prefix 'Eric' instead of 'E5'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8318
diff
changeset
|
335 | EricMessageBox.critical( |
8051
b78279548993
MicroPython: changed the handling of the download stuff and corrected/extended the Calliope mini path.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8038
diff
changeset
|
336 | self.microPython, |
b78279548993
MicroPython: changed the handling of the download stuff and corrected/extended the Calliope mini path.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8038
diff
changeset
|
337 | self.tr("Flash MicroPython/Firmware"), |
b78279548993
MicroPython: changed the handling of the download stuff and corrected/extended the Calliope mini path.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8038
diff
changeset
|
338 | self.tr( |
b78279548993
MicroPython: changed the handling of the download stuff and corrected/extended the Calliope mini path.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8038
diff
changeset
|
339 | '<p>The "Calliope mini" is not ready for flashing' |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
340 | " the DAPLink firmware. Follow these" |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
341 | " instructions. </p>" |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
342 | "<ul>" |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
343 | "<li>unplug USB cable and any batteries</li>" |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
344 | "<li>keep RESET button pressed an plug USB cable" |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
345 | " back in</li>" |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
346 | "<li>a drive called MAINTENANCE should be" |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
347 | " available</li>" |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
348 | "</ul>" |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
349 | ), |
8051
b78279548993
MicroPython: changed the handling of the download stuff and corrected/extended the Calliope mini path.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8038
diff
changeset
|
350 | ) |
b78279548993
MicroPython: changed the handling of the download stuff and corrected/extended the Calliope mini path.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8038
diff
changeset
|
351 | else: |
8356
68ec9c3d4de5
Renamed the modules and classes of the E5Gui package to have the prefix 'Eric' instead of 'E5'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8318
diff
changeset
|
352 | EricMessageBox.critical( |
8051
b78279548993
MicroPython: changed the handling of the download stuff and corrected/extended the Calliope mini path.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8038
diff
changeset
|
353 | self.microPython, |
b78279548993
MicroPython: changed the handling of the download stuff and corrected/extended the Calliope mini path.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8038
diff
changeset
|
354 | self.tr("Flash MicroPython/Firmware"), |
b78279548993
MicroPython: changed the handling of the download stuff and corrected/extended the Calliope mini path.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8038
diff
changeset
|
355 | self.tr( |
b78279548993
MicroPython: changed the handling of the download stuff and corrected/extended the Calliope mini path.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8038
diff
changeset
|
356 | '<p>The "Calliope mini" is not ready for flashing' |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
357 | " the MicroPython firmware. Please make sure," |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
358 | " that a drive called MINI is available." |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
359 | "</p>" |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
360 | ), |
8051
b78279548993
MicroPython: changed the handling of the download stuff and corrected/extended the Calliope mini path.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8038
diff
changeset
|
361 | ) |
8062
8dc5acb30a8b
MicroPython: implemented code to deal with multiple devices attached to the computer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8051
diff
changeset
|
362 | elif len(deviceDirectories) == 1: |
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
|
363 | downloadsPath = QStandardPaths.standardLocations( |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
364 | QStandardPaths.StandardLocation.DownloadLocation |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
365 | )[0] |
8356
68ec9c3d4de5
Renamed the modules and classes of the E5Gui package to have the prefix 'Eric' instead of 'E5'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8318
diff
changeset
|
366 | firmware = EricFileDialog.getOpenFileName( |
7173
f611c3b7313f
EspDevices, MicrobitDevices: fixed a few omissions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7161
diff
changeset
|
367 | 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
|
368 | 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
|
369 | downloadsPath, |
9576
be9f8e7e42e0
Corrected some 'wrong' string quotes caused by the Black line merging.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9496
diff
changeset
|
370 | self.tr("MicroPython/Firmware Files (*.hex *.bin);;All Files (*)"), |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
371 | ) |
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
|
372 | if firmware and os.path.exists(firmware): |
8062
8dc5acb30a8b
MicroPython: implemented code to deal with multiple devices attached to the computer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8051
diff
changeset
|
373 | shutil.copy2(firmware, deviceDirectories[0]) |
8dc5acb30a8b
MicroPython: implemented code to deal with multiple devices attached to the computer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8051
diff
changeset
|
374 | else: |
8356
68ec9c3d4de5
Renamed the modules and classes of the E5Gui package to have the prefix 'Eric' instead of 'E5'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8318
diff
changeset
|
375 | EricMessageBox.warning( |
11034
7b8a21fd2d58
Extended the EricMessageBox module to determine a parent widget if none was given and extended the EricApplication class to store a reference to the main widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10806
diff
changeset
|
376 | self.microPython, |
8062
8dc5acb30a8b
MicroPython: implemented code to deal with multiple devices attached to the computer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8051
diff
changeset
|
377 | self.tr("Flash MicroPython/Firmware"), |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
378 | self.tr( |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
379 | "There are multiple devices ready for flashing." |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
380 | " Please make sure, that only one device is prepared." |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
381 | ), |
8062
8dc5acb30a8b
MicroPython: implemented code to deal with multiple devices attached to the computer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8051
diff
changeset
|
382 | ) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
383 | |
7123
94948e2aa0a5
Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7114
diff
changeset
|
384 | @pyqtSlot() |
9749 | 385 | def __showFirmwareVersions(self): |
386 | """ | |
387 | Private slot to show the firmware version of the connected device and the | |
388 | available firmware version. | |
389 | """ | |
9804 | 390 | if self.microPython.isConnected() and self.checkDeviceData(quiet=False): |
9751
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9750
diff
changeset
|
391 | if self._deviceData["mpy_name"] not in ("micropython", "circuitpython"): |
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9750
diff
changeset
|
392 | EricMessageBox.critical( |
11034
7b8a21fd2d58
Extended the EricMessageBox module to determine a parent widget if none was given and extended the EricApplication class to store a reference to the main widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10806
diff
changeset
|
393 | self.microPython, |
9751
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9750
diff
changeset
|
394 | self.tr("Show MicroPython Versions"), |
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9750
diff
changeset
|
395 | self.tr( |
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9750
diff
changeset
|
396 | """The firmware of the connected device cannot be""" |
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9750
diff
changeset
|
397 | """ determined or the board does not run MicroPython""" |
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9750
diff
changeset
|
398 | """ or CircuitPython. Aborting...""" |
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9750
diff
changeset
|
399 | ), |
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9750
diff
changeset
|
400 | ) |
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9750
diff
changeset
|
401 | else: |
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9750
diff
changeset
|
402 | if self.getDeviceType() == "bbc_microbit": |
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9750
diff
changeset
|
403 | if self._deviceData["mpy_name"] == "micropython": |
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9750
diff
changeset
|
404 | if self.__isMicroBitV1(): |
9749 | 405 | url = QUrl(FirmwareGithubUrls["microbit_v1"]) |
9751
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9750
diff
changeset
|
406 | elif self.__isMicroBitV2(): |
9749 | 407 | url = QUrl(FirmwareGithubUrls["microbit_v2"]) |
408 | else: | |
409 | EricMessageBox.critical( | |
410 | None, | |
411 | self.tr("Show MicroPython Versions"), | |
412 | self.tr( | |
413 | """<p>The BBC micro:bit generation cannot be""" | |
414 | """ determined. Aborting...</p>""" | |
415 | ), | |
416 | ) | |
417 | return | |
9751
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9750
diff
changeset
|
418 | elif self._deviceData["mpy_name"] == "circuitpython": |
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9750
diff
changeset
|
419 | url = QUrl(FirmwareGithubUrls["circuitpython"]) |
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9750
diff
changeset
|
420 | else: |
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9750
diff
changeset
|
421 | EricMessageBox.critical( |
11034
7b8a21fd2d58
Extended the EricMessageBox module to determine a parent widget if none was given and extended the EricApplication class to store a reference to the main widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10806
diff
changeset
|
422 | self.microPython, |
9751
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9750
diff
changeset
|
423 | self.tr("Show MicroPython Versions"), |
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9750
diff
changeset
|
424 | self.tr( |
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9750
diff
changeset
|
425 | """<p>The firmware URL for the device type <b>{0}</b>""" |
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9750
diff
changeset
|
426 | """ is not known. Aborting...</p>""" |
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9750
diff
changeset
|
427 | ).format(self.getDeviceType()), |
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9750
diff
changeset
|
428 | ) |
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9750
diff
changeset
|
429 | return |
9749 | 430 | |
9751
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9750
diff
changeset
|
431 | ui = ericApp().getObject("UserInterface") |
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9750
diff
changeset
|
432 | request = QNetworkRequest(url) |
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9750
diff
changeset
|
433 | reply = ui.networkAccessManager().head(request) |
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9750
diff
changeset
|
434 | reply.finished.connect(lambda: self.__firmwareVersionResponse(reply)) |
9749 | 435 | |
9820 | 436 | @pyqtSlot(QNetworkReply) |
9751
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9750
diff
changeset
|
437 | def __firmwareVersionResponse(self, reply): |
9749 | 438 | """ |
9820 | 439 | Private slot handling the response of the latest version request. |
9749 | 440 | |
441 | @param reply reference to the reply object | |
442 | @type QNetworkReply | |
443 | """ | |
444 | latestUrl = reply.url().toString() | |
445 | tag = latestUrl.rsplit("/", 1)[-1] | |
446 | while tag and not tag[0].isdecimal(): | |
447 | # get rid of leading non-decimal characters | |
448 | tag = tag[1:] | |
10806
2f6df822e3b9
Moved some functions to the EricUtilities package for consistency and adapted the code base accordingly.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10683
diff
changeset
|
449 | latestVersion = EricUtilities.versionToTuple(tag) |
9749 | 450 | |
9751
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9750
diff
changeset
|
451 | if self._deviceData["release"] == "unknown": |
9749 | 452 | currentVersionStr = self.tr("unknown") |
453 | currentVersion = (0, 0, 0) | |
454 | else: | |
9751
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9750
diff
changeset
|
455 | currentVersionStr = self._deviceData["release"] |
10806
2f6df822e3b9
Moved some functions to the EricUtilities package for consistency and adapted the code base accordingly.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10683
diff
changeset
|
456 | currentVersion = EricUtilities.versionToTuple(currentVersionStr) |
9749 | 457 | |
9751
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9750
diff
changeset
|
458 | if self._deviceData["mpy_name"] == "circuitpython": |
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9750
diff
changeset
|
459 | kind = "CircuitPython" |
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9750
diff
changeset
|
460 | microbitVersion = "2" # only v2 device can run CircuitPython |
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9750
diff
changeset
|
461 | elif self._deviceData["mpy_name"] == "micropython": |
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9750
diff
changeset
|
462 | kind = "MicroPython" |
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9750
diff
changeset
|
463 | if self.__isMicroBitV1(): |
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9750
diff
changeset
|
464 | microbitVersion = "1" |
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9750
diff
changeset
|
465 | elif self.__isMicroBitV2(): |
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9750
diff
changeset
|
466 | microbitVersion = "2" |
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9750
diff
changeset
|
467 | else: |
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9750
diff
changeset
|
468 | kind = self.tr("Firmware") |
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9750
diff
changeset
|
469 | microbitVersion = "?" |
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9750
diff
changeset
|
470 | |
9749 | 471 | msg = self.tr( |
9751
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9750
diff
changeset
|
472 | "<h4>{0} Version Information<br/>" |
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9750
diff
changeset
|
473 | "(BBC micro:bit v{1})</h4>" |
9749 | 474 | "<table>" |
9751
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9750
diff
changeset
|
475 | "<tr><td>Installed:</td><td>{2}</td></tr>" |
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9750
diff
changeset
|
476 | "<tr><td>Available:</td><td>{3}</td></tr>" |
9749 | 477 | "</table>" |
9751
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9750
diff
changeset
|
478 | ).format(kind, microbitVersion, currentVersionStr, tag) |
9749 | 479 | if currentVersion < latestVersion: |
480 | msg += self.tr("<p><b>Update available!</b></p>") | |
481 | ||
482 | EricMessageBox.information( | |
11034
7b8a21fd2d58
Extended the EricMessageBox module to determine a parent widget if none was given and extended the EricApplication class to store a reference to the main widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10806
diff
changeset
|
483 | self.microPython, |
9751
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9750
diff
changeset
|
484 | self.tr("{0} Version").format(kind), |
9749 | 485 | msg, |
486 | ) | |
487 | ||
488 | @pyqtSlot() | |
7123
94948e2aa0a5
Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7114
diff
changeset
|
489 | def __saveMain(self): |
94948e2aa0a5
Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7114
diff
changeset
|
490 | """ |
94948e2aa0a5
Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7114
diff
changeset
|
491 | 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
|
492 | connected device. |
94948e2aa0a5
Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7114
diff
changeset
|
493 | """ |
8356
68ec9c3d4de5
Renamed the modules and classes of the E5Gui package to have the prefix 'Eric' instead of 'E5'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8318
diff
changeset
|
494 | aw = ericApp().getObject("ViewManager").activeWindow() |
10512 | 495 | if aw: |
496 | title = self.tr("Save Script as 'main.py'") | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
497 | |
10512 | 498 | if not (aw.isPyFile() or aw.isMicroPythonFile()): |
499 | yes = EricMessageBox.yesNo( | |
500 | self.microPython, | |
501 | title, | |
502 | self.tr( | |
503 | """The current editor does not contain a Python""" | |
504 | """ script. Write it anyway?""" | |
505 | ), | |
506 | ) | |
507 | if not yes: | |
508 | return | |
509 | ||
510 | script = aw.text().strip() | |
511 | if not script: | |
512 | EricMessageBox.warning( | |
513 | self.microPython, | |
514 | title, | |
515 | self.tr("""The script is empty. Aborting."""), | |
516 | ) | |
7123
94948e2aa0a5
Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7114
diff
changeset
|
517 | return |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
518 | |
10512 | 519 | self.putData("main.py", script.encode("utf-8")) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
520 | |
10512 | 521 | # reset the device |
522 | self.__resetDevice() | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
523 | |
7123
94948e2aa0a5
Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7114
diff
changeset
|
524 | @pyqtSlot() |
94948e2aa0a5
Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7114
diff
changeset
|
525 | def __resetDevice(self): |
94948e2aa0a5
Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7114
diff
changeset
|
526 | """ |
94948e2aa0a5
Implemented the support for the 'BBC micro:bit' device.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7114
diff
changeset
|
527 | 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
|
528 | """ |
9989 | 529 | if self.microPython.isConnected(): |
530 | if self.getDeviceType() == "bbc_microbit": | |
531 | # BBC micro:bit | |
532 | self.executeCommands( | |
533 | "import microbit\nmicrobit.reset()\n", mode=self._submitMode | |
534 | ) | |
535 | else: | |
536 | # Calliope mini | |
537 | self.executeCommands( | |
538 | "import calliope_mini\ncalliope_mini.reset()\n", | |
539 | mode=self._submitMode, | |
540 | ) | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
541 | |
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
|
542 | 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
|
543 | """ |
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
|
544 | Public method to get the device documentation URL. |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
545 | |
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
|
546 | @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
|
547 | @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
|
548 | """ |
8117
aaa5e0eacd4e
MicroPython: changed the logic to synchronize the time because some devices don't implement long integer and failed defining the 'set_time()' function.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8096
diff
changeset
|
549 | if self.getDeviceType() == "bbc_microbit": |
7549
fcfbb9e94471
MicroPython: continued implementing support for the "Calliope mini".
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7548
diff
changeset
|
550 | # BBC micro:bit |
9751
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9750
diff
changeset
|
551 | if self._deviceData and self._deviceData["mpy_name"] == "circuitpython": |
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9750
diff
changeset
|
552 | return Preferences.getMicroPython("CircuitPythonDocuUrl") |
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9750
diff
changeset
|
553 | else: |
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9750
diff
changeset
|
554 | return Preferences.getMicroPython("MicrobitDocuUrl") |
7549
fcfbb9e94471
MicroPython: continued implementing support for the "Calliope mini".
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7548
diff
changeset
|
555 | else: |
fcfbb9e94471
MicroPython: continued implementing support for the "Calliope mini".
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7548
diff
changeset
|
556 | # Calliope mini |
fcfbb9e94471
MicroPython: continued implementing support for the "Calliope mini".
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7548
diff
changeset
|
557 | return Preferences.getMicroPython("CalliopeDocuUrl") |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
558 | |
8051
b78279548993
MicroPython: changed the handling of the download stuff and corrected/extended the Calliope mini path.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8038
diff
changeset
|
559 | def getDownloadMenuEntries(self): |
7328 | 560 | """ |
8051
b78279548993
MicroPython: changed the handling of the download stuff and corrected/extended the Calliope mini path.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8038
diff
changeset
|
561 | Public method to retrieve the entries for the downloads menu. |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
562 | |
8051
b78279548993
MicroPython: changed the handling of the download stuff and corrected/extended the Calliope mini path.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8038
diff
changeset
|
563 | @return list of tuples with menu text and URL to be opened for each |
b78279548993
MicroPython: changed the handling of the download stuff and corrected/extended the Calliope mini path.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8038
diff
changeset
|
564 | entry |
b78279548993
MicroPython: changed the handling of the download stuff and corrected/extended the Calliope mini path.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8038
diff
changeset
|
565 | @rtype list of tuple of (str, str) |
7328 | 566 | """ |
8117
aaa5e0eacd4e
MicroPython: changed the logic to synchronize the time because some devices don't implement long integer and failed defining the 'set_time()' function.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8096
diff
changeset
|
567 | if self.getDeviceType() == "bbc_microbit": |
9751
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9750
diff
changeset
|
568 | if self.__isMicroBitV1(): |
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9750
diff
changeset
|
569 | return [ |
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9750
diff
changeset
|
570 | ( |
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9750
diff
changeset
|
571 | self.tr("MicroPython Firmware for BBC micro:bit V1"), |
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9750
diff
changeset
|
572 | Preferences.getMicroPython("MicrobitMicroPythonUrl"), |
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9750
diff
changeset
|
573 | ), |
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9750
diff
changeset
|
574 | ( |
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9750
diff
changeset
|
575 | self.tr("DAPLink Firmware"), |
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9750
diff
changeset
|
576 | Preferences.getMicroPython("MicrobitFirmwareUrl"), |
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9750
diff
changeset
|
577 | ), |
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9750
diff
changeset
|
578 | ] |
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9750
diff
changeset
|
579 | elif self.__isMicroBitV2(): |
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9750
diff
changeset
|
580 | return [ |
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9750
diff
changeset
|
581 | ( |
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9750
diff
changeset
|
582 | self.tr("MicroPython Firmware for BBC micro:bit V2"), |
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9750
diff
changeset
|
583 | Preferences.getMicroPython("MicrobitV2MicroPythonUrl"), |
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9750
diff
changeset
|
584 | ), |
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9750
diff
changeset
|
585 | ( |
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9750
diff
changeset
|
586 | self.tr("CircuitPython Firmware for BBC micro:bit V2"), |
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9750
diff
changeset
|
587 | "https://circuitpython.org/board/microbit_v2/", |
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9750
diff
changeset
|
588 | ), |
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9750
diff
changeset
|
589 | ( |
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9750
diff
changeset
|
590 | self.tr("DAPLink Firmware"), |
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9750
diff
changeset
|
591 | Preferences.getMicroPython("MicrobitFirmwareUrl"), |
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9750
diff
changeset
|
592 | ), |
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9750
diff
changeset
|
593 | ] |
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9750
diff
changeset
|
594 | else: |
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9750
diff
changeset
|
595 | return [] |
7549
fcfbb9e94471
MicroPython: continued implementing support for the "Calliope mini".
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7548
diff
changeset
|
596 | else: |
8051
b78279548993
MicroPython: changed the handling of the download stuff and corrected/extended the Calliope mini path.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8038
diff
changeset
|
597 | return [ |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
598 | ( |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
599 | self.tr("MicroPython Firmware"), |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
600 | Preferences.getMicroPython("CalliopeMicroPythonUrl"), |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
601 | ), |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
602 | ( |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
603 | self.tr("DAPLink Firmware"), |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
604 | Preferences.getMicroPython("CalliopeDAPLinkUrl"), |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
605 | ), |
8051
b78279548993
MicroPython: changed the handling of the download stuff and corrected/extended the Calliope mini path.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8038
diff
changeset
|
606 | ] |
9496
05017f795c24
Changed MicroPython device imports to use importlib.import_module().
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9473
diff
changeset
|
607 | |
9765
6378da868bb0
Reorganized the MicroPython code even more.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
608 | ################################################################## |
6378da868bb0
Reorganized the MicroPython code even more.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
609 | ## Methods below implement the file system commands |
6378da868bb0
Reorganized the MicroPython code even more.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
610 | ################################################################## |
6378da868bb0
Reorganized the MicroPython code even more.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
611 | |
6378da868bb0
Reorganized the MicroPython code even more.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
612 | def ls(self, dirname=""): |
6378da868bb0
Reorganized the MicroPython code even more.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
613 | """ |
6378da868bb0
Reorganized the MicroPython code even more.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
614 | Public method to get a directory listing of the connected device. |
6378da868bb0
Reorganized the MicroPython code even more.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
615 | |
6378da868bb0
Reorganized the MicroPython code even more.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
616 | @param dirname name of the directory to be listed |
6378da868bb0
Reorganized the MicroPython code even more.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
617 | @type str |
6378da868bb0
Reorganized the MicroPython code even more.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
618 | @return tuple containg the directory listing |
6378da868bb0
Reorganized the MicroPython code even more.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
619 | @rtype tuple of str |
6378da868bb0
Reorganized the MicroPython code even more.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
620 | @exception OSError raised to indicate an issue with the device |
6378da868bb0
Reorganized the MicroPython code even more.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
621 | """ |
9766
f0e22f3a5878
Fixed a few issue introduced during the recent changes to the MicroPython package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9765
diff
changeset
|
622 | if self.hasCircuitPython(): |
f0e22f3a5878
Fixed a few issue introduced during the recent changes to the MicroPython package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9765
diff
changeset
|
623 | return super().ls(dirname=dirname) |
f0e22f3a5878
Fixed a few issue introduced during the recent changes to the MicroPython package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9765
diff
changeset
|
624 | else: |
f0e22f3a5878
Fixed a few issue introduced during the recent changes to the MicroPython package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9765
diff
changeset
|
625 | # BBC micro:bit with MicroPython does not support directories |
f0e22f3a5878
Fixed a few issue introduced during the recent changes to the MicroPython package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9765
diff
changeset
|
626 | command = """ |
f0e22f3a5878
Fixed a few issue introduced during the recent changes to the MicroPython package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9765
diff
changeset
|
627 | import os as __os_ |
f0e22f3a5878
Fixed a few issue introduced during the recent changes to the MicroPython package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9765
diff
changeset
|
628 | print(__os_.listdir()) |
f0e22f3a5878
Fixed a few issue introduced during the recent changes to the MicroPython package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9765
diff
changeset
|
629 | del __os_ |
f0e22f3a5878
Fixed a few issue introduced during the recent changes to the MicroPython package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9765
diff
changeset
|
630 | """ |
9989 | 631 | out, err = self.executeCommands(command, mode=self._submitMode) |
9766
f0e22f3a5878
Fixed a few issue introduced during the recent changes to the MicroPython package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9765
diff
changeset
|
632 | if err: |
f0e22f3a5878
Fixed a few issue introduced during the recent changes to the MicroPython package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9765
diff
changeset
|
633 | raise OSError(self._shortError(err)) |
f0e22f3a5878
Fixed a few issue introduced during the recent changes to the MicroPython package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9765
diff
changeset
|
634 | return ast.literal_eval(out.decode("utf-8")) |
9765
6378da868bb0
Reorganized the MicroPython code even more.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
635 | |
6378da868bb0
Reorganized the MicroPython code even more.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
636 | def lls(self, dirname="", fullstat=False, showHidden=False): |
6378da868bb0
Reorganized the MicroPython code even more.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
637 | """ |
6378da868bb0
Reorganized the MicroPython code even more.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
638 | Public method to get a long directory listing of the connected device |
6378da868bb0
Reorganized the MicroPython code even more.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
639 | including meta data. |
6378da868bb0
Reorganized the MicroPython code even more.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
640 | |
6378da868bb0
Reorganized the MicroPython code even more.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
641 | @param dirname name of the directory to be listed |
6378da868bb0
Reorganized the MicroPython code even more.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
642 | @type str |
6378da868bb0
Reorganized the MicroPython code even more.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
643 | @param fullstat flag indicating to return the full stat() tuple |
6378da868bb0
Reorganized the MicroPython code even more.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
644 | @type bool |
6378da868bb0
Reorganized the MicroPython code even more.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
645 | @param showHidden flag indicating to show hidden files as well |
6378da868bb0
Reorganized the MicroPython code even more.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
646 | @type bool |
6378da868bb0
Reorganized the MicroPython code even more.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
647 | @return list containing the directory listing with tuple entries of |
6378da868bb0
Reorganized the MicroPython code even more.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
648 | the name and and a tuple of mode, size and time (if fullstat is |
6378da868bb0
Reorganized the MicroPython code even more.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
649 | false) or the complete stat() tuple. 'None' is returned in case the |
6378da868bb0
Reorganized the MicroPython code even more.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
650 | directory doesn't exist. |
6378da868bb0
Reorganized the MicroPython code even more.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
651 | @rtype tuple of (str, tuple) |
6378da868bb0
Reorganized the MicroPython code even more.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
652 | @exception OSError raised to indicate an issue with the device |
6378da868bb0
Reorganized the MicroPython code even more.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
653 | """ |
11186
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
654 | if self.hasCircuitPython() or self.supportsDirectories(): |
9766
f0e22f3a5878
Fixed a few issue introduced during the recent changes to the MicroPython package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9765
diff
changeset
|
655 | return super().lls( |
f0e22f3a5878
Fixed a few issue introduced during the recent changes to the MicroPython package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9765
diff
changeset
|
656 | dirname=dirname, fullstat=fullstat, showHidden=showHidden |
f0e22f3a5878
Fixed a few issue introduced during the recent changes to the MicroPython package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9765
diff
changeset
|
657 | ) |
9765
6378da868bb0
Reorganized the MicroPython code even more.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
658 | else: |
11186
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
659 | # BBC micro:bit with old MicroPython does not support directories |
9766
f0e22f3a5878
Fixed a few issue introduced during the recent changes to the MicroPython package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9765
diff
changeset
|
660 | command = """ |
f0e22f3a5878
Fixed a few issue introduced during the recent changes to the MicroPython package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9765
diff
changeset
|
661 | import os as __os_ |
f0e22f3a5878
Fixed a few issue introduced during the recent changes to the MicroPython package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9765
diff
changeset
|
662 | |
f0e22f3a5878
Fixed a few issue introduced during the recent changes to the MicroPython package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9765
diff
changeset
|
663 | def is_visible(filename, showHidden): |
f0e22f3a5878
Fixed a few issue introduced during the recent changes to the MicroPython package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9765
diff
changeset
|
664 | return showHidden or (filename[0] != '.' and filename[-1] != '~') |
f0e22f3a5878
Fixed a few issue introduced during the recent changes to the MicroPython package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9765
diff
changeset
|
665 | |
f0e22f3a5878
Fixed a few issue introduced during the recent changes to the MicroPython package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9765
diff
changeset
|
666 | def stat(filename): |
11186
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
667 | try: |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
668 | return __os_.stat(filename) |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
669 | except AttributeError: |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
670 | size = __os_.size(filename) |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
671 | return (0, 0, 0, 0, 0, 0, size, 0, 0, 0) |
9766
f0e22f3a5878
Fixed a few issue introduced during the recent changes to the MicroPython package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9765
diff
changeset
|
672 | |
f0e22f3a5878
Fixed a few issue introduced during the recent changes to the MicroPython package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9765
diff
changeset
|
673 | def listdir_stat(showHidden): |
f0e22f3a5878
Fixed a few issue introduced during the recent changes to the MicroPython package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9765
diff
changeset
|
674 | files = __os_.listdir() |
f0e22f3a5878
Fixed a few issue introduced during the recent changes to the MicroPython package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9765
diff
changeset
|
675 | return list((f, stat(f)) for f in files if is_visible(f,showHidden)) |
f0e22f3a5878
Fixed a few issue introduced during the recent changes to the MicroPython package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9765
diff
changeset
|
676 | |
f0e22f3a5878
Fixed a few issue introduced during the recent changes to the MicroPython package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9765
diff
changeset
|
677 | print(listdir_stat({0})) |
f0e22f3a5878
Fixed a few issue introduced during the recent changes to the MicroPython package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9765
diff
changeset
|
678 | del __os_, stat, listdir_stat, is_visible |
f0e22f3a5878
Fixed a few issue introduced during the recent changes to the MicroPython package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9765
diff
changeset
|
679 | """.format( |
f0e22f3a5878
Fixed a few issue introduced during the recent changes to the MicroPython package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9765
diff
changeset
|
680 | showHidden |
f0e22f3a5878
Fixed a few issue introduced during the recent changes to the MicroPython package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9765
diff
changeset
|
681 | ) |
9989 | 682 | out, err = self.executeCommands(command, mode=self._submitMode) |
9766
f0e22f3a5878
Fixed a few issue introduced during the recent changes to the MicroPython package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9765
diff
changeset
|
683 | if err: |
f0e22f3a5878
Fixed a few issue introduced during the recent changes to the MicroPython package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9765
diff
changeset
|
684 | raise OSError(self._shortError(err)) |
f0e22f3a5878
Fixed a few issue introduced during the recent changes to the MicroPython package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9765
diff
changeset
|
685 | fileslist = ast.literal_eval(out.decode("utf-8")) |
f0e22f3a5878
Fixed a few issue introduced during the recent changes to the MicroPython package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9765
diff
changeset
|
686 | if fileslist is None: |
f0e22f3a5878
Fixed a few issue introduced during the recent changes to the MicroPython package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9765
diff
changeset
|
687 | return None |
9765
6378da868bb0
Reorganized the MicroPython code even more.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
688 | else: |
9766
f0e22f3a5878
Fixed a few issue introduced during the recent changes to the MicroPython package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9765
diff
changeset
|
689 | if fullstat: |
f0e22f3a5878
Fixed a few issue introduced during the recent changes to the MicroPython package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9765
diff
changeset
|
690 | return fileslist |
f0e22f3a5878
Fixed a few issue introduced during the recent changes to the MicroPython package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9765
diff
changeset
|
691 | else: |
f0e22f3a5878
Fixed a few issue introduced during the recent changes to the MicroPython package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9765
diff
changeset
|
692 | return [(f, (s[0], s[6], s[8])) for f, s in fileslist] |
9765
6378da868bb0
Reorganized the MicroPython code even more.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
693 | |
6378da868bb0
Reorganized the MicroPython code even more.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
694 | def pwd(self): |
6378da868bb0
Reorganized the MicroPython code even more.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
695 | """ |
6378da868bb0
Reorganized the MicroPython code even more.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
696 | Public method to get the current directory of the connected device. |
6378da868bb0
Reorganized the MicroPython code even more.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
697 | |
6378da868bb0
Reorganized the MicroPython code even more.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
698 | @return current directory |
6378da868bb0
Reorganized the MicroPython code even more.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
699 | @rtype str |
6378da868bb0
Reorganized the MicroPython code even more.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
700 | """ |
9766
f0e22f3a5878
Fixed a few issue introduced during the recent changes to the MicroPython package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9765
diff
changeset
|
701 | if self.hasCircuitPython(): |
f0e22f3a5878
Fixed a few issue introduced during the recent changes to the MicroPython package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9765
diff
changeset
|
702 | return super().pwd() |
f0e22f3a5878
Fixed a few issue introduced during the recent changes to the MicroPython package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9765
diff
changeset
|
703 | else: |
11186
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
704 | try: |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
705 | return super().pwd() |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
706 | except OSError: |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
707 | # BBC micro:bit with old MicroPython does not support directories |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
708 | return "" |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
709 | |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
710 | def rm(self, filename): |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
711 | """ |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
712 | Public method to remove a file from the connected device. |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
713 | |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
714 | @param filename name of the file to be removed |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
715 | @type str |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
716 | """ |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
717 | if filename.startswith("/") and not self.supportsDirectories(): |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
718 | filename = filename[1:] |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
719 | super().rm(filename) |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
720 | |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
721 | def putData(self, deviceFileName, content): |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
722 | """ |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
723 | Public method to write the given data to the connected device. |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
724 | |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
725 | @param deviceFileName name of the file to write to |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
726 | @type str |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
727 | @param content data to write |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
728 | @type bytes |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
729 | @return flag indicating success |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
730 | @rtype bool |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
731 | """ |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
732 | if deviceFileName.startswith("/") and not self.supportsDirectories(): |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
733 | deviceFileName = deviceFileName[1:] |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
734 | return super().putData(deviceFileName, content) |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
735 | |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
736 | def getData(self, deviceFileName): |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
737 | """ |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
738 | Public method to read data from the connected device. |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
739 | |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
740 | @param deviceFileName name of the file to read from |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
741 | @type str |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
742 | @return data read from the device |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
743 | @rtype bytes |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
744 | """ |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
745 | if deviceFileName.startswith("/") and not self.supportsDirectories(): |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
746 | deviceFileName = deviceFileName[1:] |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
747 | return super().getData(deviceFileName) |
9765
6378da868bb0
Reorganized the MicroPython code even more.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
748 | |
6378da868bb0
Reorganized the MicroPython code even more.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
749 | ################################################################## |
6378da868bb0
Reorganized the MicroPython code even more.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
750 | ## time related methods below |
6378da868bb0
Reorganized the MicroPython code even more.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
751 | ################################################################## |
6378da868bb0
Reorganized the MicroPython code even more.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
752 | |
6378da868bb0
Reorganized the MicroPython code even more.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
753 | def _getSetTimeCode(self): |
6378da868bb0
Reorganized the MicroPython code even more.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
754 | """ |
6378da868bb0
Reorganized the MicroPython code even more.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
755 | Protected method to get the device code to set the time. |
6378da868bb0
Reorganized the MicroPython code even more.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
756 | |
6378da868bb0
Reorganized the MicroPython code even more.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
757 | Note: This method must be implemented in the various device specific |
6378da868bb0
Reorganized the MicroPython code even more.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
758 | subclasses. |
6378da868bb0
Reorganized the MicroPython code even more.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
759 | |
6378da868bb0
Reorganized the MicroPython code even more.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
760 | @return code to be executed on the connected device to set the time |
6378da868bb0
Reorganized the MicroPython code even more.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
761 | @rtype str |
6378da868bb0
Reorganized the MicroPython code even more.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
762 | """ |
6378da868bb0
Reorganized the MicroPython code even more.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
763 | # rtc_time[0] - year 4 digit |
6378da868bb0
Reorganized the MicroPython code even more.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
764 | # rtc_time[1] - month 1..12 |
6378da868bb0
Reorganized the MicroPython code even more.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
765 | # rtc_time[2] - day 1..31 |
6378da868bb0
Reorganized the MicroPython code even more.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
766 | # rtc_time[3] - weekday 1..7 1=Monday |
6378da868bb0
Reorganized the MicroPython code even more.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
767 | # rtc_time[4] - hour 0..23 |
6378da868bb0
Reorganized the MicroPython code even more.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
768 | # rtc_time[5] - minute 0..59 |
6378da868bb0
Reorganized the MicroPython code even more.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
769 | # rtc_time[6] - second 0..59 |
6378da868bb0
Reorganized the MicroPython code even more.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
770 | # rtc_time[7] - yearday 1..366 |
6378da868bb0
Reorganized the MicroPython code even more.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
771 | # rtc_time[8] - isdst 0, 1, or -1 |
9766
f0e22f3a5878
Fixed a few issue introduced during the recent changes to the MicroPython package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9765
diff
changeset
|
772 | if self.hasCircuitPython(): |
f0e22f3a5878
Fixed a few issue introduced during the recent changes to the MicroPython package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9765
diff
changeset
|
773 | return super()._getSetTimeCode() |
f0e22f3a5878
Fixed a few issue introduced during the recent changes to the MicroPython package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9765
diff
changeset
|
774 | else: |
f0e22f3a5878
Fixed a few issue introduced during the recent changes to the MicroPython package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9765
diff
changeset
|
775 | return "" |
9765
6378da868bb0
Reorganized the MicroPython code even more.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9763
diff
changeset
|
776 | |
9864 | 777 | ################################################################## |
778 | ## Methods below implement Bluetooth related methods | |
9870
0399d3607829
Fixed a few code formatting and style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9864
diff
changeset
|
779 | ## |
9864 | 780 | ## Note: These functions are only available on BBC micro:bit v2 |
781 | ## with CircuitPython firmware loaded. This is handled | |
782 | ## through the 'hasBluetooth()' method. | |
783 | ## | |
784 | ## The Bluetooth related code below is a copy of the one found in | |
785 | ## the CircuitPythonDevices.py module with modifications to cope | |
786 | ## with the limited set of available modules (e.g. no binascii | |
787 | ## or json). | |
788 | ################################################################## | |
789 | ||
790 | def hasBluetooth(self): | |
791 | """ | |
792 | Public method to check the availability of Bluetooth. | |
793 | ||
794 | @return flag indicating the availability of Bluetooth | |
795 | @rtype bool | |
796 | @exception OSError raised to indicate an issue with the device | |
797 | """ | |
798 | if not self.hasCircuitPython(): | |
799 | return False | |
800 | ||
801 | command = """ | |
802 | def has_bt(): | |
803 | try: | |
804 | import _bleio | |
805 | if hasattr(_bleio, 'adapter'): | |
806 | return True | |
807 | except ImportError: | |
808 | pass | |
809 | ||
810 | return False | |
811 | ||
812 | print(has_bt()) | |
813 | del has_bt | |
814 | """ | |
9989 | 815 | out, err = self.executeCommands(command, mode=self._submitMode, timeout=10000) |
9864 | 816 | if err: |
817 | raise OSError(self._shortError(err)) | |
818 | return out.strip() == b"True" | |
819 | ||
820 | def getBluetoothStatus(self): | |
821 | """ | |
822 | Public method to get Bluetooth status data of the connected board. | |
823 | ||
824 | @return list of tuples containing the translated status data label and | |
825 | the associated value | |
826 | @rtype list of tuples of (str, str) | |
827 | @exception OSError raised to indicate an issue with the device | |
828 | """ | |
829 | command = """ | |
830 | def ble_status(): | |
831 | import _bleio | |
832 | ||
833 | def address2str(address): | |
834 | return ':'.join('{0:02x}'.format(x) for x in address) | |
835 | ||
836 | a = _bleio.adapter | |
837 | ||
838 | ble_enabled = a.enabled | |
839 | if not ble_enabled: | |
840 | a.enabled = True | |
841 | ||
842 | res = { | |
843 | 'active': ble_enabled, | |
844 | 'mac': address2str(bytes(reversed(a.address.address_bytes))), | |
845 | 'addr_type': a.address.type, | |
846 | 'name': a.name, | |
847 | 'advertising': a.advertising, | |
848 | 'connected': a.connected, | |
849 | } | |
850 | ||
851 | if not ble_enabled: | |
852 | a.enabled = False | |
853 | ||
854 | print(res) | |
855 | ||
856 | ble_status() | |
857 | del ble_status | |
858 | """ | |
9989 | 859 | out, err = self.executeCommands(command, mode=self._submitMode) |
9864 | 860 | if err: |
861 | raise OSError(self._shortError(err)) | |
862 | ||
863 | status = [] | |
864 | bleStatus = ast.literal_eval(out.decode("utf-8")) | |
865 | status.append((self.tr("Active"), self.bool2str(bleStatus["active"]))) | |
866 | status.append((self.tr("Name"), bleStatus["name"])) | |
867 | status.append((self.tr("MAC-Address"), bleStatus["mac"])) | |
868 | status.append( | |
869 | (self.tr("Address Type"), self.__bleAddressType[bleStatus["addr_type"]]) | |
870 | ) | |
871 | status.append((self.tr("Connected"), self.bool2str(bleStatus["connected"]))) | |
872 | status.append((self.tr("Advertising"), self.bool2str(bleStatus["advertising"]))) | |
873 | ||
874 | return status | |
875 | ||
876 | def activateBluetoothInterface(self): | |
877 | """ | |
878 | Public method to activate the Bluetooth interface. | |
879 | ||
880 | @return flag indicating the new state of the Bluetooth interface | |
881 | @rtype bool | |
882 | @exception OSError raised to indicate an issue with the device | |
883 | """ | |
884 | command = """ | |
885 | def activate_ble(): | |
886 | import _bleio | |
887 | ||
888 | a = _bleio.adapter | |
889 | if not a.enabled: | |
890 | a.enabled = True | |
891 | print(a.enabled) | |
892 | ||
893 | activate_ble() | |
894 | del activate_ble | |
895 | """ | |
9989 | 896 | out, err = self.executeCommands(command, mode=self._submitMode) |
9864 | 897 | if err: |
898 | raise OSError(self._shortError(err)) | |
899 | ||
900 | return out.strip() == b"True" | |
901 | ||
902 | def deactivateBluetoothInterface(self): | |
903 | """ | |
904 | Public method to deactivate the Bluetooth interface. | |
905 | ||
906 | @return flag indicating the new state of the Bluetooth interface | |
907 | @rtype bool | |
908 | @exception OSError raised to indicate an issue with the device | |
909 | """ | |
910 | command = """ | |
911 | def deactivate_ble(): | |
912 | import _bleio | |
913 | ||
914 | a = _bleio.adapter | |
915 | if a.enabled: | |
916 | a.enabled = False | |
917 | print(a.enabled) | |
918 | ||
919 | deactivate_ble() | |
920 | del deactivate_ble | |
921 | """ | |
9989 | 922 | out, err = self.executeCommands(command, mode=self._submitMode) |
9864 | 923 | if err: |
924 | raise OSError(self._shortError(err)) | |
925 | ||
926 | return out.strip() == b"True" | |
927 | ||
928 | def getDeviceScan(self, timeout=10): | |
929 | """ | |
930 | Public method to perform a Bluetooth device scan. | |
931 | ||
932 | @param timeout duration of the device scan in seconds (defaults | |
933 | to 10) | |
934 | @type int (optional) | |
935 | @return tuple containing a dictionary with the scan results and | |
936 | an error string | |
937 | @rtype tuple of (dict, str) | |
938 | """ | |
939 | from ..BluetoothDialogs.BluetoothAdvertisement import ( | |
940 | ADV_IND, | |
941 | ADV_SCAN_IND, | |
942 | SCAN_RSP, | |
943 | BluetoothAdvertisement, | |
944 | ) | |
945 | ||
946 | command = """ | |
947 | def ble_scan(): | |
948 | import _bleio | |
949 | import time | |
950 | ||
951 | def address2str(address): | |
952 | return ':'.join('{{0:02x}}'.format(x) for x in address) | |
953 | ||
954 | a = _bleio.adapter | |
955 | ||
956 | ble_enabled = a.enabled | |
957 | if not ble_enabled: | |
958 | a.enabled = True | |
959 | ||
960 | scanResults = a.start_scan( | |
961 | buffer_size=1024, extended=True, timeout={0}, minimum_rssi=-120, active=True | |
962 | ) | |
10032
102b79b2a8cd
Finetuned the bluetooth scan function for various MicroPython boards.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9989
diff
changeset
|
963 | time.sleep({0} + 0.2) |
9864 | 964 | a.stop_scan() |
965 | ||
966 | for res in scanResults: | |
967 | print({{ | |
968 | 'address': address2str(bytes(reversed(res.address.address_bytes))), | |
969 | 'advertisement': res.advertisement_bytes, | |
970 | 'connectable': res.connectable, | |
971 | 'rssi': res.rssi, | |
972 | 'scan_response': res.scan_response, | |
973 | }}) | |
974 | ||
975 | if not ble_enabled: | |
976 | a.enabled = False | |
977 | ||
978 | ble_scan() | |
979 | del ble_scan | |
980 | """.format( | |
981 | timeout | |
982 | ) | |
9989 | 983 | out, err = self.executeCommands( |
9864 | 984 | command, mode=self._submitMode, timeout=(timeout + 5) * 1000 |
985 | ) | |
986 | if err: | |
987 | return {}, err | |
988 | ||
989 | scanResults = {} | |
990 | for line in out.decode("utf-8").splitlines(): | |
991 | res = ast.literal_eval(line) | |
992 | address = res["address"] | |
993 | if address not in scanResults: | |
994 | scanResults[address] = BluetoothAdvertisement(address) | |
995 | if res["scan_response"]: | |
996 | advType = SCAN_RSP | |
997 | elif res["connectable"]: | |
998 | advType = ADV_IND | |
999 | else: | |
1000 | advType = ADV_SCAN_IND | |
1001 | scanResults[address].update(advType, res["rssi"], res["advertisement"]) | |
1002 | ||
1003 | return scanResults, "" | |
1004 | ||
11167 | 1005 | def supportsDeviceScan(self): |
1006 | """ | |
1007 | Public method to indicate, that the Bluetooth implementation supports | |
1008 | scanning for devices. | |
1009 | ||
1010 | @return flag indicating that the scanning function is supported | |
1011 | @rtype bool | |
1012 | """ | |
1013 | return True | |
1014 | ||
11186
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
1015 | def _boardInformationCommands(self): |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
1016 | """ |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
1017 | Protected method defining the list of commands to be execute on the board |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
1018 | for determining information about the board. |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
1019 | |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
1020 | @return list of command strings to be executed |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
1021 | @rtype list of str |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
1022 | """ |
11189
289c7150ec4b
Corrected some code in the MicrobitDevices module related to CircuitPython.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11186
diff
changeset
|
1023 | if self.hasCircuitPython(): |
289c7150ec4b
Corrected some code in the MicrobitDevices module related to CircuitPython.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11186
diff
changeset
|
1024 | return super()._boardInformationCommands() |
289c7150ec4b
Corrected some code in the MicrobitDevices module related to CircuitPython.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11186
diff
changeset
|
1025 | else: |
289c7150ec4b
Corrected some code in the MicrobitDevices module related to CircuitPython.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11186
diff
changeset
|
1026 | # These are a subset of the generic ones. |
289c7150ec4b
Corrected some code in the MicrobitDevices module related to CircuitPython.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11186
diff
changeset
|
1027 | return [ # needs to be splitted for boards with low memory |
289c7150ec4b
Corrected some code in the MicrobitDevices module related to CircuitPython.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11186
diff
changeset
|
1028 | """def get_board_info(): |
11186
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
1029 | res = {} |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
1030 | |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
1031 | try: |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
1032 | import os |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
1033 | uname = os.uname() |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
1034 | res['sysname'] = uname.sysname |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
1035 | res['nodename'] = uname.nodename |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
1036 | res['release'] = uname.release |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
1037 | res['version'] = uname.version |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
1038 | res['machine'] = uname.machine |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
1039 | except AttributeError: |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
1040 | import sys |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
1041 | res['sysname'] = sys.platform |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
1042 | res['nodename'] = sys.platform |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
1043 | res['release'] = '.'.join(str(v) for v in sys.implementation.version) |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
1044 | res['version'] = sys.version.split(';', 1)[-1].strip() |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
1045 | res['machine'] = sys.implementation._machine |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
1046 | |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
1047 | return res |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
1048 | |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
1049 | print(get_board_info()) |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
1050 | del get_board_info |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
1051 | """, |
11189
289c7150ec4b
Corrected some code in the MicrobitDevices module related to CircuitPython.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11186
diff
changeset
|
1052 | """def get_board_info(): |
11186
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
1053 | res = {} |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
1054 | |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
1055 | import sys |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
1056 | res['py_platform'] = sys.platform |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
1057 | res['py_version'] = sys.version |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
1058 | |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
1059 | try: |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
1060 | res['mpy_name'] = sys.implementation.name |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
1061 | except AttributeError: |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
1062 | res['mpy_name'] = 'unknown' |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
1063 | try: |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
1064 | res['mpy_version'] = '.'.join((str(i) for i in sys.implementation.version)) |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
1065 | except AttributeError: |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
1066 | res['mpy_version'] = 'unknown' |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
1067 | try: |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
1068 | import pimoroni |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
1069 | res['mpy_variant'] = 'Pimoroni Pico' |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
1070 | try: |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
1071 | import version |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
1072 | res['mpy_variant_info'] = version.BUILD |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
1073 | res['mpy_variant_version'] = version.BUILD.split('-')[2][1:] |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
1074 | except ImportError: |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
1075 | res['mpy_variant_info'] = '' |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
1076 | res['mpy_variant_version'] = '' |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
1077 | except ImportError: |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
1078 | res['mpy_variant'] = '' |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
1079 | res['mpy_variant_info'] = '' |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
1080 | res['mpy_variant_version'] = '' |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
1081 | |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
1082 | return res |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
1083 | |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
1084 | print(get_board_info()) |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
1085 | del get_board_info |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
1086 | """, |
11189
289c7150ec4b
Corrected some code in the MicrobitDevices module related to CircuitPython.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11186
diff
changeset
|
1087 | """def get_board_info(): |
11186
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
1088 | res = {} |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
1089 | |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
1090 | try: |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
1091 | import ulab |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
1092 | res['ulab'] = ulab.__version__ |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
1093 | except ImportError: |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
1094 | res['ulab'] = None |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
1095 | |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
1096 | return res |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
1097 | |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
1098 | print(get_board_info()) |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
1099 | del get_board_info |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
1100 | """, |
11189
289c7150ec4b
Corrected some code in the MicrobitDevices module related to CircuitPython.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11186
diff
changeset
|
1101 | # micro:bit specific variants due to missing float support |
289c7150ec4b
Corrected some code in the MicrobitDevices module related to CircuitPython.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11186
diff
changeset
|
1102 | """def get_board_info(): |
11186
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
1103 | res = {} |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
1104 | |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
1105 | import gc |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
1106 | gc.enable() |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
1107 | gc.collect() |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
1108 | mem_alloc = gc.mem_alloc() |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
1109 | mem_free = gc.mem_free() |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
1110 | mem_total = mem_alloc + mem_free |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
1111 | res['mem_total'] = mem_total |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
1112 | res['mem_used'] = mem_alloc |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
1113 | res['mem_free'] = mem_free |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
1114 | del gc, mem_alloc, mem_free, mem_total |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
1115 | |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
1116 | return res |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
1117 | |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
1118 | print(get_board_info()) |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
1119 | del get_board_info |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
1120 | """, |
11189
289c7150ec4b
Corrected some code in the MicrobitDevices module related to CircuitPython.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11186
diff
changeset
|
1121 | """def get_board_info(): |
11186
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
1122 | res = {} |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
1123 | |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
1124 | try: |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
1125 | import os |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
1126 | stat_ = os.statvfs('/flash') |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
1127 | res['flash_info_available'] = True |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
1128 | res['flash_total'] = stat_[2] * stat_[0] |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
1129 | res['flash_free'] = stat_[3] * stat_[0] |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
1130 | except (AttributeError, OSError): |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
1131 | res['flash_info_available'] = False |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
1132 | |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
1133 | return res |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
1134 | |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
1135 | print(get_board_info()) |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
1136 | del get_board_info |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
1137 | """, |
11189
289c7150ec4b
Corrected some code in the MicrobitDevices module related to CircuitPython.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11186
diff
changeset
|
1138 | """def get_board_info(): |
11186
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
1139 | res = {} |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
1140 | |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
1141 | import machine as mc |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
1142 | import microbit as mb |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
1143 | try: |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
1144 | if isinstance(mc.freq(), tuple): |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
1145 | res['mc_frequency'] = mc.freq()[0] |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
1146 | else: |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
1147 | res['mc_frequency'] = mc.freq() |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
1148 | except NotImplementedError: |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
1149 | res['mc_frequency'] = None |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
1150 | try: |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
1151 | res['mc_temp_c'] = mc.Temp().read() |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
1152 | except AttributeError: |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
1153 | try: |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
1154 | res['mc_temp_c'] = mb.temperature() * 100 |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
1155 | except AttributeError: |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
1156 | res['mc_temp_c'] = None |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
1157 | res['mc_id'] = mc.unique_id() |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
1158 | if 'mc_id' in res: |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
1159 | res['mc_id'] = ':'.join('{0:02X}'.format(x) for x in res['mc_id']) |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
1160 | else: |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
1161 | res['mc_id'] = None |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
1162 | |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
1163 | return res |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
1164 | |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
1165 | print(get_board_info()) |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
1166 | del get_board_info |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
1167 | """, |
11189
289c7150ec4b
Corrected some code in the MicrobitDevices module related to CircuitPython.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11186
diff
changeset
|
1168 | ] |
9496
05017f795c24
Changed MicroPython device imports to use importlib.import_module().
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9473
diff
changeset
|
1169 | |
11177
f511038a0061
Corrected some issues related to controllers with small RAM and limited numbers support (i.e. BBC micro:bit and Calliope mini).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11167
diff
changeset
|
1170 | def getBoardInformation(self): |
f511038a0061
Corrected some issues related to controllers with small RAM and limited numbers support (i.e. BBC micro:bit and Calliope mini).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11167
diff
changeset
|
1171 | """ |
f511038a0061
Corrected some issues related to controllers with small RAM and limited numbers support (i.e. BBC micro:bit and Calliope mini).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11167
diff
changeset
|
1172 | Public method to get some information data of the connected board. |
f511038a0061
Corrected some issues related to controllers with small RAM and limited numbers support (i.e. BBC micro:bit and Calliope mini).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11167
diff
changeset
|
1173 | |
f511038a0061
Corrected some issues related to controllers with small RAM and limited numbers support (i.e. BBC micro:bit and Calliope mini).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11167
diff
changeset
|
1174 | @return dictionary containing the determined data |
f511038a0061
Corrected some issues related to controllers with small RAM and limited numbers support (i.e. BBC micro:bit and Calliope mini).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11167
diff
changeset
|
1175 | @rtype dict |
f511038a0061
Corrected some issues related to controllers with small RAM and limited numbers support (i.e. BBC micro:bit and Calliope mini).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11167
diff
changeset
|
1176 | """ |
f511038a0061
Corrected some issues related to controllers with small RAM and limited numbers support (i.e. BBC micro:bit and Calliope mini).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11167
diff
changeset
|
1177 | res = super().getBoardInformation() |
11186
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
1178 | |
11189
289c7150ec4b
Corrected some code in the MicrobitDevices module related to CircuitPython.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11186
diff
changeset
|
1179 | if not self.hasCircuitPython(): |
289c7150ec4b
Corrected some code in the MicrobitDevices module related to CircuitPython.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11186
diff
changeset
|
1180 | # post-process the results to determine the right float entries |
11186
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
1181 | |
11189
289c7150ec4b
Corrected some code in the MicrobitDevices module related to CircuitPython.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11186
diff
changeset
|
1182 | # 1. memory |
289c7150ec4b
Corrected some code in the MicrobitDevices module related to CircuitPython.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11186
diff
changeset
|
1183 | res["mem_total_kb"] = res["mem_total"] / 1024.0 |
289c7150ec4b
Corrected some code in the MicrobitDevices module related to CircuitPython.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11186
diff
changeset
|
1184 | res["mem_used_kb"] = res["mem_used"] / 1024.0 |
289c7150ec4b
Corrected some code in the MicrobitDevices module related to CircuitPython.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11186
diff
changeset
|
1185 | res["mem_used_pc"] = res["mem_used"] / res["mem_total"] * 100.0 |
289c7150ec4b
Corrected some code in the MicrobitDevices module related to CircuitPython.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11186
diff
changeset
|
1186 | res["mem_free_kb"] = res["mem_free"] / 1024.0 |
289c7150ec4b
Corrected some code in the MicrobitDevices module related to CircuitPython.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11186
diff
changeset
|
1187 | res["mem_free_pc"] = res["mem_free"] / res["mem_total"] * 100.0 |
11186
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
1188 | |
11189
289c7150ec4b
Corrected some code in the MicrobitDevices module related to CircuitPython.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11186
diff
changeset
|
1189 | # 2. flash |
289c7150ec4b
Corrected some code in the MicrobitDevices module related to CircuitPython.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11186
diff
changeset
|
1190 | if res["flash_info_available"]: |
289c7150ec4b
Corrected some code in the MicrobitDevices module related to CircuitPython.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11186
diff
changeset
|
1191 | res["flash_total_kb"] = res["flash_total"] / 1024.0 |
289c7150ec4b
Corrected some code in the MicrobitDevices module related to CircuitPython.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11186
diff
changeset
|
1192 | res["flash_free_kb"] = res["flash_free"] / 1024.0 |
289c7150ec4b
Corrected some code in the MicrobitDevices module related to CircuitPython.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11186
diff
changeset
|
1193 | res["flash_used_kb"] = res["flash_total_kb"] - res["flash_free_kb"] |
289c7150ec4b
Corrected some code in the MicrobitDevices module related to CircuitPython.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11186
diff
changeset
|
1194 | res["flash_free_pc"] = ( |
289c7150ec4b
Corrected some code in the MicrobitDevices module related to CircuitPython.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11186
diff
changeset
|
1195 | res["flash_free_kb"] / res["flash_total_kb"] * 100.0 |
289c7150ec4b
Corrected some code in the MicrobitDevices module related to CircuitPython.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11186
diff
changeset
|
1196 | ) |
289c7150ec4b
Corrected some code in the MicrobitDevices module related to CircuitPython.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11186
diff
changeset
|
1197 | res["flash_used_pc"] = ( |
289c7150ec4b
Corrected some code in the MicrobitDevices module related to CircuitPython.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11186
diff
changeset
|
1198 | res["flash_used_kb"] / res["flash_total_kb"] * 100.0 |
289c7150ec4b
Corrected some code in the MicrobitDevices module related to CircuitPython.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11186
diff
changeset
|
1199 | ) |
11186
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
1200 | |
11189
289c7150ec4b
Corrected some code in the MicrobitDevices module related to CircuitPython.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11186
diff
changeset
|
1201 | # 3. machine |
289c7150ec4b
Corrected some code in the MicrobitDevices module related to CircuitPython.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11186
diff
changeset
|
1202 | res["mc_frequency_mhz"] = ( |
289c7150ec4b
Corrected some code in the MicrobitDevices module related to CircuitPython.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11186
diff
changeset
|
1203 | res["mc_frequency"] / 1000000.0 |
289c7150ec4b
Corrected some code in the MicrobitDevices module related to CircuitPython.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11186
diff
changeset
|
1204 | if res["mc_frequency"] is not None |
289c7150ec4b
Corrected some code in the MicrobitDevices module related to CircuitPython.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11186
diff
changeset
|
1205 | else None |
289c7150ec4b
Corrected some code in the MicrobitDevices module related to CircuitPython.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11186
diff
changeset
|
1206 | ) |
289c7150ec4b
Corrected some code in the MicrobitDevices module related to CircuitPython.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11186
diff
changeset
|
1207 | with contextlib.suppress(KeyError): |
289c7150ec4b
Corrected some code in the MicrobitDevices module related to CircuitPython.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11186
diff
changeset
|
1208 | if res["mc_temp_c"] is not None: |
289c7150ec4b
Corrected some code in the MicrobitDevices module related to CircuitPython.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11186
diff
changeset
|
1209 | res["mc_temp_c"] = ( |
289c7150ec4b
Corrected some code in the MicrobitDevices module related to CircuitPython.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11186
diff
changeset
|
1210 | res["mc_temp_c"] / 100 |
289c7150ec4b
Corrected some code in the MicrobitDevices module related to CircuitPython.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11186
diff
changeset
|
1211 | ) # due to integer support only |
11177
f511038a0061
Corrected some issues related to controllers with small RAM and limited numbers support (i.e. BBC micro:bit and Calliope mini).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11167
diff
changeset
|
1212 | |
f511038a0061
Corrected some issues related to controllers with small RAM and limited numbers support (i.e. BBC micro:bit and Calliope mini).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11167
diff
changeset
|
1213 | return res |
f511038a0061
Corrected some issues related to controllers with small RAM and limited numbers support (i.e. BBC micro:bit and Calliope mini).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11167
diff
changeset
|
1214 | |
11186
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
1215 | def isMicrobit(self): |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
1216 | """ |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
1217 | Public method to check, if the device is a BBC micro:bit or Calliope mini. |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
1218 | |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
1219 | @return flag indicating a micro:bit device |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
1220 | @rtype bool |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
1221 | """ |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
1222 | if ( |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
1223 | ("micro:bit" in self.deviceName() or "Calliope" in self.deviceName()) |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
1224 | and not self.hasCircuitPython() |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
1225 | and not self.supportsDirectories() |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
1226 | ): |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
1227 | return True |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
1228 | |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
1229 | return False |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
1230 | |
11177
f511038a0061
Corrected some issues related to controllers with small RAM and limited numbers support (i.e. BBC micro:bit and Calliope mini).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11167
diff
changeset
|
1231 | |
10683
779cda568acb
Changed the source code and the source code documentation to improve the indication of unused method/function arguments.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10512
diff
changeset
|
1232 | def createDevice(microPythonWidget, deviceType, _vid, _pid, _boardName, serialNumber): |
9496
05017f795c24
Changed MicroPython device imports to use importlib.import_module().
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9473
diff
changeset
|
1233 | """ |
05017f795c24
Changed MicroPython device imports to use importlib.import_module().
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9473
diff
changeset
|
1234 | Function to instantiate a MicroPython device object. |
05017f795c24
Changed MicroPython device imports to use importlib.import_module().
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9473
diff
changeset
|
1235 | |
05017f795c24
Changed MicroPython device imports to use importlib.import_module().
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9473
diff
changeset
|
1236 | @param microPythonWidget reference to the main MicroPython widget |
05017f795c24
Changed MicroPython device imports to use importlib.import_module().
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9473
diff
changeset
|
1237 | @type MicroPythonWidget |
05017f795c24
Changed MicroPython device imports to use importlib.import_module().
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9473
diff
changeset
|
1238 | @param deviceType device type assigned to this device interface |
05017f795c24
Changed MicroPython device imports to use importlib.import_module().
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9473
diff
changeset
|
1239 | @type str |
10683
779cda568acb
Changed the source code and the source code documentation to improve the indication of unused method/function arguments.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10512
diff
changeset
|
1240 | @param _vid vendor ID (unused) |
9496
05017f795c24
Changed MicroPython device imports to use importlib.import_module().
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9473
diff
changeset
|
1241 | @type int |
10683
779cda568acb
Changed the source code and the source code documentation to improve the indication of unused method/function arguments.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10512
diff
changeset
|
1242 | @param _pid product ID (unused) |
9496
05017f795c24
Changed MicroPython device imports to use importlib.import_module().
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9473
diff
changeset
|
1243 | @type int |
10683
779cda568acb
Changed the source code and the source code documentation to improve the indication of unused method/function arguments.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10512
diff
changeset
|
1244 | @param _boardName name of the board (unused) |
9738 | 1245 | @type str |
9751
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9750
diff
changeset
|
1246 | @param serialNumber serial number of the board |
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9750
diff
changeset
|
1247 | @type str |
9496
05017f795c24
Changed MicroPython device imports to use importlib.import_module().
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9473
diff
changeset
|
1248 | @return reference to the instantiated device object |
05017f795c24
Changed MicroPython device imports to use importlib.import_module().
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9473
diff
changeset
|
1249 | @rtype MicrobitDevice |
05017f795c24
Changed MicroPython device imports to use importlib.import_module().
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9473
diff
changeset
|
1250 | """ |
9751
606ac0e26533
Various enhancements and improvements to the MicroPython/CircuitPython related modules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9750
diff
changeset
|
1251 | return MicrobitDevice(microPythonWidget, deviceType, serialNumber) |
11186
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
1252 | |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
1253 | |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
1254 | # |
c2d18aefef6b
Corrected some issues in the 'micro:bit' device class and enhanced the MPy file manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11177
diff
changeset
|
1255 | # eflag: noqa = M-613 |