Skip to content

Commit c16f9d7

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 6689845 commit c16f9d7

File tree

4 files changed

+45
-49
lines changed

4 files changed

+45
-49
lines changed

calibration.html

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -293,10 +293,8 @@ <h6 id="fl" >First layer gcode generator</h6>
293293
<!-- firstlayerForm -->
294294
<form name="firstlayerForm" id="firstlayerForm" onsubmit="return false;">
295295
<script>
296-
createForm("firstlayer");
296+
createForm("firstlayer");
297297
</script>
298-
<p><input type="button" onclick="processGcode(form)" value="Download Gcode"></p>
299-
<p><input type="button" onclick="resetFormToDefaults(form)" value="Reset parameters"> <input type="button" onclick="outputSettings(form)" value="Output Settings Summary"></p>
300298
</form>
301299
<h2>Interpreting Results:</h2>
302300
<p>Please use the following video as a guide to this test:</p>
@@ -323,10 +321,8 @@ <h6 id="bl">Baseline test print generator</h6>
323321
<!-- baselineForm -->
324322
<form name="baselineForm" id="baselineForm" onsubmit="return false;">
325323
<script>
326-
createForm("baseline");
324+
createForm("baseline");
327325
</script>
328-
<p><input type="button" onclick="processGcode(form)" value="Download Gcode"></p>
329-
<p><input type="button" onclick="resetFormToDefaults(form)" value="Reset parameters"> <input type="button" onclick="outputSettings(form)" value="Output Settings Summary"></p>
330326
</form>
331327
<h2>Interpreting Results:</h2>
332328
<p>Please use the following video as a guide to this test:</p>
@@ -751,8 +747,6 @@ <h6 id="ret">Retraction tuning tower generator</h6>
751747
<script>
752748
createForm("retraction");
753749
</script>
754-
<p><input type="button" onclick="processGcode(form)" value="Download Gcode"></p>
755-
<p><input type="button" onclick="resetFormToDefaults(form)" value="Reset parameters"> <input type="button" onclick="outputSettings(form)" value="Output Settings Summary"></p>
756750
</form>
757751
<h2>Interpreting Results:</h2>
758752
<p>Please use the following video as a guide to this test:</p>
@@ -809,8 +803,6 @@ <h6 id="tmp">Temperature tuning tower generator</h6>
809803
<script>
810804
createForm("temperature");
811805
</script>
812-
<p><input type="button" onclick="processGcode(form)" value="Download Gcode"></p>
813-
<p><input type="button" onclick="resetFormToDefaults(form)" value="Reset parameters"> <input type="button" onclick="outputSettings(form)" value="Output Settings Summary"></p>
814806
</form>
815807
<h2>Interpreting Results:</h2>
816808
<p>Please use the following video as a guide to this test:</p>
@@ -921,8 +913,6 @@ <h6 id="acc">Acceleration & jerk/junction deviation tuning tower generator</h6>
921913
<script>
922914
createForm("acceleration");
923915
</script>
924-
<p><input type="button" onclick="processGcode(form)" value="Download Gcode"></p>
925-
<p><input type="button" onclick="resetFormToDefaults(form)" value="Reset parameters"> <input type="button" onclick="outputSettings(form)" value="Output Settings Summary"></p>
926916
<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>
927917
</form>
928918
<h2>Interpreting Results:</h2>
@@ -1183,8 +1173,6 @@ <h6 id="spd">Speed/feedrate tuning tower generator</h6>
11831173
<script>
11841174
createForm("speed");
11851175
</script>
1186-
<p><input type="button" onclick="processGcode(form)" value="Download Gcode"></p>
1187-
<p><input type="button" onclick="resetFormToDefaults(form)" value="Reset parameters"> <input type="button" onclick="outputSettings(form)" value="Output Settings Summary"></p>
11881176
</form>
11891177
<h2>Interpreting Results:</h2>
11901178
<p>Please use the following video as a guide to this test:</p>

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
@@ -457,6 +457,13 @@ var endGcode = /*html*/ `<h4>Additional end gcode</h4>
457457

458458
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.`;
459459

460+
var downloadGcodeHtml = /*html*/ `<h4>Download</h4>
461+
<p><label>Filename: <input type="text" name="{formName}_filename" value="{formName}.gcode"></label></p>
462+
<p><input type="button" onclick="downloadGcode(form, form['{formName}_filename'].value)" value="Download Gcode"></p>
463+
<p><input type="button" onclick="resetFormToDefaults(form)" value="Reset parameters">
464+
<input type="button" onclick="downloadSettings(form, form['{formName}_filename'].value)" value="Output Settings Summary"></p>
465+
`;
466+
460467
function createForm(n){
461468
document.write('<input type="hidden" name="description" value="'+n+'">')
462469
document.write(nozzleLayer);
@@ -493,4 +500,5 @@ function createForm(n){
493500
}
494501
document.write(endGcode);
495502
document.write(preview);
496-
}
503+
document.write(downloadGcodeHtml.replaceAll('{formName}', n));
504+
}

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;
@@ -592,37 +591,14 @@ function processGcode(formName) {
592591
if(formName.deltaHome.checked == true) {
593592
gcode = gcode.replace(/G28 X0 ; home X axis/, "G28 ; home all on delta");
594593
}
595-
596-
// process finished gcode file
597-
downloadFile(description+'.gcode', gcode);
594+
595+
return gcode;
598596
}
599597

600598
function outputSettings(formName) {
601-
var fileName;
602-
var string = "Settings for ";
603-
switch(formName.name) {
604-
case "firstlayerForm":
605-
string += "first layer"
606-
fileName = "firstlayersettings.txt";
607-
break;
608-
case "baselineForm":
609-
string += "baseline print"
610-
fileName = "baselinesettings.txt";
611-
break;
612-
case "retractionForm":
613-
string += "retraction tuning"
614-
fileName = "retractionsettings.txt";
615-
break;
616-
case "temperatureForm":
617-
string += "temperature tuning"
618-
fileName = "temperaturesettings.txt";
619-
break;
620-
case "accelerationForm":
621-
string += "acceleration and jerk/junction deviation tuning"
622-
fileName = "accelerationsettings.txt";
623-
break;
624-
}
625-
string += " form\n_________________________________________________________________________\n\n";
599+
var string = "";
600+
string += "Settings for " + formName.description.value + " form\n";
601+
string += "_________________________________________________________________________\n\n";
626602
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";
627603
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";
628604

@@ -720,6 +696,32 @@ function outputSettings(formName) {
720696
string += " B | "+formName.accel_b1.value+" mm/sec/sec | "+formName.accel_b4.value+"\n";
721697
string += " A | "+formName.accel_a1.value+" mm/sec/sec | "+formName.accel_a4.value+"\n";
722698
}
723-
}
724-
downloadFile(fileName, string);
699+
}
700+
return string;
701+
}
702+
703+
704+
function downloadGcode(form, fileName) {
705+
var gcode = processGcode(form);
706+
var settings = outputSettings(form);
707+
708+
// process finished gcode file
709+
if (!fileName) {
710+
fileName = form.description.value + ".gcode";
711+
}
712+
713+
var output = "";
714+
// prefix each line with ; to indicate comment
715+
output += "; " + settings.replaceAll("\n", "\n; ");
716+
output += gcode;
717+
downloadFile(fileName, output);
718+
}
719+
720+
function downloadSettings(form, fileName) {
721+
var settings = outputSettings(form);
722+
723+
if (!fileName) {
724+
fileName = form.description.value + "settings.txt";
725+
}
726+
downloadFile(fileName, settings);
725727
}

0 commit comments

Comments
 (0)