42 (0x1B4F, 0x8D23), # SparkFun SAMD21 Dev Breakout |
43 (0x1B4F, 0x8D23), # SparkFun SAMD21 Dev Breakout |
43 (0x1209, 0x2017), # Mini SAM M4 |
44 (0x1209, 0x2017), # Mini SAM M4 |
44 (0x1209, 0x7102), # Mini SAM M0 |
45 (0x1209, 0x7102), # Mini SAM M0 |
45 ], |
46 ], |
46 "description": "CircuitPython Boards", |
47 "description": "CircuitPython Boards", |
47 "icon": "adafruitDevice", |
48 "icon": "circuitPythonDevice", |
48 }, |
49 }, |
49 |
50 |
50 "bbc_microbit": { |
51 "bbc_microbit": { |
51 "ids": [ |
52 "ids": [ |
52 (0x0D28, 0x0204), # micro:bit |
53 (0x0D28, 0x0204), # micro:bit |
133 @param microPythonWidget reference to the main MicroPython widget |
134 @param microPythonWidget reference to the main MicroPython widget |
134 @type MicroPythonReplWidget |
135 @type MicroPythonReplWidget |
135 @return instantiated device interface |
136 @return instantiated device interface |
136 @rtype MicroPythonDevice |
137 @rtype MicroPythonDevice |
137 """ |
138 """ |
138 # TODO: not implemented yet |
139 if deviceType == "esp": |
139 return MicroPythonDevice(microPythonWidget) |
140 from .EspDevices import EspDevice |
|
141 return EspDevice(microPythonWidget) |
|
142 elif deviceType == "circuitpython": |
|
143 from .CircuitPythonDevices import CircuitPythonDevice |
|
144 return CircuitPythonDevice(microPythonWidget) |
|
145 elif deviceType == "bbc_microbit": |
|
146 from .MicrobitDevices import MicrobitDevice |
|
147 return MicrobitDevice(microPythonWidget) |
|
148 else: |
|
149 # nothing specific requested |
|
150 return MicroPythonDevice(microPythonWidget) |
140 |
151 |
141 |
152 |
142 class MicroPythonDevice(QObject): |
153 class MicroPythonDevice(QObject): |
143 """ |
154 """ |
144 Base class for the more specific MicroPython devices. |
155 Base class for the more specific MicroPython devices. |
152 @param parent reference to the parent object |
163 @param parent reference to the parent object |
153 @type QObject |
164 @type QObject |
154 """ |
165 """ |
155 super(MicroPythonDevice, self).__init__(parent) |
166 super(MicroPythonDevice, self).__init__(parent) |
156 |
167 |
157 self.__microPython = microPythonWidget |
168 self.microPython = microPythonWidget |
158 |
169 |
159 def setButtons(self): |
170 def setButtons(self): |
160 """ |
171 """ |
161 Public method to enable the supported action buttons. |
172 Public method to enable the supported action buttons. |
162 """ |
173 """ |
163 self.__microPython.setActionButtons( |
174 self.microPython.setActionButtons( |
|
175 open=False, save=False, |
164 run=False, repl=False, files=False, chart=False) |
176 run=False, repl=False, files=False, chart=False) |
165 |
177 |
166 def forceInterrupt(self): |
178 def forceInterrupt(self): |
167 """ |
179 """ |
168 Public method to determine the need for an interrupt when opening the |
180 Public method to determine the need for an interrupt when opening the |
177 """ |
189 """ |
178 Public method to determine, if a REPL can be started. |
190 Public method to determine, if a REPL can be started. |
179 |
191 |
180 @return tuple containing a flag indicating it is safe to start a REPL |
192 @return tuple containing a flag indicating it is safe to start a REPL |
181 and a reason why it cannot. |
193 and a reason why it cannot. |
182 """ |
194 @rtype tuple of (bool, str) |
183 return False, self.tr("Not implemented") |
195 """ |
|
196 return False, self.tr("REPL is not supported by this device.") |
184 |
197 |
185 def setRepl(self, on): |
198 def setRepl(self, on): |
186 """ |
199 """ |
187 Public method to set the REPL status and dependent status. |
200 Public method to set the REPL status and dependent status. |
188 |
201 |
189 @param on flag indicating the active status |
202 @param on flag indicating the active status |
190 @type bool |
203 @type bool |
191 """ |
204 """ |
192 return |
205 pass |
|
206 |
|
207 def canStartPlotter(self): |
|
208 """ |
|
209 Public method to determine, if a Plotter can be started. |
|
210 |
|
211 @return tuple containing a flag indicating it is safe to start a |
|
212 Plotter and a reason why it cannot. |
|
213 @rtype tuple of (bool, str) |
|
214 """ |
|
215 return False, self.tr("Plotter is not supported by this device.") |
|
216 |
|
217 def setPlotter(self, on): |
|
218 """ |
|
219 Public method to set the Plotter status and dependent status. |
|
220 |
|
221 @param on flag indicating the active status |
|
222 @type bool |
|
223 """ |
|
224 pass |
|
225 |
|
226 def canRunScript(self): |
|
227 """ |
|
228 Public method to determine, if a Plotter can be started. |
|
229 |
|
230 @return tuple containing a flag indicating it is safe to start a |
|
231 Plotter and a reason why it cannot. |
|
232 @rtype tuple of (bool, str) |
|
233 """ |
|
234 return False, self.tr("Running scripts is not supported by this" |
|
235 " device.") |
|
236 |
|
237 def runScript(self, script): |
|
238 """ |
|
239 Public method to run the given Python script. |
|
240 |
|
241 @param script script to be executed |
|
242 @type str |
|
243 """ |
|
244 pass |
|
245 |
|
246 def canStartFileManager(self): |
|
247 """ |
|
248 Public method to determine, if a File Manager can be started. |
|
249 |
|
250 @return tuple containing a flag indicating it is safe to start a |
|
251 File Manager and a reason why it cannot. |
|
252 @rtype tuple of (bool, str) |
|
253 """ |
|
254 return False, self.tr("File Manager is not supported by this device.") |
|
255 |
|
256 def setFileManager(self, on): |
|
257 """ |
|
258 Public method to set the File Manager status and dependent status. |
|
259 |
|
260 @param on flag indicating the active status |
|
261 @type bool |
|
262 """ |
|
263 pass |
193 |
264 |
194 def getWorkspace(self): |
265 def getWorkspace(self): |
195 """ |
266 """ |
196 Public method to get the workspace directory. |
267 Public method to get the workspace directory. |
197 |
268 |
198 @return workspace directory used for saving files |
269 @return workspace directory used for saving files |
199 @rtype str |
270 @rtype str |
200 """ |
271 """ |
201 return "" |
272 return (Preferences.getMultiProject("Workspace") or |
202 |
273 os.path.expanduser("~")) |
203 # TODO: are these needed? |
274 |
204 ## def findDevice(self, deviceType): |
275 def sendCommands(self, commandsList): |
205 ## """ |
276 """ |
206 ## Public method to find the first device of a specific type. |
277 Public method to send a list of commands to the device. |
207 ## |
278 |
208 ## @param deviceType device type |
279 @param commandsList list of commands to be sent to the device |
209 ## @type str |
280 @type list of str |
210 ## @return tuple containing the port the device is connected to and its |
281 """ |
211 ## serial number |
282 rawOn = [ # sequence of commands to enter raw mode |
212 ## @rtype tuple of (str, str) |
283 b'\x02', |
213 ## """ |
284 b'\r\x03', |
214 ## from PyQt5.QtSerialPort import QSerialPortInfo |
285 b'\r\x03', |
215 ## |
286 b'\r\x03', |
216 ## availablePorts = QSerialPortInfo.availablePorts() |
287 b'\r\x01', |
217 ## for port in availablePorts: |
288 ] |
218 ## vid = port.vendorIdentifier() |
289 newLine = [b'print("\\n")\r',] |
219 ## pid = port.productIdentifier() |
290 commands = [c.encode("utf-8)") + b'\r' for c in commandsList] |
220 ## for board in SupportedBoards: |
291 commands.append(b'\r') |
221 ## if ((vid, pid) in SupportedBoards[board] or |
292 commands.append(b'\x04') |
222 ## (vid, None) in SupportedBoards[board]): |
293 rawOff = [b'\x02'] |
223 ## portName = port.portName() |
294 commandSequence = rawOn + newLine + commands + rawOff |
224 ## serialNumber = port.serialNumber() |
295 self.microPython.execute(commandSequence) |
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) |
|