✨ Support position autoreporting

Includes proper handling auf cancel/pause situation, where we use the
position report as a signal that all movement has ended and the position
report should be used for final cancel/pause position, adds a new
terminal filter and also takes care of capability report evaluation and
proper interval setting via M154.

cc @thinkyhead - the cancel/pause situation worried me, so I took a look
how to solve it and that meant the implementation was already done as
well. Hope you don't hold it against me to tackle this myself after all.
This commit is contained in:
Gina Häußge committed 2021-05-25 19:50:06 +02:00
1 parent e11cd882e6
commit fcf45f7d59
7 files changed
+190 -68

No files matched your search

@@ -54,6 +54,7 @@ class VirtualPrinterPlugin(
"capabilities": {
"AUTOREPORT_TEMP": True,
"AUTOREPORT_SD_STATUS": True,
"AUTOREPORT_POS": False,
"EMERGENCY_PARSER": True,
"EXTENDED_M20": False,
},
@@ -188,6 +188,7 @@ class VirtualPrinter(object):
self._temperature_reporter = None
self._sdstatus_reporter = None
self._pos_reporter = None
self.current_line = 0
self.lastN = 0
@@ -704,26 +705,7 @@ class VirtualPrinter(object):
# noinspection PyUnusedLocal
def _gcode_M114(self, data):
# type: (str) -> bool
m114FormatString = self._settings.get(["m114FormatString"])
e = {index: value for index, value in enumerate(self._lastE)}
e["current"] = self._lastE[self.currentExtruder]
e["all"] = " ".join(
[
"E{}:{}".format(num, self._lastE[self.currentExtruder])
for num in range(self.extruderCount)
]
)
output = m114FormatString.format(
x=self._lastX,
y=self._lastY,
z=self._lastZ,
e=e,
f=self._lastF,
a=int(self._lastX * 100),
b=int(self._lastY * 100),
c=int(self._lastZ * 100),
)
output = self._generatePositionOutput()
if not self._okBeforeCommandOutput:
ok = self._ok()
if ok:
@@ -750,6 +732,22 @@ class VirtualPrinter(object):
except AttributeError:
self._send("echo:")
def _gcode_M154(self, data):
# type: (str) -> None
matchS = re.search(r"S([0-9]+)", data)
if matchS is not None:
interval = int(matchS.group(1))
if self._pos_reporter is not None:
self._pos_reporter.cancel()
if interval > 0:
self._pos_reporter = RepeatedTimer(
interval, lambda: self._send(self._generatePositionOutput())
)
self._pos_reporter.start()
else:
self._pos_reporter = None
def _gcode_M155(self, data):
# type: (str) -> None
matchS = re.search(r"S([0-9]+)", data)
@@ -1501,6 +1499,29 @@ class VirtualPrinter(object):
else:
self._send("Not SD printing")
def _generatePositionOutput(self):
# type: () -> str
m114FormatString = self._settings.get(["m114FormatString"])
e = {index: value for index, value in enumerate(self._lastE)}
e["current"] = self._lastE[self.currentExtruder]
e["all"] = " ".join(
[
"E{}:{}".format(num, self._lastE[self.currentExtruder])
for num in range(self.extruderCount)
]
)
output = m114FormatString.format(
x=self._lastX,
y=self._lastY,
z=self._lastZ,
e=e,
f=self._lastF,
a=int(self._lastX * 100),
b=int(self._lastY * 100),
c=int(self._lastZ * 100),
)
return output
def _generateTemperatureOutput(self):
# type: () -> str
if self._settings.get_boolean(["repetierStyleTargetTemperature"]):