Skip to content

Commit 3e65412

Browse files
committed
Improve download function
- Allow to specify used filename - Output all settings as a comment on top of gcode - Unify download buttons
1 parent f5761ed commit 3e65412

File tree

4 files changed

+45
-47
lines changed

4 files changed

+45
-47
lines changed

calibration.html

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -294,10 +294,8 @@ <h6 id="fl" >First layer gcode generator</h6>
294294
<!-- firstlayerForm -->
295295
<form name="firstlayerForm" id="firstlayerForm" onsubmit="return false;">
296296
<script>
297-
createForm("firstlayer");
297+
createForm("firstlayer");
298298
</script>
299-
<p><input type="button" onclick="processGcode(form)" value="Download Gcode"></p>
300-
<p><input type="button" onclick="resetFormToDefaults(form)" value="Reset parameters"> <input type="button" onclick="outputSettings(form)" value="Output Settings Summary"></p>
301299
</form>
302300
<h2>Interpreting Results:</h2>
303301
<p>Please use the following video as a guide to this test:</p>
@@ -324,10 +322,8 @@ <h6 id="bl">Baseline test print generator</h6>
324322
<!-- baselineForm -->
325323
<form name="baselineForm" id="baselineForm" onsubmit="return false;">
326324
<script>
327-
createForm("baseline");
325+
createForm("baseline");
328326
</script>
329-
<p><input type="button" onclick="processGcode(form)" value="Download Gcode"></p>
330-
<p><input type="button" onclick="resetFormToDefaults(form)" value="Reset parameters"> <input type="button" onclick="outputSettings(form)" value="Output Settings Summary"></p>
331327
</form>
332328
<h2>Interpreting Results:</h2>
333329
<p>Please use the following video as a guide to this test:</p>
@@ -752,8 +748,6 @@ <h6 id="ret">Retraction tuning tower generator</h6>
752748
<script>
753749
createForm("retraction");
754750
</script>
755-
<p><input type="button" onclick="processGcode(form)" value="Download Gcode"></p>
756-
<p><input type="button" onclick="resetFormToDefaults(form)" value="Reset parameters"> <input type="button" onclick="outputSettings(form)" value="Output Settings Summary"></p>
757751
</form>
758752
<h2>Interpreting Results:</h2>
759753
<p>Please use the following video as a guide to this test:</p>
@@ -810,8 +804,6 @@ <h6 id="tmp">Temperature tuning tower generator</h6>
810804
<script>
811805
createForm("temperature");
812806
</script>
813-
<p><input type="button" onclick="processGcode(form)" value="Download Gcode"></p>
814-
<p><input type="button" onclick="resetFormToDefaults(form)" value="Reset parameters"> <input type="button" onclick="outputSettings(form)" value="Output Settings Summary"></p>
815807
</form>
816808
<h2>Interpreting Results:</h2>
817809
<p>Please use the following video as a guide to this test:</p>
@@ -922,8 +914,6 @@ <h6 id="acc">Acceleration & jerk/junction deviation tuning tower generator</h6>
922914
<script>
923915
createForm("acceleration");
924916
</script>
925-
<p><input type="button" onclick="processGcode(form)" value="Download Gcode"></p>
926-
<p><input type="button" onclick="resetFormToDefaults(form)" value="Reset parameters"> <input type="button" onclick="outputSettings(form)" value="Output Settings Summary"></p>
927917
<p class="warning">This gcode will raise the acceleration limits (<a href="https://marlinfw.org/docs/gcode/M201.html" target="_blank">M201</a>), set acceleration (<a href="https://marlinfw.org/docs/gcode/M204.html" target="_blank">M204</a>) and set junction deviation/jerk (<a href="https://marlinfw.org/docs/gcode/M205.html" target="_blank">M205</a>) for the purposes of the test. If you print another job afterwards these higher values will still be in place. If you are unsure how to restore your previous values, the easiest thing to do is to power cycle the printer.</p>
928918
</form>
929919
<h2>Interpreting Results:</h2>

js/commongcode.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
var commonStart = `; G-Code originally generated by Simplify3D(R) Version 4.1.2
2-
; This calibration test gcode modified by the Teaching Tech Calibration website: https://teachingtechyt.github.io/calibration.html
3-
;M80 ; power supply on
1+
var commonStart = `;M80 ; power supply on
42
G90
53
M82
64
M106 S0

