mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-08 07:27:29 -06:00
parent
17e5d1f835
commit
a9f109fd74
2 changed files with 45 additions and 33 deletions
|
@ -58,7 +58,7 @@ class PrinterConnection(SignalEmitter):
|
||||||
self._gcode_position = 0
|
self._gcode_position = 0
|
||||||
|
|
||||||
# List of gcode lines to be printed
|
# List of gcode lines to be printed
|
||||||
self._gcode = None
|
self._gcode = []
|
||||||
|
|
||||||
# Number of extruders
|
# Number of extruders
|
||||||
self._extruder_count = 1
|
self._extruder_count = 1
|
||||||
|
@ -102,8 +102,12 @@ class PrinterConnection(SignalEmitter):
|
||||||
# \param gcode_list List with gcode (strings).
|
# \param gcode_list List with gcode (strings).
|
||||||
def printGCode(self, gcode_list):
|
def printGCode(self, gcode_list):
|
||||||
if self.isPrinting() or not self._is_connected:
|
if self.isPrinting() or not self._is_connected:
|
||||||
|
Logger.log("d", "Printer is busy or not connected, aborting print")
|
||||||
return
|
return
|
||||||
self._gcode = gcode_list
|
|
||||||
|
self._gcode.clear()
|
||||||
|
for layer in gcode_list:
|
||||||
|
self._gcode.extend(layer.split("\n"))
|
||||||
|
|
||||||
#Reset line number. If this is not done, first line is sometimes ignored
|
#Reset line number. If this is not done, first line is sometimes ignored
|
||||||
self._gcode.insert(0, "M110")
|
self._gcode.insert(0, "M110")
|
||||||
|
@ -156,14 +160,18 @@ class PrinterConnection(SignalEmitter):
|
||||||
return
|
return
|
||||||
programmer.close()
|
programmer.close()
|
||||||
|
|
||||||
|
self.setProgress(100, 100)
|
||||||
|
|
||||||
## Upload new firmware to machine
|
## Upload new firmware to machine
|
||||||
# \param filename full path of firmware file to be uploaded
|
# \param filename full path of firmware file to be uploaded
|
||||||
def updateFirmware(self, file_name):
|
def updateFirmware(self, file_name):
|
||||||
|
Logger.log("i", "Updating firmware of %s using %s", self._serial_port, file_name)
|
||||||
self._firmware_file_name = file_name
|
self._firmware_file_name = file_name
|
||||||
self._update_firmware_thread.start()
|
self._update_firmware_thread.start()
|
||||||
|
|
||||||
## Private connect function run by thread. Can be started by calling connect.
|
## Private connect function run by thread. Can be started by calling connect.
|
||||||
def _connect(self):
|
def _connect(self):
|
||||||
|
Logger.log("d", "Attempting to connect to %s", self._serial_port)
|
||||||
self._is_connecting = True
|
self._is_connecting = True
|
||||||
programmer = stk500v2.Stk500v2()
|
programmer = stk500v2.Stk500v2()
|
||||||
try:
|
try:
|
||||||
|
@ -174,8 +182,9 @@ class PrinterConnection(SignalEmitter):
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
Logger.log("i", "Could not establish connection on %s, unknown reasons. Device is not arduino based." % self._serial_port)
|
Logger.log("i", "Could not establish connection on %s, unknown reasons. Device is not arduino based." % self._serial_port)
|
||||||
|
|
||||||
if not self._serial or not programmer.serial:
|
if not self._serial:
|
||||||
self._is_connecting = False
|
self._is_connecting = False
|
||||||
|
Logger.log("i", "Could not establish connection on %s, unknown reasons.", self._serial_port)
|
||||||
return
|
return
|
||||||
|
|
||||||
# If the programmer connected, we know its an atmega based version. Not all that usefull, but it does give some debugging information.
|
# If the programmer connected, we know its an atmega based version. Not all that usefull, but it does give some debugging information.
|
||||||
|
@ -229,13 +238,14 @@ class PrinterConnection(SignalEmitter):
|
||||||
self.connectionStateChanged.emit(self._serial_port)
|
self.connectionStateChanged.emit(self._serial_port)
|
||||||
if self._is_connected:
|
if self._is_connected:
|
||||||
self._listen_thread.start() #Start listening
|
self._listen_thread.start() #Start listening
|
||||||
'''Application.getInstance().addOutputDevice(self._serial_port, {
|
#Application.getInstance().addOutputDevice(self._serial_port, {
|
||||||
"id": self._serial_port,
|
#"id": self._serial_port,
|
||||||
"function": self.printGCode,
|
#"function": self.printGCode,
|
||||||
"description": "Print with USB {0}".format(self._serial_port),
|
#"shortDescription": "Print with USB",
|
||||||
"icon": "print_usb",
|
#"description": "Print with USB {0}".format(self._serial_port),
|
||||||
"priority": 1
|
#"icon": "save",
|
||||||
})'''
|
#"priority": 1
|
||||||
|
#})
|
||||||
|
|
||||||
else:
|
else:
|
||||||
Logger.log("w", "Printer connection state was not changed")
|
Logger.log("w", "Printer connection state was not changed")
|
||||||
|
@ -264,6 +274,7 @@ class PrinterConnection(SignalEmitter):
|
||||||
def _sendCommand(self, cmd):
|
def _sendCommand(self, cmd):
|
||||||
if self._serial is None:
|
if self._serial is None:
|
||||||
return
|
return
|
||||||
|
|
||||||
if "M109" in cmd or "M190" in cmd:
|
if "M109" in cmd or "M190" in cmd:
|
||||||
self._heatup_wait_start_time = time.time()
|
self._heatup_wait_start_time = time.time()
|
||||||
if "M104" in cmd or "M109" in cmd:
|
if "M104" in cmd or "M109" in cmd:
|
||||||
|
@ -363,6 +374,7 @@ class PrinterConnection(SignalEmitter):
|
||||||
if b"Extruder switched off" in line or b"Temperature heated bed switched off" in line or b"Something is wrong, please turn off the printer." in line:
|
if b"Extruder switched off" in line or b"Temperature heated bed switched off" in line or b"Something is wrong, please turn off the printer." in line:
|
||||||
if not self.hasError():
|
if not self.hasError():
|
||||||
self._setErrorState(line[6:])
|
self._setErrorState(line[6:])
|
||||||
|
|
||||||
elif b" T:" in line or line.startswith(b"T:"): #Temperature message
|
elif b" T:" in line or line.startswith(b"T:"): #Temperature message
|
||||||
try:
|
try:
|
||||||
self._setExtruderTemperature(self._temperature_requested_extruder_index,float(re.search(b"T: *([0-9\.]*)", line).group(1)))
|
self._setExtruderTemperature(self._temperature_requested_extruder_index,float(re.search(b"T: *([0-9\.]*)", line).group(1)))
|
||||||
|
@ -442,7 +454,7 @@ class PrinterConnection(SignalEmitter):
|
||||||
## Set the progress of the print.
|
## Set the progress of the print.
|
||||||
# It will be normalized (based on max_progress) to range 0 - 100
|
# It will be normalized (based on max_progress) to range 0 - 100
|
||||||
def setProgress(self, progress, max_progress = 100):
|
def setProgress(self, progress, max_progress = 100):
|
||||||
self._progress = progress / max_progress * 100 #Convert to scale of 0-100
|
self._progress = (progress / max_progress) * 100 #Convert to scale of 0-100
|
||||||
self.progressChanged.emit(self._progress, self._serial_port)
|
self.progressChanged.emit(self._progress, self._serial_port)
|
||||||
|
|
||||||
## Cancel the current print. Printer connection wil continue to listen.
|
## Cancel the current print. Printer connection wil continue to listen.
|
||||||
|
|
|
@ -47,7 +47,7 @@ class USBPrinterManager(QObject, SignalEmitter, Extension):
|
||||||
self.setMenuName("Firmware")
|
self.setMenuName("Firmware")
|
||||||
self.addMenuItem(i18n_catalog.i18n("Update Firmware"), self.updateAllFirmware)
|
self.addMenuItem(i18n_catalog.i18n("Update Firmware"), self.updateAllFirmware)
|
||||||
|
|
||||||
pyqtError = pyqtSignal(str, arguments = ["amount"])
|
pyqtError = pyqtSignal(str, arguments = ["error"])
|
||||||
processingProgress = pyqtSignal(float, arguments = ["amount"])
|
processingProgress = pyqtSignal(float, arguments = ["amount"])
|
||||||
pyqtExtruderTemperature = pyqtSignal(float, arguments = ["amount"])
|
pyqtExtruderTemperature = pyqtSignal(float, arguments = ["amount"])
|
||||||
pyqtBedTemperature = pyqtSignal(float, arguments = ["amount"])
|
pyqtBedTemperature = pyqtSignal(float, arguments = ["amount"])
|
||||||
|
@ -59,9 +59,9 @@ class USBPrinterManager(QObject, SignalEmitter, Extension):
|
||||||
path = QUrl.fromLocalFile(os.path.join(PluginRegistry.getInstance().getPluginPath("USBPrinting"), "FirmwareUpdateWindow.qml"))
|
path = QUrl.fromLocalFile(os.path.join(PluginRegistry.getInstance().getPluginPath("USBPrinting"), "FirmwareUpdateWindow.qml"))
|
||||||
component = QQmlComponent(Application.getInstance()._engine, path)
|
component = QQmlComponent(Application.getInstance()._engine, path)
|
||||||
|
|
||||||
context = QQmlContext(Application.getInstance()._engine.rootContext())
|
self._firmware_context = QQmlContext(Application.getInstance()._engine.rootContext())
|
||||||
context.setContextProperty("manager", self)
|
self._firmware_context.setContextProperty("manager", self)
|
||||||
self._firmware_view = component.create(context)
|
self._firmware_view = component.create(self._firmware_context)
|
||||||
|
|
||||||
self._firmware_view.show()
|
self._firmware_view.show()
|
||||||
|
|
||||||
|
@ -72,10 +72,10 @@ class USBPrinterManager(QObject, SignalEmitter, Extension):
|
||||||
path = QUrl.fromLocalFile(os.path.join(PluginRegistry.getInstance().getPluginPath("USBPrinting"), "ControlWindow.qml"))
|
path = QUrl.fromLocalFile(os.path.join(PluginRegistry.getInstance().getPluginPath("USBPrinting"), "ControlWindow.qml"))
|
||||||
|
|
||||||
component = QQmlComponent(Application.getInstance()._engine, path)
|
component = QQmlComponent(Application.getInstance()._engine, path)
|
||||||
context = QQmlContext(Application.getInstance()._engine.rootContext())
|
self._control_context = QQmlContext(Application.getInstance()._engine.rootContext())
|
||||||
context.setContextProperty("manager", self)
|
self._control_context.setContextProperty("manager", self)
|
||||||
|
|
||||||
self._control_view = component.create(context)
|
self._control_view = component.create(self._control_context)
|
||||||
|
|
||||||
self._control_view.show()
|
self._control_view.show()
|
||||||
|
|
||||||
|
@ -175,8 +175,8 @@ class USBPrinterManager(QObject, SignalEmitter, Extension):
|
||||||
|
|
||||||
## Callback for error
|
## Callback for error
|
||||||
def onError(self, error):
|
def onError(self, error):
|
||||||
self._error_message = error
|
self._error_message = error if type(error) is str else error.decode("utf-8")
|
||||||
self.pyqtError.emit(error)
|
self.pyqtError.emit(self._error_message)
|
||||||
|
|
||||||
## Callback for progress change
|
## Callback for progress change
|
||||||
def onProgress(self, progress, serial_port):
|
def onProgress(self, progress, serial_port):
|
||||||
|
@ -241,9 +241,9 @@ class USBPrinterManager(QObject, SignalEmitter, Extension):
|
||||||
Application.getInstance().addOutputDevice(serial_port, {
|
Application.getInstance().addOutputDevice(serial_port, {
|
||||||
"id": serial_port,
|
"id": serial_port,
|
||||||
"function": self.spawnControlInterface,
|
"function": self.spawnControlInterface,
|
||||||
"description": "Print through USB {0}".format(serial_port),
|
"description": "Print with USB {0}".format(serial_port),
|
||||||
"shortDescription": "Print through USB",
|
"shortDescription": "Print with USB",
|
||||||
"icon": "print_usb",
|
"icon": "save",
|
||||||
"priority": 1
|
"priority": 1
|
||||||
})
|
})
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue