Skip to content

Proof of concept gcode comment section skip #67

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions Actions/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,9 @@ def processAction(self, msg):
elif msg["data"]["command"] == "moveGcodeZ":
if not self.moveGcodeZ(int(msg["data"]["arg"])):
self.data.ui_queue1.put("Alert", "Alert", "Error with moving to Z move")
elif msg["data"]["command"] == "moveGcodeSection":
if not self.moveGcodeSection(int(msg["data"]["arg"])):
self.data.ui_queue1.put("Alert", "Alert", "Error with moving to comment section")
elif msg["data"]["command"] == "moveGcodeGoto":
if not self.moveGcodeIndex(int(msg["data"]["arg"]), True):
self.data.ui_queue1.put("Alert", "Alert", "Error with moving to Z move")
Expand Down Expand Up @@ -644,6 +647,30 @@ def moveGcodeZ(self, moves):
self.data.console_queue.put(str(e))
return False

def moveGcodeSection(self, moves):
'''
Moves the gcode index to the next comment section.
:param moves:
:return:
'''
try:
dist = 0
#determine the number of lines to move to reach the next comment section.
for index, sectionComments in enumerate(self.data.sectionIndex):
if moves > 0 and sectionComments > self.data.gcodeIndex:
dist = self.data.sectionIndex[index + moves - 1] - self.data.gcodeIndex
break
if moves < 0 and sectionComments < self.data.gcodeIndex:
dist = self.data.sectionIndex[index + moves + 1] - self.data.gcodeIndex
if self.moveGcodeIndex(dist):
# this command will continue on in the moveGcodeIndex "if"
return True
else:
return False
except Exception as e:
self.data.console_queue.put(str(e))
return False

