eric7.MicroPython.Devices.MicrobitDevices
Module implementing the device interface class for BBC micro:bit and
Calliope mini boards.
Global Attributes
Classes
MicrobitDevice |
Class implementing the device for BBC micro:bit and Calliope mini boards. |
Functions
createDevice |
Function to instantiate a MicroPython device object. |
MicrobitDevice
Class implementing the device for BBC micro:bit and Calliope mini boards.
Derived from
BaseDevice
Class Attributes
Class Methods
Methods
MicrobitDevice |
Constructor |
__createMicrobitMenu |
Private method to create the microbit submenu. |
__firmwareVersionResponse |
Private slot handling the response of the latest version request. |
__flashMicroPython |
Private slot to flash MicroPython or the DAPLink firmware to the device. |
__isCalliope |
Private method to check, if the device is a Calliope mini. |
__isMicroBitV1 |
Private method to check, if the device is a BBC micro:bit v1. |
__isMicroBitV2 |
Private method to check, if the device is a BBC micro:bit v2. |
__resetDevice |
Private slot to reset the connected device. |
__saveMain |
Private slot to copy the current script as 'main.py' onto the connected device. |
__showFirmwareVersions |
Private slot to show the firmware version of the connected device and the available firmware version. |
_getSetTimeCode |
Protected method to get the device code to set the time. |
activateBluetoothInterface |
Public method to activate the Bluetooth interface. |
addDeviceMenuEntries |
Public method to add device specific entries to the given menu. |
canRunScript |
Public method to determine, if a script can be executed. |
canStartFileManager |
Public method to determine, if a File Manager can be started. |
canStartPlotter |
Public method to determine, if a Plotter can be started. |
canStartRepl |
Public method to determine, if a REPL can be started. |
deactivateBluetoothInterface |
Public method to deactivate the Bluetooth interface. |
deviceName |
Public method to get the name of the device. |
forceInterrupt |
Public method to determine the need for an interrupt when opening the serial connection. |
getBluetoothStatus |
Public method to get Bluetooth status data of the connected board. |
getDeviceScan |
Public method to perform a Bluetooth device scan. |
getDocumentationUrl |
Public method to get the device documentation URL. |
getDownloadMenuEntries |
Public method to retrieve the entries for the downloads menu. |
hasBluetooth |
Public method to check the availability of Bluetooth. |
hasFlashMenuEntry |
Public method to check, if the device has its own flash menu entry. |
hasTimeCommands |
Public method to check, if the device supports time commands. |
lls |
Public method to get a long directory listing of the connected device including meta data. |
ls |
Public method to get a directory listing of the connected device. |
pwd |
Public method to get the current directory of the connected device. |
runScript |
Public method to run the given Python script. |
setButtons |
Public method to enable the supported action buttons. |
setConnected |
Public method to set the connection state. |
Static Methods
MicrobitDevice (Constructor)
MicrobitDevice(microPythonWidget, deviceType, serialNumber, parent=None)
Constructor
- microPythonWidget (MicroPythonWidget)
-
reference to the main MicroPython widget
- deviceType (str)
-
type of the device
- serialNumber (str)
-
serial number of the board
- parent (QObject)
-
reference to the parent object
MicrobitDevice.__createMicrobitMenu
__createMicrobitMenu()
Private method to create the microbit submenu.
MicrobitDevice.__firmwareVersionResponse
__firmwareVersionResponse(reply)
Private slot handling the response of the latest version request.
- reply (QNetworkReply)
-
reference to the reply object
MicrobitDevice.__flashMicroPython
__flashMicroPython(firmware=False)
Private slot to flash MicroPython or the DAPLink firmware to the
device.
- firmware (bool)
-
flag indicating to flash the DAPLink firmware
MicrobitDevice.__isCalliope
__isCalliope()
Private method to check, if the device is a Calliope mini.
- Return:
-
flag indicating a Calliope mini
- Return Type:
-
bool
MicrobitDevice.__isMicroBitV1
__isMicroBitV1()
Private method to check, if the device is a BBC micro:bit v1.
- Return:
-
falg indicating a BBC micro:bit v1
- Return Type:
-
bool
MicrobitDevice.__isMicroBitV2
__isMicroBitV2()
Private method to check, if the device is a BBC micro:bit v2.
- Return:
-
falg indicating a BBC micro:bit v2
- Return Type:
-
bool
MicrobitDevice.__resetDevice
__resetDevice()
Private slot to reset the connected device.
MicrobitDevice.__saveMain
__saveMain()
Private slot to copy the current script as 'main.py' onto the
connected device.
MicrobitDevice.__showFirmwareVersions
__showFirmwareVersions()
Private slot to show the firmware version of the connected device and the
available firmware version.
MicrobitDevice._getSetTimeCode
_getSetTimeCode()
Protected method to get the device code to set the time.
Note: This method must be implemented in the various device specific
subclasses.
- Return:
-
code to be executed on the connected device to set the time
- Return Type:
-
str
MicrobitDevice.activateBluetoothInterface
activateBluetoothInterface()
Public method to activate the Bluetooth interface.
- Return:
-
flag indicating the new state of the Bluetooth interface
- Return Type:
-
bool
- Raises OSError:
-
raised to indicate an issue with the device
MicrobitDevice.addDeviceMenuEntries
addDeviceMenuEntries(menu)
Public method to add device specific entries to the given menu.
- menu (QMenu)
-
reference to the context menu
MicrobitDevice.canRunScript
canRunScript()
Public method to determine, if a script can be executed.
- Return:
-
tuple containing a flag indicating it is safe to start a
Plotter and a reason why it cannot.
- Return Type:
-
tuple of (bool, str)
MicrobitDevice.canStartFileManager
canStartFileManager()
Public method to determine, if a File Manager can be started.
- Return:
-
tuple containing a flag indicating it is safe to start a
File Manager and a reason why it cannot.
- Return Type:
-
tuple of (bool, str)
MicrobitDevice.canStartPlotter
canStartPlotter()
Public method to determine, if a Plotter can be started.
- Return:
-
tuple containing a flag indicating it is safe to start a
Plotter and a reason why it cannot.
- Return Type:
-
tuple of (bool, str)
MicrobitDevice.canStartRepl
canStartRepl()
Public method to determine, if a REPL can be started.
- Return:
-
tuple containing a flag indicating it is safe to start a REPL
and a reason why it cannot.
- Return Type:
-
tuple of (bool, str)
MicrobitDevice.deactivateBluetoothInterface
deactivateBluetoothInterface()
Public method to deactivate the Bluetooth interface.
- Return:
-
flag indicating the new state of the Bluetooth interface
- Return Type:
-
bool
- Raises OSError:
-
raised to indicate an issue with the device
MicrobitDevice.deviceName
deviceName()
Public method to get the name of the device.
- Return:
-
name of the device
- Return Type:
-
str
MicrobitDevice.forceInterrupt
forceInterrupt()
Public method to determine the need for an interrupt when opening the
serial connection.
- Return:
-
flag indicating an interrupt is needed
- Return Type:
-
bool
MicrobitDevice.getBluetoothStatus
getBluetoothStatus()
Public method to get Bluetooth status data of the connected board.
- Return:
-
list of tuples containing the translated status data label and
the associated value
- Return Type:
-
list of tuples of (str, str)
- Raises OSError:
-
raised to indicate an issue with the device
MicrobitDevice.getDeviceScan
getDeviceScan(timeout=10)
Public method to perform a Bluetooth device scan.
- timeout (int (optional))
-
duration of the device scan in seconds (defaults
to 10)
- Return:
-
tuple containing a dictionary with the scan results and
an error string
- Return Type:
-
tuple of (dict, str)
MicrobitDevice.getDocumentationUrl
getDocumentationUrl()
Public method to get the device documentation URL.
- Return:
-
documentation URL of the device
- Return Type:
-
str
MicrobitDevice.getDownloadMenuEntries
getDownloadMenuEntries()
Public method to retrieve the entries for the downloads menu.
- Return:
-
list of tuples with menu text and URL to be opened for each
entry
- Return Type:
-
list of tuple of (str, str)
MicrobitDevice.hasBluetooth
hasBluetooth()
Public method to check the availability of Bluetooth.
- Return:
-
flag indicating the availability of Bluetooth
- Return Type:
-
bool
- Raises OSError:
-
raised to indicate an issue with the device
MicrobitDevice.hasFlashMenuEntry
hasFlashMenuEntry()
Public method to check, if the device has its own flash menu entry.
- Return:
-
flag indicating a specific flash menu entry
- Return Type:
-
bool
MicrobitDevice.hasTimeCommands
hasTimeCommands()
Public method to check, if the device supports time commands.
The default returns True.
- Return:
-
flag indicating support for time commands
- Return Type:
-
bool
MicrobitDevice.lls
lls(dirname="", fullstat=False, showHidden=False)
Public method to get a long directory listing of the connected device
including meta data.
- dirname (str)
-
name of the directory to be listed
- fullstat (bool)
-
flag indicating to return the full stat() tuple
- showHidden (bool)
-
flag indicating to show hidden files as well
- Return:
-
list containing the directory listing with tuple entries of
the name and and a tuple of mode, size and time (if fullstat is
false) or the complete stat() tuple. 'None' is returned in case the
directory doesn't exist.
- Return Type:
-
tuple of (str, tuple)
- Raises OSError:
-
raised to indicate an issue with the device
MicrobitDevice.ls
ls(dirname="")
Public method to get a directory listing of the connected device.
- dirname (str)
-
name of the directory to be listed
- Return:
-
tuple containg the directory listing
- Return Type:
-
tuple of str
- Raises OSError:
-
raised to indicate an issue with the device
MicrobitDevice.pwd
pwd()
Public method to get the current directory of the connected device.
- Return:
-
current directory
- Return Type:
-
str
MicrobitDevice.runScript
runScript(script)
Public method to run the given Python script.
- script (str)
-
script to be executed
MicrobitDevice.setButtons
setButtons()
Public method to enable the supported action buttons.
MicrobitDevice.setConnected
setConnected(connected)
Public method to set the connection state.
Note: This method can be overwritten to perform actions upon connect
or disconnect of the device.
- connected (bool)
-
connection state
createDevice
createDevice(microPythonWidget, deviceType, _vid, _pid, _boardName, serialNumber)
Function to instantiate a MicroPython device object.
- microPythonWidget (MicroPythonWidget)
-
reference to the main MicroPython widget
- deviceType (str)
-
device type assigned to this device interface
- _vid (int)
-
vendor ID (unused)
- _pid (int)
-
product ID (unused)
- _boardName (str)
-
name of the board (unused)
- serialNumber (str)
-
serial number of the board
- Return:
-
reference to the instantiated device object
- Return Type:
-
MicrobitDevice