mirror of
https://git.mirrors.martin98.com/https://github.com/Ultimaker/Cura
synced 2025-05-02 00:34:26 +08:00
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:
parent
39920c95f3
commit
7bb486a34b
@ -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,28 +534,29 @@ 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"])
|
||||||
|
|
||||||
try:
|
if self._processing_preheat_requests:
|
||||||
is_preheating = self._json_printer_state["bed"]["pre_heat"]["active"]
|
try:
|
||||||
except KeyError: #Old firmware doesn't support that.
|
is_preheating = self._json_printer_state["bed"]["pre_heat"]["active"]
|
||||||
pass #Don't update the pre-heat remaining time.
|
except KeyError: #Old firmware doesn't support that.
|
||||||
else:
|
pass #Don't update the pre-heat remaining time.
|
||||||
if is_preheating:
|
else:
|
||||||
try:
|
if is_preheating:
|
||||||
remaining_preheat_time = self._json_printer_state["bed"]["pre_heat"]["remaining"]
|
try:
|
||||||
except KeyError: #Error in firmware. If "active" is supported, "remaining" should also be supported.
|
remaining_preheat_time = self._json_printer_state["bed"]["pre_heat"]["remaining"]
|
||||||
pass #Anyway, don't update.
|
except KeyError: #Error in firmware. If "active" is supported, "remaining" should also be supported.
|
||||||
else:
|
pass #Anyway, don't update.
|
||||||
#Only update if time estimate is significantly off (>5000ms).
|
else:
|
||||||
#Otherwise we get issues with latency causing the timer to count inconsistently.
|
#Only update if time estimate is significantly off (>5000ms).
|
||||||
if abs(self._preheat_bed_timer.remainingTime() - remaining_preheat_time * 1000) > 5000:
|
#Otherwise we get issues with latency causing the timer to count inconsistently.
|
||||||
self._preheat_bed_timer.setInterval(remaining_preheat_time * 1000)
|
if abs(self._preheat_bed_timer.remainingTime() - remaining_preheat_time * 1000) > 5000:
|
||||||
self._preheat_bed_timer.start()
|
self._preheat_bed_timer.setInterval(remaining_preheat_time * 1000)
|
||||||
|
self._preheat_bed_timer.start()
|
||||||
|
self.preheatBedRemainingTimeChanged.emit()
|
||||||
|
else: #Not pre-heating. Must've cancelled.
|
||||||
|
if self._preheat_bed_timer.isActive():
|
||||||
|
self._preheat_bed_timer.setInterval(0)
|
||||||
|
self._preheat_bed_timer.stop()
|
||||||
self.preheatBedRemainingTimeChanged.emit()
|
self.preheatBedRemainingTimeChanged.emit()
|
||||||
else: #Not pre-heating. Must've cancelled.
|
|
||||||
if self._preheat_bed_timer.isActive():
|
|
||||||
self._preheat_bed_timer.setInterval(0)
|
|
||||||
self._preheat_bed_timer.stop()
|
|
||||||
self.preheatBedRemainingTimeChanged.emit()
|
|
||||||
|
|
||||||
|
|
||||||
def close(self):
|
def close(self):
|
||||||
@ -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:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user