From c818e7618e5afe32b66f6da0c73762fe6a61b743 Mon Sep 17 00:00:00 2001
From: Adukra <43076626+Adukra@users.noreply.github.com>
Date: Fri, 7 Sep 2018 18:15:23 -0400
Subject: [PATCH 1/8] UI Panel for GCode

---
 index.html | 19 +++++++++++++++++++
 js/main.js | 35 +++++++++++++++++++++++++++++++++++
 2 files changed, 54 insertions(+)

diff --git a/index.html b/index.html
index aea2dad..37e2064 100644
--- a/index.html
+++ b/index.html
@@ -341,6 +341,25 @@ <h3 class="panel-title">Colors</h3>
                     </div>
                 </div><!-- #colors -->
 
+                <div id="gcode" class="panel panel-default">
+                    <div class="panel-heading">
+                        <button class="panel-toggle btn btn-default btn-xs pull-right" type="button" data-toggle="collapse" data-target="#gcode-body">
+                            <span class="glyphicon glyphicon-menu-down"></span>
+                        </button>
+                        <h3 class="panel-title">GCode</h3>
+                    </div>
+                    <div id="gcode-body" class="panel-body collapse">
+                        <div class="form-group">
+                            <label for="start" style="width: 100%; float: none;" >Start</label>
+                            <textarea id="start" class="form-control" rows="5" style="width: 100%; float: none;" ></textarea>
+                        </div>
+                        <div class="form-group">
+                            <label for="end" style="width: 100%; float: none;" >End</label>
+                            <textarea id="end" class="form-control" rows="5" style="width: 100%; float: none;" ></textarea>
+                        </div>
+                    </div>
+                </div><!-- #gcode -->
+
             </div><!-- #sidebar -->
 
             <div id="main">
diff --git a/js/main.js b/js/main.js
index 281e8a3..339e824 100644
--- a/js/main.js
+++ b/js/main.js
@@ -85,6 +85,14 @@ var settings = new SLAcer.Settings({
             position : 7
         }
     },
+    gcode: {
+        start : 'G21;\nG91;\nM17;\nM106 S0;\nG28 Z0;\n;W:480;\n;H:854;\n',
+        end: 'M106 S0;\nG1 Z20.0;\nG4 S300;\nM18;',
+        panel: {
+            collapsed: true,
+            position : 8
+        }
+    },
     viewer3d: {
         color: 0xffffff
     }
@@ -1072,6 +1080,33 @@ $sliceColor.colorpicker().on('changeColor.colorpicker', function(e) {
     }
 });
 
+// gcode
+var $gcodeBody = initPanel('gcode');
+var $gcodeStart = $gcodeBody.find('#start');
+var $gcodeEnd = $gcodeBody.find('#end');
+
+function updateGcodeUI() {
+    var gcode = settings.get('gcode');
+
+    $gcodeStart.val(gcode.start);
+    $gcodeEnd.val(gcode.end);
+}
+
+function updateGcodeSettings() {
+    var startText = $gcodeStart.val();
+    var endText = $gcodeEnd.val();
+
+    settings.set('gcode', {
+        start   : $gcodeStart.val(),
+        end     : $gcodeEnd.val(),
+    });
+}
+
+$gcodeStart.on('change', updateGcodeSettings);
+$gcodeEnd.on('change', updateGcodeSettings);
+
+updateGcodeUI();
+
 // Alert
 var $alertPanel   = $('#alert');
 var $alertMessage = $alertPanel.find('.message');

From c648543123143c318caa3fc8281562383c9b7150 Mon Sep 17 00:00:00 2001
From: Adukra <43076626+Adukra@users.noreply.github.com>
Date: Fri, 7 Sep 2018 18:26:41 -0400
Subject: [PATCH 2/8] use settings when generating GCode

now uses gcode.start for beginning of generated gcode and gcode.end at the end
---
 js/main.js | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/js/main.js b/js/main.js
