def compatible_board(self, port): """Use adafruit_board_toolkit to find out whether a board is running CircuitPython. The toolkit sees if the CDC Interface name is appropriate. """ pid = port.productIdentifier() vid = port.vendorIdentifier() manufacturer = port.manufacturer() serial_number = port.serialNumber() port_name = self.port_path(port.portName()) # Find all the CircuitPython REPL comports, # and see if any of their device names match the one passed in. for comport in circuitpython_serial.repl_comports(): if comport.device == port_name: return Device( vid, pid, port_name, serial_number, manufacturer, self.name, self.short_name, "CircuitPython board", ) # No match. return None
def compatible_board(self, port): """ A compatible board must match on vendor ID, but only needs to match on product ID or manufacturer ID, if they are supplied in the list of valid boards (aren't None). """ pid = port.productIdentifier() vid = port.vendorIdentifier() manufacturer = port.manufacturer() serial_number = port.serialNumber() port_name = self.port_path(port.portName()) for v, p, m, device_name in self.valid_boards: if (v == vid and (p == pid or p is None) and (m == manufacturer or m is None)): return Device( vid, pid, port_name, serial_number, manufacturer, self.name, self.short_name, device_name, ) return None
def test_micropython_mode_find_device_darwin_remove_extraneous_devices(): """ Check that if on OS X, only one version of the same device is shown, as OS X shows every device on two different ports. """ editor = mock.MagicMock() view = mock.MagicMock() mm = MicroPythonMode(editor, view) mm.valid_boards = [(0x0D28, 0x0204, None, "micro:bit")] mock_port = mock.MagicMock() mock_port.portName = mock.MagicMock(return_value="tty.usbserial-XXX") mock_port.productIdentifier = mock.MagicMock(return_value=0x0204) mock_port.vendorIdentifier = mock.MagicMock(return_value=0x0D28) mock_port.serialNumber = mock.MagicMock(return_value="123456") mock_port2 = mock.MagicMock() mock_port2.portName = mock.MagicMock(return_value="cu.usbserial-XXX") mock_port2.productIdentifier = mock.MagicMock(return_value=0x0204) mock_port2.vendorIdentifier = mock.MagicMock(return_value=0x0D28) mock_port2.serialNumber = mock.MagicMock(return_value="123456") device = Device( mock_port2.vendorIdentifier(), mock_port2.productIdentifier(), "/dev/" + mock_port2.portName(), mock_port2.serialNumber(), "ARM", "BBC micro:bit", "microbit", None, ) with mock.patch("sys.platform", "darwin"), mock.patch("os.name", "posix"), mock.patch( "mu.modes.base.QSerialPortInfo.availablePorts", return_value=[mock_port, mock_port2], ): assert mm.find_devices() == [device]
def test_micropython_mode_find_device(): """ Ensure it's possible to detect a device and return the expected port. """ editor = mock.MagicMock() view = mock.MagicMock() mm = MicroPythonMode(editor, view) mock_port = mock.MagicMock() for vid, pid, manufacturer, board_name in mm.valid_boards: mock_port.vid = vid mock_port.productIdentifier = mock.MagicMock(return_value=pid) mock_port.vendorIdentifier = mock.MagicMock(return_value=vid) mock_port.manufacturer = mock.MagicMock(return_value=manufacturer) mock_port.portName = mock.MagicMock(return_value="COM0") mock_port.serialNumber = mock.MagicMock(return_value="12345") mock_os = mock.MagicMock() mock_os.name = "nt" mock_sys = mock.MagicMock() mock_sys.platform = "win32" device = Device( mock_port.vendorIdentifier(), mock_port.productIdentifier(), mock_port.portName(), mock_port.serialNumber(), "micro:bit", board_name, None, ) with mock.patch( "mu.modes.base.QSerialPortInfo.availablePorts", return_value=[mock_port], ), mock.patch("mu.modes.base.os", mock_os), mock.patch("mu.modes.base.sys", mock_sys): assert mm.find_devices() == [device]
def sparkfunESP32(): return Device( 0x0403, 0x6015, "COM0", "123456", "Sparkfun ESP32 Thing", "ESP MicroPython", "esp", )
def snek_device(): return Device(0x0403, 0x6001, "COM0", "123456", "Snek", "Snekboard", "snek")
def microbit_incompatible(): # Board ID not valid for a micro:bit board return Device(0x0D28, 0x0204, "COM0", "99AA1234", "ARM", "BBC micro:bit", "microbit")
def microbit_v1_5(): # Board ID in Serial Number for micro:bit v1.5 return Device(0x0D28, 0x0204, "COM10", "9901ABCD", "ARM", "BBC micro:bit", "microbit")
def microbit(): # Board ID in Serial Number for micro:bit v1.3 and v1.3B return Device(0x0D28, 0x0204, "COM0", "9900ABCD", "ARM", "BBC micro:bit", "microbit")
def microbit(): return Device(0x0D28, 0x0204, "COM0", "123456", "ARM", "BBC micro:bit", "microbit")
def microbit_old_firmware(): return Device( 0x0D28, 0x0204, "COM0", "990112345", "ARM", "BBC micro:bit", "microbit" )