Support EMERGENCY_PARSER & use M108 on cancel (unless disabled)

Implements #1504
This commit is contained in:
Gina Häußge committed 2018-09-26 15:29:15 +02:00
1 parent 1f957e1ee2
commit f32ea65b2c
6 files changed
+96 -21

No files matched your search

+5 -1
View File
@@ -154,6 +154,7 @@ def getSettings():
"blockM0M1": s.getBoolean(["serial", "blockM0M1"]),
"logPositionOnPause": s.getBoolean(["serial", "logPositionOnPause"]),
"logPositionOnCancel": s.getBoolean(["serial", "logPositionOnCancel"]),
"abortHeatupOnCancel": s.getBoolean(["serial", "abortHeatupOnCancel"]),
"supportResendsWithoutOk": s.get(["serial", "supportResendsWithoutOk"]),
"waitForStart": s.getBoolean(["serial", "waitForStartOnConnect"]),
"alwaysSendChecksum": s.getBoolean(["serial", "alwaysSendChecksum"]),
@@ -171,7 +172,8 @@ def getSettings():
"maxTimeoutsLong": s.getInt(["serial", "maxCommunicationTimeouts", "long"]),
"capAutoreportTemp": s.getBoolean(["serial", "capabilities", "autoreport_temp"]),
"capAutoreportSdStatus": s.getBoolean(["serial", "capabilities", "autoreport_sdstatus"]),
"capBusyProtocol": s.getBoolean(["serial", "capabilities", "busy_protocol"])
"capBusyProtocol": s.getBoolean(["serial", "capabilities", "busy_protocol"]),
"capEmergencyParser": s.getBoolean(["serial", "capabilities", "emergency_parser"])
},
"folder": {
"uploads": s.getBaseFolder("uploads"),
@@ -448,12 +450,14 @@ def _saveSettings(data):
if "blockWhileDwelling" in data["serial"]: s.setBoolean(["serial", "blockWhileDwelling"], data["serial"]["blockWhileDwelling"])
if "logPositionOnPause" in data["serial"]: s.setBoolean(["serial", "logPositionOnPause"], data["serial"]["logPositionOnPause"])
if "logPositionOnCancel" in data["serial"]: s.setBoolean(["serial", "logPositionOnCancel"], data["serial"]["logPositionOnCancel"])
if "abortHeatupOnCancel" in data["serial"]: s.setBoolean(["serial", "abortHeatupOnCancel"], data["serial"]["abortHeatupOnCancel"])
if "maxTimeoutsIdle" in data["serial"]: s.setInt(["serial", "maxCommunicationTimeouts", "idle"], data["serial"]["maxTimeoutsIdle"])
if "maxTimeoutsPrinting" in data["serial"]: s.setInt(["serial", "maxCommunicationTimeouts", "printing"], data["serial"]["maxTimeoutsPrinting"])
if "maxTimeoutsLong" in data["serial"]: s.setInt(["serial", "maxCommunicationTimeouts", "long"], data["serial"]["maxTimeoutsLong"])
if "capAutoreportTemp" in data["serial"]: s.setBoolean(["serial", "capabilities", "autoreport_temp"], data["serial"]["capAutoreportTemp"])
if "capAutoreportSdStatus" in data["serial"]: s.setBoolean(["serial", "capabilities", "autoreport_sdstatus"], data["serial"]["capAutoreportSdStatus"])
if "capBusyProtocol" in data["serial"]: s.setBoolean(["serial", "capabilities", "busy_protocol"], data["serial"]["capBusyProtocol"])
if "capEmergencyParser" in data["serial"]: s.setBoolean(["serial", "capabilities", "emergency_parser"], data["serial"]["capEmergencyParser"])
oldLog = s.getBoolean(["serial", "log"])
if "log" in data["serial"]: s.setBoolean(["serial", "log"], data["serial"]["log"])
+6 -3
View File
@@ -121,6 +121,7 @@ default_settings = {
"supportResendsWithoutOk": "detect",
"logPositionOnPause": True,
"logPositionOnCancel": False,
"abortHeatupOnCancel": True,
"waitForStartOnConnect": False,
"alwaysSendChecksum": False,
"neverSendChecksum": False,
@@ -141,7 +142,8 @@ default_settings = {
"capabilities": {
"autoreport_temp": True,
"autoreport_sdstatus": True,
"busy_protocol": True
"busy_protocol": True,
"emergency_parser": True
},
# command specific flags
@@ -411,10 +413,11 @@ default_settings = {
"preparedOks": [],
"okFormatString": "ok",
"m115FormatString": "FIRMWARE_NAME:{firmware_name} PROTOCOL_VERSION:1.0",
"m115ReportCapabilities": False,
"m115ReportCapabilities": True,
"capabilities": {
"AUTOREPORT_TEMP": True,
"AUTOREPORT_SD_STATUS": True
"AUTOREPORT_SD_STATUS": True,
"EMERGENCY_PARSER": True
},
"m114FormatString": "X:{x} Y:{y} Z:{z} E:{e[current]} Count: A:{a} B:{b} C:{c}",
"ambientTemperature": 21.3,
@@ -183,12 +183,14 @@ $(function() {
self.serial_supportResendsWithoutOk = ko.observable(undefined);
self.serial_logPositionOnPause = ko.observable(undefined);
self.serial_logPositionOnCancel = ko.observable(undefined);
self.serial_abortHeatupOnCancel = ko.observable(undefined);
self.serial_maxTimeoutsIdle = ko.observable(undefined);
self.serial_maxTimeoutsPrinting = ko.observable(undefined);
self.serial_maxTimeoutsLong = ko.observable(undefined);
self.serial_capAutoreportTemp = ko.observable(undefined);
self.serial_capAutoreportSdStatus = ko.observable(undefined);
self.serial_capBusyProtocol = ko.observable(undefined);
self.serial_capEmergencyParser = ko.observable(undefined);
self.folder_uploads = ko.observable(undefined);
self.folder_timelapse = ko.observable(undefined);
@@ -280,6 +280,13 @@
</label>
</div>
</div>
<div class="control-group">
<div class="controls">
<label class="checkbox">
<input type="checkbox" data-bind="checked: serial_capEmergencyParser" id="settings-serialCapEmergencyParser"> {{ _('Send emergency GCODES <code>M108</code> and <code>M410</code> without waiting for acknowledgement, if detected as supported by the firmware') }}
</label>
</div>
</div>
<div class="control-group">
<div class="controls">
<label class="checkbox">
@@ -377,19 +384,28 @@
</div>
</fieldset>
<fieldset>
<legend>{{ _('Event based position logging') }}</legend>
<legend>{{ _('Pausing') }}</legend>
<div class="controls">
<label class="checkbox">
<input type="checkbox" data-bind="checked: serial_logPositionOnPause" id="settings-serialLogPositionOnPause"> {{ _('Log position on pause') }} <span class="label label-important">{{ _('Warning') }}</span>
<span class="help-block">{{ _('If you disable this, the <code>pause_position</code> placeholders in your pause/resume GCODE scripts will stay unpopulated! However, pausing speed might improve slightly.') }}</span>
</label>
</div>
</fieldset>
<fieldset>
<legend>{{ _('Cancelling') }}</legend>
<div class="controls">
<label class="checkbox">
<input type="checkbox" data-bind="checked: serial_logPositionOnCancel" id="settings-serialLogPositionOnCancel"> {{ _('Log position on cancel') }} <span class="label label-important">{{ _('Warning') }}</span>
<span class="help-block">{{ _('If you disable this, the <code>cancel_position</code> placeholders in your cancel GCODE script and the corresponding data in the print recovery data will stay unpopulated! However, cancelling speed might improve slightly.') }}</span>
</label>
</div>
<div class="controls">
<label class="checkbox">
<input type="checkbox" data-bind="checked: serial_abortHeatupOnCancel" id="settings-serialAbortHeatupOnCancel"> {{ _('Attempt to abort any blocking heatups on cancel via <code>M108</code>.') }}
<span class="help-block">{{ _('Uncheck this if your firmware doesn\'t support <code>M108</code> for aborting blocking heatups!') }}</span>
</label>
</div>
</fieldset>
</div>
</div>
+1 -2
View File
@@ -1302,7 +1302,7 @@ class CountedEvent(object):
self._event.wait(timeout)
def blocked(self):
return self.counter == 0
return self.counter <= 0
def acquire(self, blocking=1):
return self._mutex.acquire(blocking=blocking)
@@ -1313,7 +1313,6 @@ class CountedEvent(object):
def _internal_set(self, value):
self._counter = value
if self._counter <= 0:
self._counter = 0
self._event.clear()
else:
if self._max is not None and self._counter > self._max:
+65 -14
View File
@@ -351,6 +351,7 @@ class MachineCom(object):
CAPABILITY_AUTOREPORT_TEMP = "AUTOREPORT_TEMP"
CAPABILITY_AUTOREPORT_SD_STATUS = "AUTOREPORT_SD_STATUS"
CAPABILITY_BUSY_PROTOCOL = "BUSY_PROTOCOL"
CAPABILITY_EMERGENCY_PARSER = "EMERGENCY_PARSER"
CAPABILITY_SUPPORT_ENABLED = "enabled"
CAPABILITY_SUPPORT_DETECTED = "detected"
@@ -438,7 +439,8 @@ class MachineCom(object):
self._capability_support = {
self.CAPABILITY_AUTOREPORT_TEMP: settings().getBoolean(["serial", "capabilities", "autoreport_temp"]),
self.CAPABILITY_AUTOREPORT_SD_STATUS: settings().getBoolean(["serial", "capabilities", "autoreport_sdstatus"]),
self.CAPABILITY_BUSY_PROTOCOL: settings().getBoolean(["serial", "capabilities", "busy_protocol"])
self.CAPABILITY_BUSY_PROTOCOL: settings().getBoolean(["serial", "capabilities", "busy_protocol"]),
self.CAPABILITY_EMERGENCY_PARSER: settings().getBoolean(["serial", "capabilities", "emergency_parser"])
}
self._lastLines = deque([], 50)
@@ -477,7 +479,7 @@ class MachineCom(object):
self._long_running_commands = settings().get(["serial", "longRunningCommands"])
self._checksum_requiring_commands = settings().get(["serial", "checksumRequiringCommands"])
self._clear_to_send = CountedEvent(max=10, name="comm.clear_to_send")
self._clear_to_send = CountedEvent(name="comm.clear_to_send")
self._send_queue = SendQueue()
self._temperature_timer = None
self._sd_status_timer = None
@@ -541,6 +543,7 @@ class MachineCom(object):
self._log_position_on_pause = settings().getBoolean(["serial", "logPositionOnPause"])
self._log_position_on_cancel = settings().getBoolean(["serial", "logPositionOnCancel"])
self._abort_heatup_on_cancel = settings().getBoolean(["serial", "abortHeatupOnCancel"])
# print job
self._currentFile = None
@@ -1197,6 +1200,13 @@ class MachineCom(object):
with self._jobLock:
self._changeState(self.STATE_CANCELLING)
if self._abort_heatup_on_cancel:
# abort any ongoing heatups immediately to get back control over the printer
self.sendCommand("M108",
part_of_job=False,
tags=tags | {"trigger:comm.cancel", "trigger:abort_heatup"},
force=True)
if self.isSdFileSelected():
if not external_sd:
self.sendCommand("M25", part_of_job=True, tags=tags | {"trigger:comm.cancel",}) # pause print
@@ -1825,6 +1835,8 @@ class MachineCom(object):
elif capability == self.CAPABILITY_AUTOREPORT_SD_STATUS and enabled:
self._logger.info("Firmware states that it supports sd status autoreporting")
self._set_autoreport_sdstatus_interval()
elif capability == self.CAPABILITY_EMERGENCY_PARSER and enabled:
self._logger.info("Firmware states that it supports emergency GCODEs M108 and M410 to be sent without waiting for an acknowledgement first")
# notify plugins
for name, hook in self._firmware_info_hooks["capabilities"].items():
@@ -2982,17 +2994,7 @@ class MachineCom(object):
continue
# now comes the part where we increase line numbers and send stuff - no turning back now
command_requiring_checksum = gcode is not None and gcode in self._checksum_requiring_commands
command_allowing_checksum = gcode is not None or self._sendChecksumWithUnknownCommands
checksum_enabled = not self._neverSendChecksum and ((self.isPrinting() and self._currentFile and self._currentFile.checksum) or
self._alwaysSendChecksum or
not self._firmware_info_received)
command_to_send = command.encode("ascii", errors="replace")
if command_requiring_checksum or (command_allowing_checksum and checksum_enabled):
self._do_increment_and_send_with_checksum(command_to_send)
else:
self._do_send_without_checksum(command_to_send)
self._do_send(command, gcode=gcode)
# trigger "sent" phase and use up one "ok"
if on_sent is not None and callable(on_sent):
@@ -3152,6 +3154,24 @@ class MachineCom(object):
##~~ actual sending via serial
def _needs_checksum(self, gcode=None):
command_requiring_checksum = gcode is not None and gcode in self._checksum_requiring_commands
command_allowing_checksum = gcode is not None or self._sendChecksumWithUnknownCommands
return command_requiring_checksum or (command_allowing_checksum and self._checksum_enabled)
@property
def _checksum_enabled(self):
return not self._neverSendChecksum and ((self.isPrinting() and self._currentFile and self._currentFile.checksum) or
self._alwaysSendChecksum or
not self._firmware_info_received)
def _do_send(self, command, gcode=None):
command_to_send = command.encode("ascii", errors="replace")
if self._needs_checksum(gcode):
self._do_increment_and_send_with_checksum(command_to_send)
else:
self._do_send_without_checksum(command_to_send)
def _do_increment_and_send_with_checksum(self, cmd):
with self._line_mutex:
linenumber = self._currentLine
@@ -3420,7 +3440,12 @@ class MachineCom(object):
self._resendDelta = None
def _gcode_M112_queuing(self, cmd, cmd_type=None, gcode=None, subcode=None, *args, **kwargs):
# emergency stop, jump the queue with the M112
self._logger.info("Force-sending M112 to the printer")
# emergency stop, jump the queue with the M112, regardless of whether the EMERGENCY_PARSER capability is
# available or not
#
# send the M112 once without and with checksum
self._do_send_without_checksum("M112")
self._do_increment_and_send_with_checksum("M112")
@@ -3448,6 +3473,32 @@ class MachineCom(object):
# I hope it got it the first time because as far as I can tell, there is no way to know
return None,
def _gcode_M108_queuing(self, cmd, gcode=None, *args, **kwargs):
# only jump the queue with M108 if the EMERGENCY_PARSER capability is available
if not self._capability_support.get(self.CAPABILITY_EMERGENCY_PARSER, False) or not self._firmware_capabilities.get(self.CAPABILITY_EMERGENCY_PARSER, False):
return
self._logger.info("Force-sending M108 to the printer")
self._do_send(cmd, gcode=gcode)
# use up an ok since we will get one back for this command and don't want to get out of sync
self._clear_to_send.clear()
return None,
def _gcode_M410_queuing(self, cmd, gcode=None, *args, **kwargs):
# only jump the queue with M410 if the EMERGENCY_PARSER capability is available
if not self._capability_support.get(self.CAPABILITY_EMERGENCY_PARSER, False) or not self._firmware_capabilities.get(self.CAPABILITY_EMERGENCY_PARSER, False):
return
self._logger.info("Force-sending M410 to the printer")
self._do_send(cmd, gcode=gcode)
# use up an ok since we will get one back for this command and don't want to get out of sync
self._clear_to_send.clear()
return None,
def _gcode_M114_queued(self, *args, **kwargs):
self._reset_position_timers()
_gcode_M114_sent = _gcode_M114_queued