index 339e824..18465d2 100644
--- a/js/main.js
+++ b/js/main.js
@@ -778,7 +778,9 @@ function slice() {
 function endSlicing() {
 
     if(WOWExport) {// GCode & export logic
-        wowFile += "M106 S0;\nG1 Z20.0;\nG4 S300;\nM18;"
+        // add gcode footer from settings
+        var gcode = settings.get('gcode');
+        wowFile += gcode.end;
 
         zipFile.file("print.wow", wowFile, {binary: true});
 
@@ -864,7 +866,9 @@ function startSlicing() {
         */
         //console.log(textDecoder.encode(binary_layer));
 
-        wowFile += "G21;\nG91;\nM17;\nM106 S0;\nG28 Z0;\n;W:480;\n;H:854;\n"
+        // use gcode header from settings
+        var gcode = settings.get('gcode');
+        wowFile += gcode.start;
     }
 
     slicesNumber && slice();

From 7b304172eacb1cf70f731d7c720fecf9d8502d25 Mon Sep 17 00:00:00 2001
From: Adukra <43076626+Adukra@users.noreply.github.com>
Date: Fri, 7 Sep 2018 19:02:08 -0400
Subject: [PATCH 3/8] reset to default option for gcode

a button for resetting gcode to default seemed wise after some testing
---
 css/main.css |  3 ++-
 index.html   |  6 ++++--
 js/main.js   | 26 ++++++++++++++++++++++++--
 3 files changed, 30 insertions(+), 5 deletions(-)

diff --git a/css/main.css b/css/main.css
index ee1457a..9e65683 100644
--- a/css/main.css
+++ b/css/main.css
@@ -54,7 +54,8 @@
 }
 
 #sidebar .info-value,
-#sidebar .form-control {
+#sidebar .form-control,
+#sidebar .btn-reset {
     width: 40%;
     float: left;
 }
diff --git a/index.html b/index.html
index 37e2064..519c619 100644
--- a/index.html
+++ b/index.html
@@ -350,11 +350,13 @@ <h3 class="panel-title">GCode</h3>
                     </div>
                     <div id="gcode-body" class="panel-body collapse">
                         <div class="form-group">
-                            <label for="start" style="width: 100%; float: none;" >Start</label>
+                            <label for="resetStart" >Start</label>
+                            <span class="btn btn-default btn-xs btn-reset" id="resetStart" title="Reset to default Start GCode" >Reset</span>
                             <textarea id="start" class="form-control" rows="5" style="width: 100%; float: none;" ></textarea>
                         </div>
                         <div class="form-group">
-                            <label for="end" style="width: 100%; float: none;" >End</label>
+                            <label for="resetEnd" >End</label>
+                            <span class="btn btn-default btn-xs btn-reset" id="resetEnd" title="Reset to default End GCode" >Reset</span>
                             <textarea id="end" class="form-control" rows="5" style="width: 100%; float: none;" ></textarea>
                         </div>
                     </div>
diff --git a/js/main.js b/js/main.js
index 18465d2..379e6f1 100644
--- a/js/main.js
+++ b/js/main.js
@@ -86,8 +86,8 @@ var settings = new SLAcer.Settings({
         }
     },
     gcode: {
-        start : 'G21;\nG91;\nM17;\nM106 S0;\nG28 Z0;\n;W:480;\n;H:854;\n',
-        end: 'M106 S0;\nG1 Z20.0;\nG4 S300;\nM18;',
+        start : getDefaultGcodeStart(),
+        end: getDefaultGcodeEnd(),
         panel: {
             collapsed: true,
             position : 8
@@ -1088,6 +1088,8 @@ $sliceColor.colorpicker().on('changeColor.colorpicker', function(e) {
 var $gcodeBody = initPanel('gcode');
 var $gcodeStart = $gcodeBody.find('#start');
 var $gcodeEnd = $gcodeBody.find('#end');
+var $gcodeResetStart = $gcodeBody.find('#resetStart');
+var $gcodeResetEnd = $gcodeBody.find('#resetEnd');
 
 function updateGcodeUI() {
     var gcode = settings.get('gcode');
@@ -1106,8 +1108,28 @@ function updateGcodeSettings() {
     });
 }
 
+function resetGcodeStart() {
+    $gcodeStart.val(getDefaultGcodeStart());
+    updateGcodeSettings();
+}
+
+function resetGcodeEnd() {
+    $gcodeEnd.val(getDefaultGcodeEnd());
+    updateGcodeSettings();
+}
+
+function getDefaultGcodeStart() {
+    return 'G21;\nG91;\nM17;\nM106 S0;\nG28 Z0;\n;W:480;\n;H:854;\n';
+}
+
+function getDefaultGcodeEnd() {
+    return 'M106 S0;\nG1 Z20.0;\nG4 S300;\nM18;';
+}
+
 $gcodeStart.on('change', updateGcodeSettings);
 $gcodeEnd.on('change', updateGcodeSettings);
+$gcodeResetStart.on('click', resetGcodeStart);
+$gcodeResetEnd.on('click', resetGcodeEnd);
 
 updateGcodeUI();
 

From be9c74a850e31cb0de790b29068d2dfaf4146b9f Mon Sep 17 00:00:00 2001
From: Adukra <43076626+Adukra@users.noreply.github.com>
Date: Fri, 7 Sep 2018 19:10:37 -0400
Subject: [PATCH 4/8] comments

was double-checking that I have the right start and end gcode defaults and added links to documentation in comments
---
 js/main.js | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/js/main.js b/js/main.js
index 379e6f1..532648c 100644
--- a/js/main.js
+++ b/js/main.js
@@ -1119,11 +1119,11 @@ function resetGcodeEnd() {
 }
 
 function getDefaultGcodeStart() {
-    return 'G21;\nG91;\nM17;\nM106 S0;\nG28 Z0;\n;W:480;\n;H:854;\n';
+    return 'G21;\nG91;\nM17;\nM106 S0;\nG28 Z0;\n;W:480;\n;H:854;\n'; // see https://github.com/bastirichter/Sparkmaker/blob/master/file_format.md for details
 }
 
 function getDefaultGcodeEnd() {
-    return 'M106 S0;\nG1 Z20.0;\nG4 S300;\nM18;';
+    return 'M106 S0;\nG1 Z20.0;\nG4 S300;\nM18;'; // see https://github.com/bastirichter/Sparkmaker/blob/master/file_format.md for details
 }
 
 $gcodeStart.on('change', updateGcodeSettings);

From 1e639af20d1681bc8b3e518a6b5064ab22132ada Mon Sep 17 00:00:00 2001
From: Adukra <43076626+Adukra@users.noreply.github.com>
Date: Sat, 22 Sep 2018 20:47:47 -0400
Subject: [PATCH 5/8] export SM FHD format

experimental option to export in SparkMaker FHD file format
---
 index.html |  1 +
 js/main.js | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 53 insertions(+), 1 deletion(-)

diff --git a/index.html b/index.html
index 519c619..85cdbd4 100644
--- a/index.html
+++ b/index.html
@@ -212,6 +212,7 @@ <h3 class="panel-title">Slicer</h3>
                             <input type="radio" name="slicer-image-extension" id="slicer-image-extension-png" value="png" /> png
                             <input type="radio" name="slicer-image-extension" id="slicer-image-extension-svg" value="svg" /> svg
                             <input type="radio" name="slicer-image-extension" id="slicer-image-extension-wow" value="wow" checked="checked" /> wow
+                            <input type="radio" name="slicer-image-extension" id="slicer-image-extension-fhd" value="fhd" checked="checked" /> FHD
                         </div>
 
                         <hr />
diff --git a/js/main.js b/js/main.js
index 532648c..e06c57c 100644
--- a/js/main.js
+++ b/js/main.js
@@ -208,6 +208,28 @@ function getSlice(layerNumber) {
             if (settings.get('slicer.folder')) {
                 zipFolder.file(fileName, imgData, {base64: true});
             }
+        } else if (FHDExport) {
+            // image file
+            var fileName = 'slice (' + layerNumber + ').png';
+            var imgData  = dataURL.substr(dataURL.indexOf(',') + 1);
+            zipFolder.file(fileName, imgData, {base64: true});
+
+            // gcode
+            wowFile += "M106 S0;\n"; // UV lights off
+            wowFile += "G1 Z" + settings.get('slicer.lifting.height') + " F" + settings.get('slicer.lifting.speed') + ";\n"; // raise bed up specified height and speed
+            wowFile += "G1 Z-" + (settings.get('slicer.lifting.height') - settings.get('slicer.layers.height') / 1000) + " F" + settings.get('slicer.lifting.decline') + ";\n"; // lower bed down specified height and speed
+
+            //bottom layer
+            var exposure_time;
+            if(layerNumber<=settings.get('slicer.layers.bottom')){
+                exposure_time = settings.get('slicer.light.bottom');
+            }else{
+                exposure_time = settings.get('slicer.light.on');
+            }
+
+            wowFile += "{" + fileName + "};\n"; // link to layer image
+            wowFile += "M106 S"+settings.get('slicer.light.strength')+";\n"; // UV lights on specified strength
+            wowFile += "G4 S" + exposure_time / 1000 + ";\n"; // wait specified layer cure time
         }else if (WOWExport) {
             //console.log('layer number:', layerNumber);
             //console.log('z position :', zPosition);
@@ -666,6 +688,7 @@ var $slicerLiftingHeight = $slicerBody.find('#slicer-lifting-height');
 var $slicerExportPNG = $slicerBody.find('#slicer-image-extension-png');
 var $slicerExportSVG = $slicerBody.find('#slicer-image-extension-svg');
 var $slicerExportWOW = $slicerBody.find('#slicer-image-extension-wow');
+var $slicerExportFHD = $slicerBody.find('#slicer-image-extension-fhd');
 
 var $slicerSpeedYes    = $slicerBody.find('#slicer-speed-yes');
 var $slicerSpeedNo     = $slicerBody.find('#slicer-speed-no');
@@ -715,6 +738,7 @@ function updateSlicerSettings() {
     settings.set('slicer.png', $slicerExportPNG[0].checked);
     settings.set('slicer.svg', $slicerExportSVG[0].checked);
     settings.set('slicer.wow', $slicerExportWOW[0].checked);
+    settings.set('slicer.fhd', $slicerExportFHD[0].checked);
 
     settings.set('slicer.zip', $slicerMakeZipYes[0].checked);
 
@@ -738,6 +762,7 @@ var zipFolder;
 var wowFile;
 
 var WOWExport;
+var FHDExport;
 var SVGExport;
 var PNGExport;
 
@@ -784,6 +809,15 @@ function endSlicing() {
 
         zipFile.file("print.wow", wowFile, {binary: true});
 
+        // hotfix for mirror bug
+        flipGeometry();
+    } else if (FHDExport) {
+        // add gcode footer from settings
+        var gcode = settings.get('gcode'); // I believe same end gcode is valid for FHD as for standard sparkmaker - Adam
+        wowFile += gcode.end;
+
+        zipFolder.file("print.wow", wowFile, {binary: true}); // probably don't need binary, but doesn't seem to hurt
+
         // hotfix for mirror bug
         flipGeometry();
     }
@@ -814,6 +848,7 @@ function startSlicing() {
     zipFolder = null;
     wowFile   = null;
     WOWExport = null;
+    FHDExport = null;
     SVGExport = null;
     PNGExport = null;
 
@@ -840,9 +875,13 @@ function startSlicing() {
             declineSpeed  : parseInt(settings.get('slicer.lifting.decline')),  // mm/min
             liftingHeight : parseInt(settings.get('slicer.lifting.height'))  // mm
         }, null, 2));
-        WOWExport = settings.get('slicer.wow')
+        WOWExport = settings.get('slicer.wow');
+        FHDExport = settings.get('slicer.fhd');
         SVGExport = settings.get('slicer.svg');
         PNGExport = settings.get('slicer.png');
+        if (FHDExport) {
+            zipFolder = zipFile.folder('print-FHD');
+        }
     }
 
     if(WOWExport){// GCode logic
@@ -869,6 +908,18 @@ function startSlicing() {
         // use gcode header from settings
         var gcode = settings.get('gcode');
         wowFile += gcode.start;
+    } else if (FHDExport) {
+        // hotfix for first layer bug - before flip geometry!
+        $sliderInput.slider('setValue', currentSliceNumber);
+
+        // hotfix for mirror bug
+        flipGeometry();
+
+        wowFile = "";
+
+        // use gcode header from settings
+        var gcode = settings.get('gcode'); // I believe same start gcode is valid for FHD as for standard sparkmaker - Adam
+        wowFile += gcode.start;
     }
 
     slicesNumber && slice();

From 6dde259d440d820580a69e2859f446b7b196b187 Mon Sep 17 00:00:00 2001
From: Adukra <43076626+Adukra@users.noreply.github.com>
Date: Sat, 22 Sep 2018 21:20:23 -0400
Subject: [PATCH 6/8] update UI for slicer output type

use dropdown select control instead of radio buttons for slicer output type
---
 index.html | 12 +++++++-----
 js/main.js | 35 ++++++++++++++++++-----------------
 2 files changed, 25 insertions(+), 22 deletions(-)

diff --git a/index.html b/index.html
index 85cdbd4..27a39f8 100644
--- a/index.html
+++ b/index.html
@@ -208,11 +208,13 @@ <h3 class="panel-title">Slicer</h3>
                         <hr />
 
                         <div class="form-group">
-                            <label for="slicer-image-extension">Output type</label>
-                            <input type="radio" name="slicer-image-extension" id="slicer-image-extension-png" value="png" /> png
-                            <input type="radio" name="slicer-image-extension" id="slicer-image-extension-svg" value="svg" /> svg
-                            <input type="radio" name="slicer-image-extension" id="slicer-image-extension-wow" value="wow" checked="checked" /> wow
-                            <input type="radio" name="slicer-image-extension" id="slicer-image-extension-fhd" value="fhd" checked="checked" /> FHD
+                            <label for="output-type">Output type</label>
+                            <select id="output-type" class="form-control input-sm">
+                                <option>png</option>
+                                <option>svg</option>
+                                <option>wow</option>
+                                <option>fhd</option>
+                            </select>
                         </div>
 
                         <hr />
diff --git a/js/main.js b/js/main.js
index e06c57c..b346bac 100644
--- a/js/main.js
+++ b/js/main.js
@@ -22,9 +22,7 @@ var settings = new SLAcer.Settings({
         },
         zip: true,
         folder: false,
-        wow: true,
-        svg: false,
-        png: false,
+        output: 'wow',
         speed: true,
         speedDelay: 10, // ms
         panel: {
@@ -685,10 +683,7 @@ var $printTimeValue  = $slicerBody.find('#print-time');
 var $slicerLiftingSpeed  = $slicerBody.find('#slicer-lifting-speed');
 var $slicerLiftingHeight = $slicerBody.find('#slicer-lifting-height');
 
-var $slicerExportPNG = $slicerBody.find('#slicer-image-extension-png');
-var $slicerExportSVG = $slicerBody.find('#slicer-image-extension-svg');
-var $slicerExportWOW = $slicerBody.find('#slicer-image-extension-wow');
-var $slicerExportFHD = $slicerBody.find('#slicer-image-extension-fhd');
+var $outputType = $slicerBody.find('#output-type');
 
 var $slicerSpeedYes    = $slicerBody.find('#slicer-speed-yes');
 var $slicerSpeedNo     = $slicerBody.find('#slicer-speed-no');
@@ -735,10 +730,7 @@ function updateSlicerSettings() {
     settings.set('slicer.lifting.speed', $slicerLiftingSpeed.val());
     settings.set('slicer.lifting.height', $slicerLiftingHeight.val());
 
-    settings.set('slicer.png', $slicerExportPNG[0].checked);
-    settings.set('slicer.svg', $slicerExportSVG[0].checked);
-    settings.set('slicer.wow', $slicerExportWOW[0].checked);
-    settings.set('slicer.fhd', $slicerExportFHD[0].checked);
+    settings.set('slicer.output', $outputType.val());
 
     settings.set('slicer.zip', $slicerMakeZipYes[0].checked);
 
@@ -859,7 +851,7 @@ function startSlicing() {
         }
         zipFile.file("README.txt", 'Generated by SLAcer.js for SparkMaker\r\nhttps://n0sr3v.github.io/SLAcer.js/\r\n\r\nProject based on: \r\nhttps://github.com/lautr3k/SLAcer.js\r\nAppreciate this work!\r\n');
         zipFile.file("slacer.json", JSON.stringify({
-            imageExtension: settings.get('slicer.png') ? 'png' : settings.get('slicer.svg') ? 'svg' : 'wow',
+            imageExtension: settings.get('slicer.output'),
             imageDirectoryCreated: settings.get('slicer.folder') ? 'false' : 'true',
             imageDirectory: !settings.get('slicer.folder') ? '' : 'slices',
             screenWidth   : settings.get('screen.width'),
@@ -875,10 +867,18 @@ function startSlicing() {
             declineSpeed  : parseInt(settings.get('slicer.lifting.decline')),  // mm/min
             liftingHeight : parseInt(settings.get('slicer.lifting.height'))  // mm
         }, null, 2));
-        WOWExport = settings.get('slicer.wow');
-        FHDExport = settings.get('slicer.fhd');
-        SVGExport = settings.get('slicer.svg');
-        PNGExport = settings.get('slicer.png');
+        if ($outputType.val() == 'wow') {
+            WOWExport = true;
+        }
+        else if ($outputType.val() == 'fhd') {
+            FHDExport = true;
+        }
+        else if ($outputType.val() == 'svg') {
+            SVGExport = true;
+        }
+        else if ($outputType.val() == 'png') {
+            PNGExport = true;
+        }
         if (FHDExport) {
             zipFolder = zipFile.folder('print-FHD');
         }
@@ -960,7 +960,7 @@ $abortButton.on('click', function(e) {
     endSlicing();
 });
 
-$('#slicer-image-extension-' + (settings.get('slicer.png') ? 'png' : settings.get('slicer.svg') ? 'svg' : 'wow')).prop('checked', true);
+$outputType.val(settings.get('slicer.output'));
 $('#slicer-make-zip-' + (settings.get('slicer.zip') ? 'yes' : 'no')).prop('checked', true);
 
 //new
@@ -968,6 +968,7 @@ $('#slicer-make-folder-' + (settings.get('slicer.folder') ? 'yes' : 'no')).prop(
 
 $('#slicer-speed-' + (settings.get('slicer.speed') ? 'yes' : 'no')).prop('checked', true);
 $('#slicer input').on('input, change', updateSlicerSettings);
+$('#slicer select').on('change', updateSlicerSettings);
 updateSlicerUI();
 
 // Build volume panel

From 36c1ed877be87f105e89e7adb51214002996f5d6 Mon Sep 17 00:00:00 2001
From: Adukra <43076626+Adukra@users.noreply.github.com>
Date: Wed, 3 Oct 2018 21:46:37 -0400
Subject: [PATCH 7/8] presets for sparkmaker and FHD

Added presets to make it easier to switch between original sparkmaker and sparkmaker FHD settings. Custom settings are supported as well
---
 index.html |  10 +++++
 js/main.js | 113 ++++++++++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 122 insertions(+), 1 deletion(-)

diff --git a/index.html b/index.html
index 27a39f8..843dcb4 100644
--- a/index.html
+++ b/index.html
@@ -108,6 +108,14 @@ <h3 class="panel-title">File</h3>
                             </span>
                             <small>Or drop an STL file anywhere.<br>In case of error check your model <a href="https://service.netfabb.com/service.php">here</a>!</small>
                         </div>
+                        <div class="form-group">
+                            <label for="printer-type" style="width: 25%;">Printer</label>
+                            <select id="printer-type" class="form-control input-sm" style="width: 75%;">
+                                <option>Sparkmaker</option>
+                                <option>Sparkmaker FHD</option>
+                                <option>Custom</option>
+                            </select>
+                        </div>
                     </div>
                 </div><!-- #file -->
 
@@ -391,6 +399,8 @@ <h3 class="panel-title">GCode</h3>
             <p class="message">Alert message empty...</p>
         </div>
 
+        <div id="dialog-confirm"></div>
+
         <script src="vendor/jquery-2.1.4.min.js" type="text/javascript"></script>
         <script src="vendor/jquery-ui/jquery-ui.min.js" type="text/javascript"></script>
         <script src="vendor/bootstrap/js/bootstrap.min.js" type="text/javascript"></script>
diff --git a/js/main.js b/js/main.js
index b346bac..3fc1cc7 100644
--- a/js/main.js
+++ b/js/main.js
@@ -7,7 +7,8 @@ var settings = new SLAcer.Settings({
         panel: {
             collapsed: false,
             position : 0
-        }
+        },
+        printer: 'Custom'
     },
     slicer: {
         layers: {
@@ -615,6 +616,7 @@ function parseUnit(value, unit) {
 // File panel
 var $fileBody  = initPanel('file');
 var $fileInput = $fileBody.find('#file-input');
+var $printerType = $fileBody.find('#printer-type');
 var loadedFile = null;
 
 $fileInput.on('change', function(e) {
@@ -623,6 +625,115 @@ $fileInput.on('change', function(e) {
     loader.loadFile(loadedFile);
 });
 
+$printerType.on('change', function(e) {
+    newPrinterType = $printerType.val();
+
+    if (newPrinterType == 'Custom') {
+        // update printerType setting only
+        settings.set('file.printer', newPrinterType);
+    }
+    else {
+        // TODO: need to fix slider errors when using jquery-ui full (as opposed to .min). Then we can use this confirm dialog
+//        // make sure user is willing to update screen, build volume, and outputType settings
+//        $("#dialog-confirm").html("Are you sure you want to replace screen, build volume, gcode, and outputType settings with \"" + newPrinterType + "\" defaults?");
+//        $("#dialog-confirm").dialog({
+//            resizable: false,
+//            modal: true,
+//            title: "Update Settings?",
+//            height: 250,
+//            width: 400,
+//            buttons: {
+//                "Yes": function () {
+//                    $(this).dialog('close');
+                    // update settings
+                    settings.set('file.printer', newPrinterType);
+                    printerDefaults(newPrinterType);
+//                },
+//                "No": function () {
+//                    $(this).dialog('close');
+//                    // revert printerType input to the old printer-type value from settings
+//                    $printerType.val(settings.get('file.printer'));
+//                }
+//            }
+//        });
+    }
+});
+
+function printerDefaults(printerType) {
+    // update settings and UI
+    if (printerType == 'Sparkmaker') {
+        // screen
+        settings.set('screen', {
+            width   : 854,
+            height  : 480,
+            diagonal: {
+                size: 4.6,
+                unit: 'in'
+            }
+        });
+        $('#screen-diagonal-unit-' + settings.get('screen.diagonal.unit')).prop('checked', true);
+        updateScreenUI();
+
+        // build volume x,y,z,unit
+        settings.set('buildVolume', {
+            size: {
+                x: 102,
+                y: 56,
+                z: 125
+            },
+            unit: 'mm'
+        });
+        $('#build-volume-unit-' + settings.get('buildVolume.unit')).prop('checked', true);
+        updateBuildVolumeUI()
+
+        // outputType
+        settings.set('slicer.output', 'wow');
+        $outputType.val(settings.get('slicer.output'));
+
+        // gcode
+        resetGcodeStart(); // gcode prefix and suffix are the same for both Sparkmaker and Sparkmaker FHD for now
+        resetGcodeEnd();
+    }
+    else if (printerType == 'Sparkmaker FHD') {
+        // screen
+        settings.set('screen', {
+            width   : 1920,
+            height  : 1080,
+            diagonal: {
+                size: 4.9686,
+                unit: 'in'
+            }
+        });
+        $('#screen-diagonal-unit-' + settings.get('screen.diagonal.unit')).prop('checked', true);
+        updateScreenUI();
+
+        // build volume
+        settings.set('buildVolume', {
+            size: {
+                x: 110.016,
+                y: 61.8357,
+                z: 125
+            },
+            unit: 'mm'
+        });
+        $('#build-volume-unit-' + settings.get('buildVolume.unit')).prop('checked', true);
+        updateBuildVolumeUI()
+
+        // outputType
+        settings.set('slicer.output', 'fhd');
+        $outputType.val(settings.get('slicer.output'));
+
+        // gcode
+        resetGcodeStart(); // gcode prefix and suffix are the same for both Sparkmaker and Sparkmaker FHD for now
+        resetGcodeEnd();
+    }
+
+    // reload 3d view with new screen and build-volume settings
+    updateBuildVolumeSettings();
+    updateScreenSettings();
+}
+
+
 // Mesh panel
 var $meshBody     = initPanel('mesh');
 var $meshFaces    = $meshBody.find('#mesh-faces');

From f17923719bfa5dcbcd48c76a88905c3937475e33 Mon Sep 17 00:00:00 2001
From: Adukra <43076626+Adukra@users.noreply.github.com>
Date: Mon, 8 Oct 2018 21:36:49 -0400
Subject: [PATCH 8/8] init printer field to settings value

init printer field to settings value
---
 js/main.js | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/js/main.js b/js/main.js
index 3fc1cc7..76e356d 100644
--- a/js/main.js
+++ b/js/main.js
@@ -659,6 +659,8 @@ $printerType.on('change', function(e) {
     }
 });
 
+$printerType.val(settings.get('file.printer'));
+
 function printerDefaults(printerType) {
     // update settings and UI
     if (printerType == 'Sparkmaker') {
