Skip to content

Commit

Permalink
New Version
Browse files Browse the repository at this point in the history
#79 REST API for values
#76 don't count on negativ extrusion
  • Loading branch information
OllisGit committed Aug 17, 2019
1 parent 427c468 commit 2bf42f1
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 23 deletions.
29 changes: 29 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,35 @@ see [Release-Overview](https://github.com/OllisGit/OctoPrint-DisplayLayerProgres

---
# Developer - Section
## REST - API
You can receive the layer/height and other values via a GET-Call.

curl -H "X-Api-Key:57FECA453FE94D46851EFC94BC9B5265" http://localhost:5000/plugin/DisplayLayerProgress/values

{
"fanSpeed": "80%",
"feedrate": "6000",
"feedrateG0": "6000",
"feedrateG1": "1575",
"height": {
"current": "0.96",
"total": "15.08",
"totalWithExtrusion": "10.08"
},
"layer": {
"averageLayerDuration": "-",
"current": "3",
"lastLayerDuration": "00m:07s",
"total": "41"
},
"print": {
"progress": "2",
"timeLeft": "12m7s",
"timeLeftInSeconds": 727
}
}

## Events
Plugin sends the following custom events to the eventbus like this:

eventManager().fire(eventKey, eventPayload)
Expand Down
70 changes: 48 additions & 22 deletions octoprint_DisplayLayerProgress/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import octoprint.util
import re
import flask
from flask import Response
import json
import logging
import threading
Expand Down Expand Up @@ -132,7 +133,8 @@ class DisplaylayerprogressPlugin(
# my stuff
octoprint.plugin.EventHandlerPlugin,
octoprint.plugin.ProgressPlugin,
octoprint.plugin.SimpleApiPlugin
octoprint.plugin.SimpleApiPlugin,
octoprint.plugin.BlueprintPlugin
):
# VAR
_layerTotalCount = NOT_PRESENT
Expand All @@ -156,6 +158,11 @@ def __init__(self):
self._showFeedrateOnPrinterDisplay = False
self._showFanSpeedOnPrinterDisplay = False

self._printTimeLeft = ""
self._printTimeLeftInSeconds = ""
self._lastLayerDuration = ""
self._averageLayerDuration = ""

self._layerExpressionsValid = True
self._allLayerExpressions = []

Expand Down Expand Up @@ -312,16 +319,18 @@ def on_event(self, event, payload):
for line in f:
try:
lineNumber += 1
matched = pattern.match(line)
matched = pattern.match(line) #identify layer count
if matched:
layerOffset = self._settings.get_int([SETTINGS_KEY_LAYER_OFFSET])
self._layerTotalCount = str(int(matched.group(1)) + layerOffset)

matched = zHeightPattern.match(line)
if matched:
currentHeight = float(matched.group(3))
if currentHeight > totalHeight:
totalHeight = currentHeight
# don't count on negativ extrusion, see issue #76
if ("E-" in line) == False:
currentHeight = float(matched.group(3))
if currentHeight > totalHeight:
totalHeight = currentHeight

matched = extrusionPattern.match(line)
if matched:
Expand Down Expand Up @@ -434,22 +443,24 @@ def _updateDisplay(self, updateReason):
currentData = self._printer.get_current_data()

# NOT NEEDED at the moment estPrintTime = currentData["job"]["estimatedPrintTime"]
printTimeLeft = ""
printTimeLeftInSeconds = currentData["progress"]["printTimeLeft"]
if printTimeLeftInSeconds is not None:
printTimeLeft = stringUtils.secondsToText(printTimeLeftInSeconds)
self._printTimeLeft = "-"
self._printTimeLeftInSeconds = currentData["progress"]["printTimeLeft"]
if self._printTimeLeftInSeconds is not None:
self._printTimeLeft = stringUtils.secondsToText(self._printTimeLeftInSeconds)
else:
self._printTimeLeftInSeconds = "-"

feedrate = self._calculateFeedrate(self._feedrate)
feedrateG0 = self._calculateFeedrate(self._feedrateG0)
feedrateG1 = self._calculateFeedrate(self._feedrateG1)

## calculate layer duration
lastLayerDuration = ""
averageLayerDuration = ""
self._lastLayerDuration = "-"
self._averageLayerDuration = "-"

if len(self._layerDurationDeque) > 0:
lastLayerDurationTimeDelta = self._layerDurationDeque[-1]
lastLayerDuration = stringUtils.strfdelta(lastLayerDurationTimeDelta, self._settings.get([SETTINGS_KEY_LAYER_AVARAGE_FORMAT_PATTERN]))
self._lastLayerDuration = stringUtils.strfdelta(lastLayerDurationTimeDelta, self._settings.get([SETTINGS_KEY_LAYER_AVARAGE_FORMAT_PATTERN]))

# avarag calc only if we have engough layer measurments
allLayerDurationCount = len(self._layerDurationDeque)
Expand All @@ -463,7 +474,7 @@ def _updateDisplay(self, updateReason):

calcAverageDuration = calcAverageDuration / allLayerDurationCount
calcAverageDurationTimeDelta = timedelta(seconds = calcAverageDuration)
averageLayerDuration = stringUtils.strfdelta(calcAverageDurationTimeDelta, self._settings.get([SETTINGS_KEY_LAYER_AVARAGE_FORMAT_PATTERN]))
self._averageLayerDuration = stringUtils.strfdelta(calcAverageDurationTimeDelta, self._settings.get([SETTINGS_KEY_LAYER_AVARAGE_FORMAT_PATTERN]))

currentValueDict = {
PROGRESS_KEYWORD_EXPRESSION: self._progress,
Expand All @@ -475,9 +486,9 @@ def _updateDisplay(self, updateReason):
FEEDRATE_G0_KEYWORD_EXPRESSION: feedrateG0,
FEEDRATE_G1_KEYWORD_EXPRESSION: feedrateG1,
FANSPEED_KEYWORD_EXPRESSION: self._fanSpeed,
PRINTTIME_LEFT_EXPRESSION: printTimeLeft,
LAYER_LAST_DURATION_EXPRESSION: lastLayerDuration,
LAYER_AVERAGE_DURATION_EXPRESSION: averageLayerDuration
PRINTTIME_LEFT_EXPRESSION: self._printTimeLeft,
LAYER_LAST_DURATION_EXPRESSION: self._lastLayerDuration,
LAYER_AVERAGE_DURATION_EXPRESSION: self._averageLayerDuration
}
printerMessagePattern = self._settings.get([SETTINGS_KEY_PRINTERDISPLAY_MESSAGEPATTERN])
printerMessageCommand = "M117 " + stringUtils.multiple_replace(printerMessagePattern, currentValueDict)
Expand Down Expand Up @@ -537,17 +548,17 @@ def _updateDisplay(self, updateReason):
eventPayload = dict(
totalLayer = self._layerTotalCount,
currentLayer = self._currentLayer,
lastLayerDuration = lastLayerDuration,
averageLayerDuration = averageLayerDuration,
lastLayerDuration = self._lastLayerDuration,
averageLayerDuration = self._averageLayerDuration,
currentHeight = self._currentHeight,
totalHeightWithExtrusion = self._totalHeightWithExtrusion,
feedrate = self._feedrate,
feedrateG0 = self._feedrateG0,
feedrateG1 = self._feedrateG1,
fanspeed = self._fanSpeed,
progress =self._progress,
printTimeLeft = printTimeLeft,
printTimeLeftInSeconds = printTimeLeftInSeconds,
printTimeLeft = self._printTimeLeft,
printTimeLeftInSeconds = self._printTimeLeftInSeconds,
)
eventManager().fire(eventKey, eventPayload)

Expand Down Expand Up @@ -686,19 +697,34 @@ def on_api_get(self, request):

return flask.jsonify(self.get_settings_defaults())

# default/other action
self._updateDisplay(UPDATE_DISPLAY_REASON_FRONTEND_CALL)

@octoprint.plugin.BlueprintPlugin.route("/values", methods=["GET"])
def get_displayLayerProgressValues(self):

# return data via the default API endpoint
return flask.jsonify({
"layer": {
"total": self._layerTotalCount,
"current": self._currentLayer
"current": self._currentLayer,
"averageLayerDuration": self._averageLayerDuration,
"lastLayerDuration": self._lastLayerDuration
},
"height": {
"total": self._totalHeight,
"totalWithExtrusion": self._totalHeightWithExtrusion,
"current": self._currentHeight
},
"fanSpeed": self._fanSpeed,
"feedrate": self._feedrate
"feedrate": self._feedrate,
"feedrateG0": self._feedrateG0,
"feedrateG1": self._feedrateG1,
"print": {
"progress": self._progress,
"timeLeft": self._printTimeLeft,
"timeLeftInSeconds": self._printTimeLeftInSeconds
}
})


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.11.1"
plugin_version = "1.12.0"

# The plugin's description. Can be overwritten within OctoPrint's internal data via __plugin_description__ in the plugin
# module
Expand Down

0 comments on commit 2bf42f1

Please sign in to comment.