Skip to content

Commit 01b7774

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 6a5ec11 commit 01b7774

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
@@ -255,10 +255,8 @@ <h6 id="fl" >First layer gcode generator</h6>
255255
<!-- firstlayerForm -->
256256
<form name="firstlayerForm" id="firstlayerForm" onsubmit="return false;">
257257
<script>
258-
createForm("firstlayer");
258+
createForm("firstlayer");
259259
</script>
260-
<p><input type="button" onclick="processGcode(form)" value="Download Gcode"></p>
261-
<p><input type="button" onclick="resetFormToDefaults(form)" value="Reset parameters"> <input type="button" onclick="outputSettings(form)" value="Output Settings Summary"></p>
262260
</form>
263261
<h2>Interpreting Results:</h2>
264262
<p>Please use the following video as a guide to this test:</p>
@@ -285,10 +283,8 @@ <h6 id="bl">Baseline test print generator</h6>
285283
<!-- baselineForm -->
286284
<form name="baselineForm" id="baselineForm" onsubmit="return false;">
287285
<script>
288-
createForm("baseline");
286+
createForm("baseline");
289287
</script>
290-
<p><input type="button" onclick="processGcode(form)" value="Download Gcode"></p>
291-
<p><input type="button" onclick="resetFormToDefaults(form)" value="Reset parameters"> <input type="button" onclick="outputSettings(form)" value="Output Settings Summary"></p>
292288
</form>
293289
<h2>Interpreting Results:</h2>
294290
<p>Please use the following video as a guide to this test:</p>
@@ -690,8 +686,6 @@ <h6 id="ret">Retraction tuning tower generator</h6>
690686
<script>
691687
createForm("retraction");
692688
</script>
693-
<p><input type="button" onclick="processGcode(form)" value="Download Gcode"></p>
694-
<p><input type="button" onclick="resetFormToDefaults(form)" value="Reset parameters"> <input type="button" onclick="outputSettings(form)" value="Output Settings Summary"></p>
695689
</form>
696690
<h2>Interpreting Results:</h2>
697691
<p>Please use the following video as a guide to this test:</p>
@@ -748,8 +742,6 @@ <h6 id="tmp">Temperature tuning tower generator</h6>
748742
<script>
749743
createForm("temperature");
750744
</script>
751-
<p><input type="button" onclick="processGcode(form)" value="Download Gcode"></p>
752-
<p><input type="button" onclick="resetFormToDefaults(form)" value="Reset parameters"> <input type="button" onclick="outputSettings(form)" value="Output Settings Summary"></p>
753745
</form>
754746
<h2>Interpreting Results:</h2>
755747
<p>Please use the following video as a guide to this test:</p>
@@ -855,8 +847,6 @@ <h6 id="acc">Acceleration & jerk/junction deviation tuning tower generator</h6>
855847
<script>
856848
createForm("acceleration");
857849
</script>
858-
<p><input type="button" onclick="processGcode(form)" value="Download Gcode"></p>
859-
<p><input type="button" onclick="resetFormToDefaults(form)" value="Reset parameters"> <input type="button" onclick="outputSettings(form)" value="Output Settings Summary"></p>
860850
</form>
861851
<h2>Interpreting Results:</h2>
862852
<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
@@ -326,6 +326,13 @@ var endGcode = /*html*/ `<h4>Additional end gcode</h4>
326326

327327
var preview = /*html*/ `<p>It is advised to preview the generated gcode through your slicer or <a href="http://gcode.ws/" target="_blank">Gcode.ws</a> before printing.`;
328328

329+
var downloadGcodeHtml = /*html*/ `<h4>Download</h4>
330+
<p><label>Filename: <input type="text" name="{formName}_filename" value="{formName}.gcode"></label></p>
331+
<p><input type="button" onclick="downloadGcode(form, form['{formName}_filename'].value)" value="Download Gcode"></p>
332+
<p><input type="button" onclick="resetFormToDefaults(form)" value="Reset parameters">
333+
<input type="button" onclick="downloadSettings(form, form['{formName}_filename'].value)" value="Output Settings Summary"></p>
334+
`;
335+
329336
function createForm(n){
330337
document.write('<input type="hidden" name="description" value="'+n+'">')
331338
document.write(nozzleLayer);
@@ -357,4 +364,5 @@ function createForm(n){
357364
}
358365
document.write(endGcode);
359366
document.write(preview);
360-
}
367+
document.write(downloadGcodeHtml.replaceAll('{formName}', n));
368+
}

js/gcodeprocessing.js

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

113113
function processGcode(formName) {
114114
var name = formName.name;
115-
var description = formName.description.value;
116115
var nozzleLayer = formName.nozzleLayer.value;
117116
var bedTemp = formName.bedtemp.value;
118117
var centre = formName.centre.checked;
@@ -544,37 +543,14 @@ function processGcode(formName) {
544543
if(formName.deltaHome.checked == true) {
545544
gcode = gcode.replace(/G28 X0 ; home X axis/, "G28 ; home all on delta");
546545
}
547-
548-
// process finished gcode file
549-
downloadFile(description+'.gcode', gcode);
546+
547+
return gcode;
550548
}
551549

552550
function outputSettings(formName) {
553-
var fileName;
554-
var string = "Settings for ";
555-
switch(formName.name) {
556-
case "firstlayerForm":
557-
string += "first layer"
558-
fileName = "firstlayersettings.txt";
559-
break;
560-
case "baselineForm":
561-
string += "baseline print"
562-
fileName = "baselinesettings.txt";
563-
break;
564-
case "retractionForm":
565-
string += "retraction tuning"
566-
fileName = "retractionsettings.txt";
567-
break;
568-
case "temperatureForm":
569-
string += "temperature tuning"
570-
fileName = "temperaturesettings.txt";
571-
break;
572-
case "accelerationForm":
573-
string += "acceleration and jerk/junction deviation tuning"
574-
fileName = "accelerationsettings.txt";
575-
break;
576-
}
577-
string += " form\n_________________________________________________________________________\n\n";
551+
var string = "";
552+
string += "Settings for " + formName.description.value + " form\n";
553+
string += "_________________________________________________________________________\n\n";
578554
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";
579555
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";
580556
if(formName.psuon.checked == true) {
@@ -653,6 +629,32 @@ function outputSettings(formName) {
653629
string += " B | "+formName.accel_b1.value+" mm/sec/sec | "+formName.accel_b4.value+"\n";
654630
string += " A | "+formName.accel_a1.value+" mm/sec/sec | "+formName.accel_a4.value+"\n";
655631
}
656-
}
657-
downloadFile(fileName, string);
632+
}
633+
return string;
634+
}
635+
636+
637+
function downloadGcode(form, fileName) {
638+
var gcode = processGcode(form);
639+
var settings = outputSettings(form);
640+
641+
// process finished gcode file
642+
if (!fileName) {
643+
fileName = form.description.value + ".gcode";
644+
}
645+
646+
var output = "";
647+
// prefix each line with ; to indicate comment
648+
output += "; " + settings.replaceAll("\n", "\n; ");
649+
output += gcode;
650+
downloadFile(fileName, output);
651+
}
652+
653+
function downloadSettings(form, fileName) {
654+
var settings = outputSettings(form);
655+
656+
if (!fileName) {
657+
fileName = form.description.value + "settings.txt";
658+
}
659+
downloadFile(fileName, settings);
658660
}

0 commit comments

Comments
 (0)