21 SupportedBoards = { |
21 SupportedBoards = { |
22 "esp": { |
22 "esp": { |
23 "ids": [ |
23 "ids": [ |
24 (0x1A86, 0x7523), # HL-340 |
24 (0x1A86, 0x7523), # HL-340 |
25 (0x10C4, 0xEA60), # CP210x |
25 (0x10C4, 0xEA60), # CP210x |
26 (0x0403, 0x6015), # Sparkfun ESP32 VID, PID |
26 (0x0403, 0x6015), # Sparkfun ESP32 |
27 ], |
27 ], |
28 "description": "ESP8266, ESP32", |
28 "description": "ESP8266, ESP32", |
29 "icon": "esp32Device", |
29 "icon": "esp32Device", |
30 }, |
30 }, |
31 |
31 |
32 "adafruit": { |
32 "circuitpython": { |
33 "ids": [ |
33 "ids": [ |
34 (0x239A, 0x8015), # Adafruit Feather M0 CircuitPython |
|
35 (0x239A, 0x8023), # Adafruit Feather M0 Express CircuitPython |
|
36 (0x239A, 0x801B), # Adafruit Feather M0 Express CircuitPython |
|
37 (0x239A, 0x8014), # Adafruit Metro M0 CircuitPython |
|
38 (0x239A, 0x8019), # Adafruit CircuitPlayground |
|
39 # Express CircuitPython |
|
40 (0x239A, 0x801D), # Adafruit Gemma M0 |
|
41 (0x239A, 0x801F), # Adafruit Trinket M0 |
|
42 (0x239A, 0x8012), # Adafruit ItsyBitsy M0 |
|
43 (0x239A, 0x8021), # Adafruit Metro M4 |
|
44 (0x239A, 0x8025), # Adafruit Feather RadioFruit |
|
45 (0x239A, 0x8026), # Adafruit Feather M4 |
|
46 (0x239A, 0x8028), # Adafruit pIRKey M0 |
|
47 (0x239A, 0x802A), # Adafruit Feather 52840 |
|
48 (0x239A, 0x802C), # Adafruit Itsy M4 |
|
49 (0x239A, 0x802E), # Adafruit CRICKit M0 |
|
50 (0x239A, 0xD1ED), # Adafruit HalloWing M0 |
|
51 (0x239A, 0x8030), # Adafruit NeoTrellis M4 |
|
52 (0x239A, 0x8032), # Grand Central |
|
53 (0x2B04, 0xC00C), # Particle Argon |
34 (0x2B04, 0xC00C), # Particle Argon |
54 (0x2B04, 0xC00D), # Particle Boron |
35 (0x2B04, 0xC00D), # Particle Boron |
55 (0x2B04, 0xC00E), # Particle Xenon |
36 (0x2B04, 0xC00E), # Particle Xenon |
56 (0x239A, 0x8034), # future board |
|
57 (0x239A, 0x8036), # future board |
|
58 (0x239A, 0x8038), # future board |
|
59 (0x239A, 0x803A), # future board |
|
60 (0x239A, 0x803C), # future board |
|
61 (0x239A, 0x803E), # future board |
|
62 (0x239A, None), # Any Adafruit Boards |
37 (0x239A, None), # Any Adafruit Boards |
|
38 (0x1209, 0xBAB1), # Electronic Cats Meow Meow |
|
39 (0x1209, 0xBAB2), # Electronic Cats CatWAN USBStick |
|
40 (0x1209, 0xBAB3), # Electronic Cats Bast Pro Mini M0 |
|
41 (0x1B4F, 0x8D22), # SparkFun SAMD21 Mini Breakout |
|
42 (0x1B4F, 0x8D23), # SparkFun SAMD21 Dev Breakout |
|
43 (0x1209, 0x2017), # Mini SAM M4 |
|
44 (0x1209, 0x7102), # Mini SAM M0 |
63 ], |
45 ], |
64 "description": "Adafruit CircuitPython", |
46 "description": "CircuitPython Boards", |
65 "icon": "adafruitDevice", |
47 "icon": "adafruitDevice", |
66 }, |
48 }, |
67 |
49 |
68 "bbc_microbit": { |
50 "bbc_microbit": { |
69 "ids": [ |
51 "ids": [ |
70 (0x0D28, 0x0204), # micro:bit USB VID, PID |
52 (0x0D28, 0x0204), # micro:bit |
71 ], |
53 ], |
72 "description": "BBC micro:bit", |
54 "description": "BBC micro:bit", |
73 "icon": "microbitDevice", |
55 "icon": "microbitDevice", |
74 }, |
56 }, |
75 } |
57 } |
140 return UI.PixmapCache.getIcon(iconName) |
122 return UI.PixmapCache.getIcon(iconName) |
141 else: |
123 else: |
142 return UI.PixmapCache.getPixmap(iconName) |
124 return UI.PixmapCache.getPixmap(iconName) |
143 |
125 |
144 |
126 |
145 def getDevice(deviceType): |
127 def getDevice(deviceType, microPythonWidget): |
146 """ |
128 """ |
147 Public method to instantiate a specific MicroPython device interface. |
129 Public method to instantiate a specific MicroPython device interface. |
148 |
130 |
149 @param deviceType type of the device interface |
131 @param deviceType type of the device interface |
150 @type str |
132 @type str |
|
133 @param microPythonWidget reference to the main MicroPython widget |
|
134 @type MicroPythonReplWidget |
151 @return instantiated device interface |
135 @return instantiated device interface |
152 @rtype MicroPythonDevice |
136 @rtype MicroPythonDevice |
153 """ |
137 """ |
154 # TODO: not implemented yet |
138 # TODO: not implemented yet |
155 return None |
139 return MicroPythonDevice(microPythonWidget) |
156 |
140 |
157 |
141 |
158 class MicroPythonDevice(QObject): |
142 class MicroPythonDevice(QObject): |
159 """ |
143 """ |
160 Base class for the more specific MicroPython devices. |
144 Base class for the more specific MicroPython devices. |
161 """ |
145 """ |
162 def __init__(self, parent=None): |
146 def __init__(self, microPythonWidget, parent=None): |
163 """ |
147 """ |
164 Constructor |
148 Constructor |
165 |
149 |
|
150 @param microPythonWidget reference to the main MicroPython widget |
|
151 @type MicroPythonReplWidget |
166 @param parent reference to the parent object |
152 @param parent reference to the parent object |
167 @type QObject |
153 @type QObject |
168 """ |
154 """ |
169 super(MicroPythonDevice, self).__init__(parent) |
155 super(MicroPythonDevice, self).__init__(parent) |
170 |
156 |
171 def supportedActions(self): |
157 self.__microPython = microPythonWidget |
172 """ |
158 |
173 Public method to get the names of the supported actions. |
159 def setButtons(self): |
174 |
160 """ |
175 @return tuple of supported actions out of "repl", "run", "files", |
161 Public method to enable the supported action buttons. |
176 "chart" |
162 """ |
177 @rtype tuple of str |
163 self.__microPython.setActionButtons( |
178 """ |
164 run=False, repl=False, files=False, chart=False) |
179 return tuple() |
165 |
180 |
166 def forceInterrupt(self): |
181 def findDevice(self, deviceType): |
167 """ |
182 """ |
168 Public method to determine the need for an interrupt when opening the |
183 Public method to find the first device of a specific type. |
169 serial connection. |
184 |
170 |
185 @param deviceType device type |
171 @return flag indicating an interrupt is needed |
186 @type str |
172 @rtype bool |
187 @return tuple containing the port the device is connected to and its |
173 """ |
188 serial number |
174 return True |
189 @rtype tuple of (str, str) |
175 |
190 """ |
176 def canStartRepl(self): |
191 from PyQt5.QtSerialPort import QSerialPortInfo |
177 """ |
192 |
178 Public method to determine, if a REPL can be started. |
193 availablePorts = QSerialPortInfo.availablePorts() |
179 |
194 for port in availablePorts: |
180 @return tuple containing a flag indicating it is safe to start a REPL |
195 vid = port.vendorIdentifier() |
181 and a reason why it cannot. |
196 pid = port.productIdentifier() |
182 """ |
197 for board in SupportedBoards: |
183 return False, self.tr("Not implemented") |
198 if ((vid, pid) in SupportedBoards[board] or |
184 |
199 (vid, None) in SupportedBoards[board]): |
185 def setRepl(self, on): |
200 portName = port.portName() |
186 """ |
201 serialNumber = port.serialNumber() |
187 Public method to set the REPL status and dependent status. |
202 return (self.__portPath(portName), serialNumber) |
188 |
203 |
189 @param on flag indicating the active status |
204 return (None, None) |
190 @type bool |
205 |
191 """ |
206 def __portPath(self, portName): |
192 return |
207 """ |
193 |
208 Private method to get the full path of a given port. |
194 def getWorkspace(self): |
209 |
195 """ |
210 @param portName name of the port the path shall be determined for |
196 Public method to get the workspace directory. |
211 @type str |
197 |
212 @return full port path |
198 @return workspace directory used for saving files |
213 @rtype str |
199 @rtype str |
214 """ |
200 """ |
215 if Globals.isWindowsPlatform(): |
201 return "" |
216 # return name unchanged |
202 |
217 return portName |
203 # TODO: are these needed? |
218 else: |
204 ## def findDevice(self, deviceType): |
219 # assume Posix system (Linux or macOS) |
205 ## """ |
220 return "/dev/{0}".format(portName) |
206 ## Public method to find the first device of a specific type. |
|
207 ## |
|
208 ## @param deviceType device type |
|
209 ## @type str |
|
210 ## @return tuple containing the port the device is connected to and its |
|
211 ## serial number |
|
212 ## @rtype tuple of (str, str) |
|
213 ## """ |
|
214 ## from PyQt5.QtSerialPort import QSerialPortInfo |
|
215 ## |
|
216 ## availablePorts = QSerialPortInfo.availablePorts() |
|
217 ## for port in availablePorts: |
|
218 ## vid = port.vendorIdentifier() |
|
219 ## pid = port.productIdentifier() |
|
220 ## for board in SupportedBoards: |
|
221 ## if ((vid, pid) in SupportedBoards[board] or |
|
222 ## (vid, None) in SupportedBoards[board]): |
|
223 ## portName = port.portName() |
|
224 ## serialNumber = port.serialNumber() |
|
225 ## return (self.__portPath(portName), serialNumber) |
|
226 ## |
|
227 ## return (None, None) |
|
228 ## |
|
229 ## def __portPath(self, portName): |
|
230 ## """ |
|
231 ## Private method to get the full path of a given port. |
|
232 ## |
|
233 ## @param portName name of the port the path shall be determined for |
|
234 ## @type str |
|
235 ## @return full port path |
|
236 ## @rtype str |
|
237 ## """ |
|
238 ## if Globals.isWindowsPlatform(): |
|
239 ## # return name unchanged |
|
240 ## return portName |
|
241 ## else: |
|
242 ## # assume Posix system (Linux or macOS) |
|
243 ## return "/dev/{0}".format(portName) |