js/createform.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,13 @@ var endGcode = /*html*/ `<h4>Additional end gcode</h4>
459459

460460
var preview = /*html*/ `<p>It is advised to preview the generated gcode through your slicer or <a href="http://zupfe.velor.ca" target="_blank">Zupfe GCode Viewer</a> before printing.`;
461461

462+
var downloadGcodeHtml = /*html*/ `<h4>Download</h4>
463+
<p><label>Filename: <input type="text" name="{formName}_filename" value="{formName}.gcode"></label></p>
464+
<p><input type="button" onclick="downloadGcode(form, form['{formName}_filename'].value)" value="Download Gcode"></p>
465+
<p><input type="button" onclick="resetFormToDefaults(form)" value="Reset parameters">
466+
<input type="button" onclick="downloadSettings(form, form['{formName}_filename'].value)" value="Output Settings Summary"></p>
467+
`;
468+
462469
function createForm(n){
463470
document.write('<input type="hidden" name="description" value="'+n+'">')
464471
document.write(nozzleLayer);
@@ -495,4 +502,5 @@ function createForm(n){
495502
}
496503
document.write(endGcode);
497504
document.write(preview);
498-
}
505+
document.write(downloadGcodeHtml.replaceAll('{formName}', n));
506+
}

js/gcodeprocessing.js

Lines changed: 33 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,6 @@ function updateFeedsTower(feedrate) {
118118

119119
function processGcode(formName) {
120120
var name = formName.name;
121-
var description = formName.description.value;
122121
var nozzleLayer = formName.nozzleLayer.value;
123122
var bedTemp = formName.bedtemp.value;
124123
var centre = formName.centre.checked;
@@ -600,37 +599,14 @@ function processGcode(formName) {
600599
if(formName.deltaHome.checked == true) {
601600
gcode = gcode.replace(/G28 X0 ; home X axis/, "G28 ; home all on delta");
602601
}
603-
604-
// process finished gcode file
605-
downloadFile(description+'.gcode', gcode);
602+
603+
return gcode;
606604
}
607605

608606
function outputSettings(formName) {
609-
var fileName;
610-
var string = "Settings for ";
611-
switch(formName.name) {
612-
case "firstlayerForm":
613-
string += "first layer"
614-
fileName = "firstlayersettings.txt";
615-
break;
616-
case "baselineForm":
617-
string += "baseline print"
618-
fileName = "baselinesettings.txt";
619-
break;
620-
case "retractionForm":
621-
string += "retraction tuning"
622-
fileName = "retractionsettings.txt";
623-
break;
624-
case "temperatureForm":
625-
string += "temperature tuning"
626-
fileName = "temperaturesettings.txt";
627-
break;
628-
case "accelerationForm":
629-
string += "acceleration and jerk/junction deviation tuning"
630-
fileName = "accelerationsettings.txt";
631-
break;
632-
}
633-
string += " form\n_________________________________________________________________________\n\n";
607+
var string = "";
608+
string += "Settings for " + formName.description.value + " form\n";
609+
string += "_________________________________________________________________________\n\n";
634610
string += "G-Code originally generated by Simplify3D(R) Version 4.1.2\nThis calibration test gcode modified by the Teaching Tech Calibration website: https://teachingtechyt.github.io/calibration.html\n";
635611
string += "All changes are marked in the gcode with 'custom' at the end of each line. Open the gcode in a text editor and search for this to your check inputs if needed.\n\n";
636612

@@ -728,6 +704,32 @@ function outputSettings(formName) {
728704
string += " B | "+formName.accel_b1.value+" mm/sec/sec | "+formName.accel_b4.value+"\n";
729705
string += " A | "+formName.accel_a1.value+" mm/sec/sec | "+formName.accel_a4.value+"\n";
730706
}
731-
}
732-
downloadFile(fileName, string);
707+
}
708+
return string;
709+
}
710+
711+
712+
function downloadGcode(form, fileName) {
713+
var gcode = processGcode(form);
714+
var settings = outputSettings(form);
715+
716+
// process finished gcode file
717+
if (!fileName) {
718+
fileName = form.description.value + ".gcode";
719+
}
720+
721+
var output = "";
722+
// prefix each line with ; to indicate comment
723+
output += "; " + settings.replaceAll("\n", "\n; ");
724+
output += gcode;
725+
downloadFile(fileName, output);
726+
}
727+
728+
function downloadSettings(form, fileName) {
729+
var settings = outputSettings(form);
730+
731+
if (!fileName) {
732+
fileName = form.description.value + "settings.txt";
733+
}
734+
downloadFile(fileName, settings);
733735
}

0 commit comments

Comments
 (0)