Skip to content

Commit

Permalink
#90 bug fixed: current height now detects relative movement
Browse files Browse the repository at this point in the history
  • Loading branch information
OllisGit committed Oct 26, 2019
1 parent 1257d29 commit cbee8a4
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 4 deletions.
26 changes: 23 additions & 3 deletions octoprint_DisplayLayerProgress/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@
# Same as setup.py 'plugin_identifier'
PLUGIN_KEY_PREFIX = "DisplayLayerProgress_"

MOVEMENT_ABSOLUTE = "g90_abs"
MOVEMENT_RELATIVE = "g91_real"

class LayerDetectorFileProcessor(octoprint.filemanager.util.LineProcessorStream):


Expand Down Expand Up @@ -175,6 +178,9 @@ def __init__(self):
self._layerDurationDeque = None
self._startLayerTime = None

self._movementMode = MOVEMENT_ABSOLUTE
self._currentHeightFloat = 0.0

def initialize(self):
# setup our custom logger
logPostfix = "events"
Expand Down Expand Up @@ -244,11 +250,22 @@ def sendingGCodeHook(self, comm_instance, phase, cmd, cmd_type, gcode, *args, **
self._updateDisplay(UPDATE_DISPLAY_REASON_LAYER_CHANGED)
# filter M117 command, not needed any more
return []

if "G90" == gcode:
self._movementMode = MOVEMENT_ABSOLUTE
if "G91" == gcode:
self._movementMode = MOVEMENT_RELATIVE

# Z-Height
matched = zHeightPattern.match(commandAsString)
if matched:
zHeight = float(matched.group(3))
self._currentHeight = "%.2f" % zHeight
if self._movementMode == MOVEMENT_RELATIVE:
self._currentHeightFloat = self._currentHeightFloat + zHeight
else:
self._currentHeightFloat = zHeight

self._currentHeight = "%.2f" % self._currentHeightFloat
self._updateDisplay(UPDATE_DISPLAY_REASON_HEIGHT_CHANGED)
# feedrate
matched = feedratePattern.match(commandAsString)
Expand Down Expand Up @@ -357,8 +374,10 @@ def on_event(self, event, payload):
if self._settings.get([SETTINGS_KEY_TOTAL_HEIGHT_METHODE]) == HEIGHT_METHODE_Z_MAX:
self._totalHeight = str("%.2f" % totalHeight)
elif self._settings.get([SETTINGS_KEY_TOTAL_HEIGHT_METHODE]) == HEIGHT_METHODE_Z_EXTRUSION:
self._totalHeight = str("%.2f" % float(self._totalHeightWithExtrusion))

if not self._totalHeightWithExtrusion == NOT_PRESENT:
self._totalHeight = str("%.2f" % float(self._totalHeightWithExtrusion))
else:
self._totalHeight = NOT_PRESENT
self._updateDisplay(UPDATE_DISPLAY_REASON_FRONTEND_CALL)

elif event == Events.FILE_DESELECTED:
Expand Down Expand Up @@ -397,6 +416,7 @@ def _resetCurrentValues(self):

self._startLayerTime = None
self._layerDurationDeque = deque(maxlen=self._settings.get_int([SETTINGS_KEY_LAYER_AVARAGE_DURATION_COUNT]))
self._currentHeightFloat = 0.0

def _resetTotalValues(self):
self._layerTotalCount = NOT_PRESENT
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
plugin_name = "DisplayLayerProgress"

# The plugin's version. Can be overwritten within OctoPrint's internal data via __plugin_version__ in the plugin module
plugin_version = "1.14.1"
plugin_version = "1.14.2"

# The plugin's description. Can be overwritten within OctoPrint's internal data via __plugin_description__ in the plugin
# module
Expand Down
17 changes: 17 additions & 0 deletions testdata/issue90/AbsRealPositions.gcode
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
G28
;Absolute positioning
G90
G1 Z5
G1 Z10
G1 Z5
G1 Z20

;Relative positioning
G91
G1 Z5
G1 Z10
G1 Z5

;Absolute positioning
G90
G1 Z33

0 comments on commit cbee8a4

Please sign in to comment.