Skip to content

Commit

Permalink
enh #5, #8, #10 done
Browse files Browse the repository at this point in the history
  • Loading branch information
Olli committed Apr 12, 2018
1 parent a11672a commit 5818d8f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 14 deletions.
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,20 @@ It shows the percentage, the current layer and the total layer count:
- NavBar: Progress: 50% Layer: 60/120

**ATTENTION:**
- The layer information output only works with Cura generated G-Code, because Cura insert the layer information (layer, layerCount) as comments in the file.
- The layer information output only works with Cura/Simplify3D generated G-Code, because these Slicer insert the layer information as comments in the file.
- If the layer comments couldn't found, only the percentage will be displayed
- You need to upload your G-Code after installation of the plugin again (if you want to reuse already stored models in OctoPrint), because while uploading the G-Code is modfied

**CURA Comment Format Example:**
```
;LAYER_COUNT:330
;LAYER:0
```
**Comment Format Examples:**

CURA: ```;LAYER:10```

Simplify3D: ```; layer 10, Z = 1.640```

The implementation is based on four steps:

1. PreProcessing the uploaded G-Code (replace layer-comment with M117)
2. Read total layer count from G-Code before start
2. Read total layer count from G-Code before start (used last layer-comment)
3. G-Code-Hook to collect the current layer information (M117-command from step 1)
4. Progress-Hook to write all information to the printer/navbar

Expand Down
20 changes: 13 additions & 7 deletions octoprint_DisplayLayerProgress/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,27 +20,33 @@
## CONSTs
NOT_PRESENT = "NOT-PRESENT"
LAYER_MESSAGE_PREFIX = "M117 INDICATOR-Layer"
LAYER_EXPRESSION = ";LAYER:([0-9]*)"
LAYER_EXPRESSION_CURA = ";LAYER:([0-9]*)"
LAYER_EXPRESSION_S3D = "; layer ([0-9]*),*"
#LAYER_COUNT_EXPRESSION = ";LAYER_COUNT:([0-9]*)" --> not usful for other slicer
LAYER_COUNT_EXPRESSION = LAYER_MESSAGE_PREFIX+"([0-9]*)"

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


def process_line(self, line):
markerLayer = LAYER_EXPRESSION
pattern = re.compile(markerLayer)

matched = pattern.match(line)
if matched:
currentLayer = matched.group(1)
line = LAYER_MESSAGE_PREFIX + currentLayer + "\r\n"
line = self._checkLineForLayerComment(line, LAYER_EXPRESSION_CURA)
line = self._checkLineForLayerComment(line, LAYER_EXPRESSION_S3D)

#line = strip_comment(line).strip() DO NOT USE, because total-layer count disapears
if not len(line):
return None
return line

def _checkLineForLayerComment(self, line, commentPattern):
pattern = re.compile(commentPattern)
matched = pattern.match(line)

if matched:
currentLayer = matched.group(1)
line = LAYER_MESSAGE_PREFIX + currentLayer + "\r\n"

return line

class DisplaylayerprogressPlugin(octoprint.plugin.SettingsPlugin,
octoprint.plugin.AssetPlugin,
Expand Down

0 comments on commit 5818d8f

Please sign in to comment.