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 1/4] 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 2/4] 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 3/4] 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 4/4] 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') {
