USB printing now uses printeroutputdevice for temperatures

CURA-1339
This commit is contained in:
Jaime van Kessel 2016-04-13 16:57:08 +02:00
parent 45b3e8fbd6
commit 0a46567c17
3 changed files with 11 additions and 25 deletions

View file

@ -25,7 +25,8 @@ UM.Dialog
Label Label
{ {
//: USB Printing dialog label, %1 is head temperature //: USB Printing dialog label, %1 is head temperature
text: catalog.i18nc("@label","Extruder Temperature %1").arg(manager.extruderTemperature) Component.onCompleted: console.log(manager.hotendTemperatures)
text: catalog.i18nc("@label","Extruder Temperature %1").arg(manager.hotendTemperatures[0])
} }
Label Label
{ {

View file

@ -197,7 +197,7 @@ class USBPrinterManager(QObject, SignalEmitter, OutputDevicePlugin, Extension):
self._printer_connections[serial_port] = connection self._printer_connections[serial_port] = connection
def _onPrinterConnectionStateChanged(self, serial_port): def _onPrinterConnectionStateChanged(self, serial_port):
if self._printer_connections[serial_port].connectionState == ConnectionState.CLOSED: if self._printer_connections[serial_port].connectionState == ConnectionState.CONNECTED:
self.getOutputDeviceManager().addOutputDevice(self._printer_connections[serial_port]) self.getOutputDeviceManager().addOutputDevice(self._printer_connections[serial_port])
else: else:
self.getOutputDeviceManager().removeOutputDevice(serial_port) self.getOutputDeviceManager().removeOutputDevice(serial_port)
@ -209,7 +209,7 @@ class USBPrinterManager(QObject, SignalEmitter, OutputDevicePlugin, Extension):
self._printer_connections_model.addRoleName(Qt.UserRole + 1,"name") self._printer_connections_model.addRoleName(Qt.UserRole + 1,"name")
self._printer_connections_model.addRoleName(Qt.UserRole + 2, "printer") self._printer_connections_model.addRoleName(Qt.UserRole + 2, "printer")
for connection in self._printer_connections: for connection in self._printer_connections:
if self._printer_connections[connection].isConnected: if self._printer_connections[connection].connectionState == ConnectionState.CONNECTED:
self._printer_connections_model.appendItem({"name":connection, "printer": self._printer_connections[connection]}) self._printer_connections_model.appendItem({"name":connection, "printer": self._printer_connections[connection]})
return self._printer_connections_model return self._printer_connections_model

View file

@ -69,21 +69,6 @@ class USBPrinterOutputDevice(PrinterOutputDevice):
# List of gcode lines to be printed # List of gcode lines to be printed
self._gcode = [] self._gcode = []
# Number of extruders
self._extruder_count = 1
# Temperatures of all extruders
self._extruder_temperatures = [0] * self._extruder_count
# Target temperatures of all extruders
self._target_extruder_temperatures = [0] * self._extruder_count
#Target temperature of the bed
self._target_bed_temperature = 0
# Temperature of the bed
self._bed_temperature = 0
# Current Z stage location # Current Z stage location
self._current_z = 0 self._current_z = 0
@ -274,6 +259,7 @@ class USBPrinterOutputDevice(PrinterOutputDevice):
if sucesfull_responses >= self._required_responses_auto_baud: if sucesfull_responses >= self._required_responses_auto_baud:
self._serial.timeout = 2 # Reset serial timeout self._serial.timeout = 2 # Reset serial timeout
self.setConnectionState(ConnectionState.CONNECTED) self.setConnectionState(ConnectionState.CONNECTED)
self._listen_thread.start() # Start listening
Logger.log("i", "Established printer connection on port %s" % self._serial_port) Logger.log("i", "Established printer connection on port %s" % self._serial_port)
return return
@ -408,15 +394,14 @@ class USBPrinterOutputDevice(PrinterOutputDevice):
Logger.log("i", "Printer connection listen thread started for %s" % self._serial_port) Logger.log("i", "Printer connection listen thread started for %s" % self._serial_port)
temperature_request_timeout = time.time() temperature_request_timeout = time.time()
ok_timeout = time.time() ok_timeout = time.time()
while self._connected: while self._connection_state == ConnectionState.CONNECTED:
line = self._readline() line = self._readline()
if line is None: if line is None:
break # None is only returned when something went wrong. Stop listening break # None is only returned when something went wrong. Stop listening
if time.time() > temperature_request_timeout: if time.time() > temperature_request_timeout:
if self._extruder_count > 0: if self._num_extruders > 0:
self._temperature_requested_extruder_index = (self._temperature_requested_extruder_index + 1) % self._extruder_count self._temperature_requested_extruder_index = (self._temperature_requested_extruder_index + 1) % self._num_extruders
self.sendCommand("M105 T%d" % (self._temperature_requested_extruder_index)) self.sendCommand("M105 T%d" % (self._temperature_requested_extruder_index))
else: else:
self.sendCommand("M105") self.sendCommand("M105")
@ -437,7 +422,7 @@ class USBPrinterOutputDevice(PrinterOutputDevice):
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._setHotendTemperature(self._temperature_requested_extruder_index, float(re.search(b"T: *([0-9\.]*)", line).group(1)))
except: except:
pass pass
if b"B:" in line: # Check if it's a bed temperature if b"B:" in line: # Check if it's a bed temperature
@ -469,8 +454,8 @@ class USBPrinterOutputDevice(PrinterOutputDevice):
else: # Request the temperature on comm timeout (every 2 seconds) when we are not printing.) else: # Request the temperature on comm timeout (every 2 seconds) when we are not printing.)
if line == b"": if line == b"":
if self._extruder_count > 0: if self._num_extruders > 0:
self._temperature_requested_extruder_index = (self._temperature_requested_extruder_index + 1) % self._extruder_count self._temperature_requested_extruder_index = (self._temperature_requested_extruder_index + 1) % self._num_extruders
self.sendCommand("M105 T%d" % self._temperature_requested_extruder_index) self.sendCommand("M105 T%d" % self._temperature_requested_extruder_index)
else: else:
self.sendCommand("M105") self.sendCommand("M105")