mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-08 07:27:29 -06:00
Added controller for USB printer
CL-541
This commit is contained in:
parent
e2845a224c
commit
a6deddb6ae
2 changed files with 62 additions and 3 deletions
57
plugins/USBPrinting/USBPrinterOutputController.py
Normal file
57
plugins/USBPrinting/USBPrinterOutputController.py
Normal file
|
@ -0,0 +1,57 @@
|
||||||
|
# Copyright (c) 2017 Ultimaker B.V.
|
||||||
|
# Cura is released under the terms of the LGPLv3 or higher.
|
||||||
|
|
||||||
|
from cura.PrinterOutput.PrinterOutputController import PrinterOutputController
|
||||||
|
from PyQt5.QtCore import QTimer
|
||||||
|
|
||||||
|
MYPY = False
|
||||||
|
if MYPY:
|
||||||
|
from cura.PrinterOutput.PrintJobOutputModel import PrintJobOutputModel
|
||||||
|
from cura.PrinterOutput.PrinterOutputModel import PrinterOutputModel
|
||||||
|
|
||||||
|
|
||||||
|
class USBPrinterOuptutController(PrinterOutputController):
|
||||||
|
def __init__(self, output_device):
|
||||||
|
super().__init__(output_device)
|
||||||
|
|
||||||
|
self._preheat_bed_timer = QTimer()
|
||||||
|
self._preheat_bed_timer.setSingleShot(True)
|
||||||
|
self._preheat_bed_timer.timeout.connect(self._onPreheatBedTimerFinished)
|
||||||
|
self._preheat_printer = None
|
||||||
|
|
||||||
|
def moveHead(self, printer: "PrinterOutputModel", x, y, z, speed):
|
||||||
|
self._output_device.sendCommand("G91")
|
||||||
|
self._output_device.sendCommand("G0 X%s Y%s Z%s F%s" % (x, y, z, speed))
|
||||||
|
self._output_device.sendCommand("G90")
|
||||||
|
|
||||||
|
def homeHead(self, printer):
|
||||||
|
self._output_device.sendCommand("G28 X")
|
||||||
|
self._output_device.sendCommand("G28 Y")
|
||||||
|
|
||||||
|
def homeBed(self, printer):
|
||||||
|
self._output_device.sendCommand("G28 Z")
|
||||||
|
|
||||||
|
def preheatBed(self, printer: "PrinterOutputModel", temperature, duration):
|
||||||
|
try:
|
||||||
|
temperature = round(temperature) # The API doesn't allow floating point.
|
||||||
|
duration = round(duration)
|
||||||
|
except ValueError:
|
||||||
|
return # Got invalid values, can't pre-heat.
|
||||||
|
|
||||||
|
self.setTargetBedTemperature(printer, temperature=temperature)
|
||||||
|
self._preheat_bed_timer.setInterval(duration * 1000)
|
||||||
|
self._preheat_bed_timer.start()
|
||||||
|
self._preheat_printer = printer
|
||||||
|
printer.updateIsPreheating(True)
|
||||||
|
|
||||||
|
def cancelPreheatBed(self, printer: "PrinterOutputModel"):
|
||||||
|
self.preheatBed(printer, temperature=0, duration=0)
|
||||||
|
self._preheat_bed_timer.stop()
|
||||||
|
printer.updateIsPreheating(False)
|
||||||
|
|
||||||
|
def setTargetBedTemperature(self, printer: "PrinterOutputModel", temperature: int):
|
||||||
|
self._output_device.sendCommand("M140 S%s" % temperature)
|
||||||
|
|
||||||
|
def _onPreheatBedTimerFinished(self):
|
||||||
|
self.setTargetBedTemperature(self._preheat_printer, 0)
|
||||||
|
self._preheat_printer.updateIsPreheating(False)
|
|
@ -11,6 +11,7 @@ from cura.PrinterOutput.PrinterOutputModel import PrinterOutputModel
|
||||||
from cura.PrinterOutput.PrintJobOutputModel import PrintJobOutputModel
|
from cura.PrinterOutput.PrintJobOutputModel import PrintJobOutputModel
|
||||||
|
|
||||||
from .AutoDetectBaudJob import AutoDetectBaudJob
|
from .AutoDetectBaudJob import AutoDetectBaudJob
|
||||||
|
from .USBPrinterOutputController import USBPrinterOuptutController
|
||||||
|
|
||||||
from serial import Serial, SerialException
|
from serial import Serial, SerialException
|
||||||
from threading import Thread
|
from threading import Thread
|
||||||
|
@ -44,7 +45,6 @@ class USBPrinterOutputDevice(PrinterOutputDevice):
|
||||||
|
|
||||||
self._baud_rate = baud_rate
|
self._baud_rate = baud_rate
|
||||||
|
|
||||||
|
|
||||||
self._all_baud_rates = [115200, 250000, 230400, 57600, 38400, 19200, 9600]
|
self._all_baud_rates = [115200, 250000, 230400, 57600, 38400, 19200, 9600]
|
||||||
|
|
||||||
# Instead of using a timer, we really need the update to be as a thread, as reading from serial can block.
|
# Instead of using a timer, we really need the update to be as a thread, as reading from serial can block.
|
||||||
|
@ -58,6 +58,8 @@ class USBPrinterOutputDevice(PrinterOutputDevice):
|
||||||
self._print_start_time = None
|
self._print_start_time = None
|
||||||
self._print_estimated_time = None
|
self._print_estimated_time = None
|
||||||
|
|
||||||
|
self._accepts_commands = True
|
||||||
|
|
||||||
# Queue for commands that need to be send. Used when command is sent when a print is active.
|
# Queue for commands that need to be send. Used when command is sent when a print is active.
|
||||||
self._command_queue = Queue()
|
self._command_queue = Queue()
|
||||||
|
|
||||||
|
@ -127,7 +129,7 @@ class USBPrinterOutputDevice(PrinterOutputDevice):
|
||||||
num_extruders = container_stack.getProperty("machine_extruder_count", "value")
|
num_extruders = container_stack.getProperty("machine_extruder_count", "value")
|
||||||
|
|
||||||
# Ensure that a printer is created.
|
# Ensure that a printer is created.
|
||||||
self._printers = [PrinterOutputModel(output_controller=None, number_of_extruders=num_extruders)]
|
self._printers = [PrinterOutputModel(output_controller=USBPrinterOuptutController(self), number_of_extruders=num_extruders)]
|
||||||
self.setConnectionState(ConnectionState.connected)
|
self.setConnectionState(ConnectionState.connected)
|
||||||
self._update_thread.start()
|
self._update_thread.start()
|
||||||
|
|
||||||
|
@ -214,7 +216,7 @@ class USBPrinterOutputDevice(PrinterOutputDevice):
|
||||||
elapsed_time = int(time() - self._print_start_time)
|
elapsed_time = int(time() - self._print_start_time)
|
||||||
print_job = self._printers[0].activePrintJob
|
print_job = self._printers[0].activePrintJob
|
||||||
if print_job is None:
|
if print_job is None:
|
||||||
print_job = PrintJobOutputModel(output_controller = None, name= Application.getInstance().getPrintInformation().jobName)
|
print_job = PrintJobOutputModel(output_controller = USBPrinterOuptutController(self), name= Application.getInstance().getPrintInformation().jobName)
|
||||||
self._printers[0].updateActivePrintJob(print_job)
|
self._printers[0].updateActivePrintJob(print_job)
|
||||||
|
|
||||||
print_job.updateTimeElapsed(elapsed_time)
|
print_job.updateTimeElapsed(elapsed_time)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue