Don't process status updates of pre-heating while request is going on

There was the problem that you'd click on pre-heat, so locally it would display the time-out. Then a package came in with the out-dated print status saying that the printer is not pre-heating, so the pre-heat was cancelled on Cura's side. Then the next status update came in saying that the pre-heat is now busy, so the pre-heat is resumed on Cura's side. So the button was flicking back and forth once after pressing. This commit makes Cura ignore any status updates that come while the put-request is still going on, because they may be outdated. It'll appear nicer to the user, mostly.

Contributes to issue CURA-3360.
This commit is contained in:
Ghostkeeper 2017-02-24 17:44:37 +01:00
parent 39920c95f3
commit 7bb486a34b
No known key found for this signature in database
GPG Key ID: C5F96EE2BC0F7E75

View File

@ -99,6 +99,7 @@ class NetworkPrinterOutputDevice(PrinterOutputDevice):
self._material_ids = [""] * self._num_extruders self._material_ids = [""] * self._num_extruders
self._hotend_ids = [""] * self._num_extruders self._hotend_ids = [""] * self._num_extruders
self._target_bed_temperature = 0 self._target_bed_temperature = 0
self._processing_preheat_requests = True
self.setPriority(2) # Make sure the output device gets selected above local file output self.setPriority(2) # Make sure the output device gets selected above local file output
self.setName(key) self.setName(key)
@ -262,6 +263,7 @@ class NetworkPrinterOutputDevice(PrinterOutputDevice):
Logger.log("i", "Pre-heating bed to %i degrees.", temperature) Logger.log("i", "Pre-heating bed to %i degrees.", temperature)
put_request = QNetworkRequest(url) put_request = QNetworkRequest(url)
put_request.setHeader(QNetworkRequest.ContentTypeHeader, "application/json") put_request.setHeader(QNetworkRequest.ContentTypeHeader, "application/json")
self._processing_preheat_requests = False
self._manager.put(put_request, data.encode()) self._manager.put(put_request, data.encode())
self._preheat_bed_timer.start(self._preheat_bed_timeout * 1000) #Times 1000 because it needs to be provided as milliseconds. self._preheat_bed_timer.start(self._preheat_bed_timeout * 1000) #Times 1000 because it needs to be provided as milliseconds.
self.preheatBedRemainingTimeChanged.emit() self.preheatBedRemainingTimeChanged.emit()
@ -532,6 +534,7 @@ class NetworkPrinterOutputDevice(PrinterOutputDevice):
self._updateHeadPosition(head_x, head_y, head_z) self._updateHeadPosition(head_x, head_y, head_z)
self._updatePrinterState(self._json_printer_state["status"]) self._updatePrinterState(self._json_printer_state["status"])
if self._processing_preheat_requests:
try: try:
is_preheating = self._json_printer_state["bed"]["pre_heat"]["active"] is_preheating = self._json_printer_state["bed"]["pre_heat"]["active"]
except KeyError: #Old firmware doesn't support that. except KeyError: #Old firmware doesn't support that.
@ -1056,6 +1059,8 @@ class NetworkPrinterOutputDevice(PrinterOutputDevice):
self._progress_message.hide() self._progress_message.hide()
elif reply.operation() == QNetworkAccessManager.PutOperation: elif reply.operation() == QNetworkAccessManager.PutOperation:
if "printer/bed/pre_heat" in reply_url: #Pre-heat command has completed. Re-enable syncing pre-heating.
self._processing_preheat_requests = True
if status_code in [200, 201, 202, 204]: if status_code in [200, 201, 202, 204]:
pass # Request was successful! pass # Request was successful!
else: else: