LegacyUM3PrinterOutputController.py 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. # Copyright (c) 2017 Ultimaker B.V.
  2. # Cura is released under the terms of the LGPLv3 or higher.
  3. from cura.PrinterOutput.PrinterOutputController import PrinterOutputController
  4. from PyQt5.QtCore import QTimer
  5. from UM.Version import Version
  6. MYPY = False
  7. if MYPY:
  8. from cura.PrinterOutput.PrintJobOutputModel import PrintJobOutputModel
  9. from cura.PrinterOutput.PrinterOutputModel import PrinterOutputModel
  10. class LegacyUM3PrinterOutputController(PrinterOutputController):
  11. def __init__(self, output_device):
  12. super().__init__(output_device)
  13. self._preheat_bed_timer = QTimer()
  14. self._preheat_bed_timer.setSingleShot(True)
  15. self._preheat_bed_timer.timeout.connect(self._onPreheatBedTimerFinished)
  16. self._preheat_printer = None
  17. self.can_control_manually = False
  18. self.can_send_raw_gcode = False
  19. # Are we still waiting for a response about preheat?
  20. # We need this so we can already update buttons, so it feels more snappy.
  21. self._preheat_request_in_progress = False
  22. def isPreheatRequestInProgress(self):
  23. return self._preheat_request_in_progress
  24. def setJobState(self, job: "PrintJobOutputModel", state: str):
  25. data = "{\"target\": \"%s\"}" % state
  26. self._output_device.put("print_job/state", data, onFinished=None)
  27. def setTargetBedTemperature(self, printer: "PrinterOutputModel", temperature: int):
  28. data = str(temperature)
  29. self._output_device.put("printer/bed/temperature/target", data, onFinished=self._onPutBedTemperatureCompleted)
  30. def _onPutBedTemperatureCompleted(self, reply):
  31. if Version(self._preheat_printer.firmwareVersion) < Version("3.5.92"):
  32. # If it was handling a preheat, it isn't anymore.
  33. self._preheat_request_in_progress = False
  34. def _onPutPreheatBedCompleted(self, reply):
  35. self._preheat_request_in_progress = False
  36. def moveHead(self, printer: "PrinterOutputModel", x, y, z, speed):
  37. head_pos = printer._head_position
  38. new_x = head_pos.x + x
  39. new_y = head_pos.y + y
  40. new_z = head_pos.z + z
  41. data = "{\n\"x\":%s,\n\"y\":%s,\n\"z\":%s\n}" %(new_x, new_y, new_z)
  42. self._output_device.put("printer/heads/0/position", data, onFinished=None)
  43. def homeBed(self, printer):
  44. self._output_device.put("printer/heads/0/position/z", "0", onFinished=None)
  45. def _onPreheatBedTimerFinished(self):
  46. self.setTargetBedTemperature(self._preheat_printer, 0)
  47. self._preheat_printer.updateIsPreheating(False)
  48. self._preheat_request_in_progress = True
  49. def cancelPreheatBed(self, printer: "PrinterOutputModel"):
  50. self.preheatBed(printer, temperature=0, duration=0)
  51. self._preheat_bed_timer.stop()
  52. printer.updateIsPreheating(False)
  53. def preheatBed(self, printer: "PrinterOutputModel", temperature, duration):
  54. try:
  55. temperature = round(temperature) # The API doesn't allow floating point.
  56. duration = round(duration)
  57. except ValueError:
  58. return # Got invalid values, can't pre-heat.
  59. if duration > 0:
  60. data = """{"temperature": "%i", "timeout": "%i"}""" % (temperature, duration)
  61. else:
  62. data = """{"temperature": "%i"}""" % temperature
  63. # Real bed pre-heating support is implemented from 3.5.92 and up.
  64. if Version(printer.firmwareVersion) < Version("3.5.92"):
  65. # No firmware-side duration support then, so just set target bed temp and set a timer.
  66. self.setTargetBedTemperature(printer, temperature=temperature)
  67. self._preheat_bed_timer.setInterval(duration * 1000)
  68. self._preheat_bed_timer.start()
  69. self._preheat_printer = printer
  70. printer.updateIsPreheating(True)
  71. return
  72. self._output_device.put("printer/bed/pre_heat", data, onFinished = self._onPutPreheatBedCompleted)
  73. printer.updateIsPreheating(True)
  74. self._preheat_request_in_progress = True