def moveGcodeIndex(self, dist, index=False):
'''
Moves the gcodeIndex by either the distance or, in index is True, uses the dist as the index.
Expand Down
2 changes: 2 additions & 0 deletions DataStructures/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ class Data:
gcodeIndex = 0
# Index of changes in z
zMoves = []
# Index of section comments
sectionIndex = []
# Holds the current value of the feed rate
feedRate = 20
# holds the address of the g-code file so that the gcode can be refreshed
Expand Down
5 changes: 5 additions & 0 deletions File/gcodeFile.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,13 @@ def loadUpdateFile(self, gcode=""):

# Find gcode indicies of z moves
self.data.zMoves = [0]
self.data.sectionIndex = [0]
zList = []
for index, line in enumerate(self.data.gcode):
# Matches text "(" + any alphanumeric characters + ")" but ignores "(MSG, gcode message text)"
s = re.search("^\((?!MSG,).+\)", line)
if s:
self.data.sectionIndex.append(index)
filtersparsed = re.sub(r'\(([^)]*)\)', '', line) # replace mach3 style gcode comments with newline
line = re.sub(r';([^.]*)?', '',filtersparsed) # replace standard ; initiated gcode comments with newline
if not line.isspace(): # if all spaces, don't send. likely a comment. #if line.find("(") == -1:
Expand Down
1 change: 1 addition & 0 deletions static/scripts/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ function setupStatusButtons(){
$('#mobileClientStatus').show();
$('#mobileCPUUsage').show();
$('#mobileControllerStatusAlert').show();
$('.navbar-brand').hide();
} else {
$('#mobileClientStatus').hide();
$('#mobileCPUUsage').hide();
Expand Down
24 changes: 24 additions & 0 deletions static/styles/frontpage.css
Original file line number Diff line number Diff line change
Expand Up @@ -143,4 +143,28 @@ html, body{
100% { background-color: #B20000; box-shadow: 0 0 3px #B20000; }
}

.controls {
align-items: center;
}

.controls .btn {
width: 100%;
padding: .375rem .125rem;
}

.controls label {
width: 100%;
margin-bottom: auto;
text-align: right;
}

#pauseButton {
color: #fff;
}

#controllerMessage { overflow-wrap: anywhere; }

.moveButtons .btn {
padding-left: .125rem;
padding-left: .125rem;
}
47 changes: 26 additions & 21 deletions templates/frontpage3d.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,58 +19,57 @@
<div class="flex-fixed-width-item"><!--"col my-sidebar">-->
<h3>Controls</h3>
<div>
<div class="row">
<div class="col mb-1">
<div class="controls row">
<div class="col-3 mb-1">
<button type="button" class="btn btn-secondary btn-block disabler" onclick="action('move','upLeft',$('#distToMove').val())"><i data-feather="arrow-up-left"></i></button>
</div>
<div class="col mb-1">
<div class="col-3 mb-1">
<button type="button" class="btn btn-dark btn-block" onclick="action('move','up',$('#distToMove').val())";><i data-feather="arrow-up"></i></button>
</div>
<div class="col mb-1">
<div class="col-3 mb-1">
<button type="button" class="btn btn-secondary btn-block" onclick="action('move','upRight',$('#distToMove').val())"><i data-feather="arrow-up-right"></i></button>
</div>
<div class="col mb-1">
<div class="col-3 mb-1">
<button type="button" class="btn btn-primary btn-block" onclick="action('macro1')">Macro1</button>
</div>
<div class="w-100"></div>
<div class="col mb-1">
<div class="col-3 mb-1">
<button type="button" class="btn btn-dark btn-block" onclick="action('move','left',$('#distToMove').val())"><i data-feather="arrow-left"></i></button>
</div>
<div class="col mb-1">
<div class="col-3 mb-1">
<button type="button" class="btn btn-dark btn-block" onclick="action('home')"><i data-feather="home"></i></button>
</div>
<div class="col mb-1">
<div class="col-3 mb-1">
<button type="button" class="btn btn-dark btn-block" onclick="action('move','right',$('#distToMove').val())"><i data-feather="arrow-right"></i></button>
</div>
<div class="col mb-1">
<div class="col-3 mb-1">
<button type="button" class="btn btn-primary btn-block" onclick="action('macro2')">Macro2</button>
</div>
<div class="w-100"></div>
<div class="col mb-1">
<div class="col-3 mb-1">
<button type="button" class="btn btn-secondary btn-block" onclick="action('move','downLeft',$('#distToMove').val())"><i data-feather="arrow-down-left"></i></button>
</div>
<div class="col mb-1">
<div class="col-3 mb-1">
<button type="button" class="btn btn-dark btn-block" onclick="action('move','down',$('#distToMove').val())"><i data-feather="arrow-down"></i></button>
</div>
<div class="col mb-1">
<div class="col-3 mb-1">
<button type="button" class="btn btn-secondary btn-block" onclick="action('move','downRight',$('#distToMove').val())"><i data-feather="arrow-down-right"></i></button>
</div>
<div class="col mb-1">
<div class="col-3 mb-1">
<button type="button" class="btn btn-primary btn-block" onclick="requestPage('zAxis');">ZAxis</button>
</div>
</div>
<div class="row">
<div class="col mb-1">
<label>Dist To Move</label>
<div class="w-100"></div>
<div class="col-3 mb-1">
<label>Distance:</label>
</div>
<div class="col-3 mb-1">
<input class="form-control" type="number" step="any" id="distToMove" value="0.01">
</div>
<div class="col-2 mb-1">
<div class="col-3 mb-1">
<button id="units" type="button" class="btn btn-secondary" onclick="unitSwitch();">--</button>
</div>
<div class="col-4 mb-1">
<button type="button" class="btn btn-primary btn-block" onclick="action('defineHome')" >Def. Home</button>
<div class="col-3 mb-1">
<button id="btnDefHome" type="button" class="btn btn-primary btn-block" onclick="action('defineHome')" ><i data-feather="save">Def.</i> <i data-feather="home">Home</i></button>
</div>
</div>
<div class="row">
Expand All @@ -89,7 +88,10 @@ <h3>Controls</h3>
<button type="button" id="stopButton" class="btn btn-block btn-danger" onclick="$(this).removeClass('stopbutton'); action('stopRun')">Stop</button>
</div>
</div>
<div class="row">
<div class="row moveButtons">
<div class="col mb-1">
<button type="button" class="btn btn-block btn-secondary" onclick="action('moveGcodeSection',-1);">&lt;(S)</button>
</div>
<div class="col mb-1">
<button type="button" class="btn btn-block btn-secondary" onclick="action('moveGcodeZ',-1);">&lt;Z</button>
</div>
Expand All @@ -102,6 +104,9 @@ <h3>Controls</h3>
<div class="col mb-1">
<button type="button" class="btn btn-block btn-secondary" onclick="action('moveGcodeZ',1);">Z&gt;</button>
</div>
<div class="col mb-1">
<button type="button" class="btn btn-block btn-secondary" onclick="action('moveGcodeSection',1);">(S)&gt;</button>
</div>
</div>
<div class="row align-items-center">
<div class="col-3 mb-1">
Expand Down
Loading