diff --git a/index.html b/index.html index 42f68a1..3165db3 100755 --- a/index.html +++ b/index.html @@ -84,7 +84,7 @@ - + diff --git a/js/Printer.js b/js/Printer.js index b54a162..d27ea8f 100644 --- a/js/Printer.js +++ b/js/Printer.js @@ -38,8 +38,10 @@ function Printer() { //this.wifiboxURL = "proxy5.php"; console.log(" wifiboxURL: ",this.wifiboxURL); - this.checkTemperature(); - this.checkProgress(); + if(autoUpdate) { + this.checkTemperature(); + this.checkProgress(); + } } this.preheat = function() { diff --git a/js/SettingsWindow.js b/js/SettingsWindow.js new file mode 100644 index 0000000..64644cf --- /dev/null +++ b/js/SettingsWindow.js @@ -0,0 +1,216 @@ +//these settings are defined in the firmware (conf_defaults.lua) and will be initialized in loadSettings() +var settings = { +"network.ap.ssid": "d3d-ap-%%MAC_ADDR_TAIL%%", +"network.ap.address": "192.168.10.1", +"network.ap.netmask": "255.255.255.0", +"printer.temperature": 220, +"printer.objectHeight": '???', +"printer.layerHeight": 0.2, +"printer.wallThickness": 0.7, +"printer.speed": 50, +"printer.travelSpeed": 200, +"printer.filamentThickness": 2.85, +"printer.useSubLayers": true, +"printer.firstLayerSlow": true, +"printer.autoWarmUp": true, +"printer.simplify.iterations": 10, +"printer.simplify.minNumPoints": 15, +"printer.simplify.minDistance": 3, +"printer.retraction.enabled": true, +"printer.retraction.speed": 250, +"printer.retraction.minDistance": 1, +"printer.retraction.amount": 2, +"printer.autoWarmUpCommand": "M104 S220 (hardcoded temperature)" +} + +function SettingsWindow() { + this.wifiboxURL; + this.window; + this.form; + this.timeoutTime = 3000; + this.retryDelay = 2000; // retry setTimout delay + this.retryLoadSettingsDelay; // retry setTimout instance + this.retrySaveSettingsDelay; // retry setTimout instance + + // Events + SettingsWindow.SETTINGS_LOADED = "settingsLoaded"; + + var self = this; + + this.init = function(wifiboxURL) { + this.wifiboxURL = wifiboxURL; + + this.window = $("#settings"); + this.window.find(".btnOK").click(this.submitwindow); + this.window.find(".settings").load("settings.html", function() { + console.log("Settings:finished loading settings.html, now loading settings..."); + + self.form = self.window.find("form"); + self.form.submit(function (e) { self.submitwindow(e) }); + + self.loadSettings(); + }); + } + this.submitwindow = function(e) { + e.preventDefault(); + e.stopPropagation(); + self.saveSettings(); + self.hideSettings(); + } + this.showSettings = function() { + console.log("f:showSettings()"); + + this.loadSettings(); // reload settings + + $("#contentOverlay").fadeIn(375, function() { + document.body.removeEventListener('touchmove',prevent,false); + }); + } + this.hideSettings = function() { + $("#contentOverlay").fadeOut(375, function() { + document.body.addEventListener('touchmove',prevent,false); + }); + } + this.loadSettings = function() { + if (!communicateWithWifibox) { + console.log(" communicateWithWifibox is false: settings aren't being loaded from wifibox...") + return; + } + console.log("Settings:loadSettings() >> getting new data..."); + + $.ajax({ + url: this.wifiboxURL + "/config/all", + dataType: 'json', + timeout: this.timeoutTime, + success: function(data){ + console.log("Settings:loadSettings response: ",data); + // TODO: no request status? + settings = data.data; + console.log(" settings: ",settings); + self.fillForm(); + $(document).trigger(SettingsWindow.SETTINGS_LOADED); + } + }).fail(function() { + console.log("Settings:loadSettings: failed"); + clearTimeout(self.retryLoadSettingsDelay); + self.retryLoadSettingsDelay = setTimeout(function() { self.loadSettings() },self.retryDelay); // retry after delay + }); + } + this.saveSettings = function(callback) { + console.log("Settings:saveSettings"); + + //var printerSettings = {}; + $("#printersettings input").each( function(index,element) { + var element = $(element); + //populate settings are with values from html + if(element.attr("type") == "text") { + settings[element.attr('name')] = element.val(); + } else if(element.attr("type") == "checkbox") { + settings[element.attr('name')] = element.prop('checked') + } + }); + + if (communicateWithWifibox) { + $.ajax({ + url: this.wifiboxURL + "/config", + type: "POST", + data: settings, + dataType: 'json', + timeout: this.timeoutTime, + success: function(data){ + console.log("Settings:saveSettings response: ",data); + if(data.status == "error") { + clearTimeout(self.retrySaveSettingsDelay); + self.retrySaveSettingsDelay = setTimeout(function() { self.saveSettings() },self.retryDelay); // retry after delay + } else { + var savedSettings = data.data; + $.each(savedSettings, function(index, val) { + if (val != "ok") { + console.log("ERROR: value '" + index + "' not successfully set. Message: " + val); + } + }); + // TODO something like a callback or feedback that saving went well / or failed + if (callback != undefined) { + callback(); + } + } + } + }).fail(function() { + console.log("Settings:saveSettings: failed"); + clearTimeout(self.retrySaveSettingsDelay); + self.retrySaveSettingsDelay = setTimeout(function() { self.saveSettings() },self.retryDelay); // retry after delay + }); + } + } + this.fillForm = function() { + //update html with loaded wifi settings + $("#ipaddress").attr('value', settings["network.ap.address"]); + $("#netmask").attr('value', settings["network.ap.netmask"]); + $("#ssid").attr('value', settings["network.ap.ssid"]); + + //update html with loaded printer settings + $("#printersettings input").each( function(index,element) { + var element = $(element); + //console.log("printer setting input: ",index,element.attr("type"),element.attr('name')); //,element); + if(element.attr("type") == "text") { + element.val(settings[element.attr('name')]); + } else if(element.attr("type") == "checkbox") { + element.prop('checked', settings[element.attr('name')]); + } + }); + } +} + +/************************* + * + * + * FROM DOODLE3D.INI + * + */ +//TODO: find all references to these variables, replace them and finally remove these. +var objectHeight = 20; +var layerHeight = .2; +//var wallThickness = .5; +var hop = 0; +//var speed = 70; +//var travelSpeed = 200; +var enableTraveling = true; +//var filamentThickness = 2.89; +var minScale = .3; +var maxScale = 1; +var shape = "%"; +var twists = 0; +var useSubLayers = true; +//var debug = false; // debug moved to main.js +var loglevel = 2; +var zOffset = 0; +var serverport = 8888; +var autoLoadImage = "hand.txt"; +var loadOffset = [0, 0]; // x en y ? +var showWarmUp = true; +var loopAlways = false; +var firstLayerSlow = true; +var useSubpathColors = false; +var autoWarmUp = true; +var maxObjectHeight = 150; +var maxScaleDifference = .1; +var frameRate = 60; +var quitOnEscape = true; +var screenToMillimeterScale = .3; // 0.3 +var targetTemperature = 230; +var simplifyiterations = 10; +var simplifyminNumPoints = 15; +var simplifyminDistance = 3; +var retractionspeed = 50; +var retractionminDistance = 5; +var retractionamount = 3; +var sideis3D = true; +var sidevisible = true; +var sidebounds = [900, 210, 131, 390]; +var sideborder = [880, 169, 2, 471]; +var windowbounds = [0, 0, 800, 500]; +var windowcenter = true; +var windowfullscreen = false; +var autoWarmUpCommand = "M104 S230"; +//var checkTemperatureInterval = 3; +var autoWarmUpDelay = 3; diff --git a/js/buttonbehaviors.js b/js/buttonbehaviors.js index ff71a3d..6737f7e 100644 --- a/js/buttonbehaviors.js +++ b/js/buttonbehaviors.js @@ -204,7 +204,7 @@ function initButtonBehavior() { btnSettings.bind('touchstart mousedown',function () { //e.preventDefault(); //console.log("btnSettings clicked"); - showSettings(); + settingsWindow.showSettings(); }); // btnSettings.on('touchend', function(e) { // e.preventDefault(); diff --git a/js/main.js b/js/main.js index 674926c..280e5eb 100644 --- a/js/main.js +++ b/js/main.js @@ -2,9 +2,10 @@ var debugMode = false; // debug mode var sendPrintCommands = true; // if Doodle3d should send print commands to the 3d printer var communicateWithWifibox = true; // if Doodle3d should try interfacing with the wifibox (in case one is not connected) var wifiboxIsRemote = false; // when you want to run the client on a computer and have it remotely connect to the wifibox +var autoUpdate = true; // auto retrieve updates about temperature and progress from printer var printer = new Printer(); - +var settingsWindow = new SettingsWindow(); $(function() { console.log("ready"); @@ -12,7 +13,7 @@ $(function() { if (getURLParameter("p") != "null") sendPrintCommands = (getURLParameter("p") == "1"); if (getURLParameter("c") != "null") communicateWithWifibox = (getURLParameter("c") == "1"); if (getURLParameter("r") != "null") wifiboxIsRemote = (getURLParameter("r") == "1"); - + if (getURLParameter("u") != "null") autoUpdate = (getURLParameter("u") == "1"); if (wifiboxIsRemote) { wifiboxURL = "http://192.168.5.1/cgi-bin/d3dapi"; @@ -30,34 +31,27 @@ $(function() { console.log("wifibox URL: " + wifiboxURL); initLayouting(); - initDoodleDrawing(); initPreviewRendering(); - - initButtonBehavior(); - initSettingsPopup(wifiboxURL); - - $("#settings .settings").load("settings.html", function() { - if (communicateWithWifibox) { - console.log("finished loading settings.html, now loading settings..."); - loadSettings(); - } else { - console.log("finished loading settings.html >> communicateWithWifibox is false: not loading settings"); - } - }); - - if(debugMode) { + printer.init(); + $(document).on(Printer.UPDATE,update); + + settingsWindow.init(wifiboxURL); + $(document).on(SettingsWindow.SETTINGS_LOADED,settingsLoaded); + + if(debugMode) { console.log("debug mode is true"); $("body").css("overflow", "auto"); $("#debug_textArea").css("display", "block"); $("#preview_tmp").css("display", "block"); } - - printer.init(); - if (communicateWithWifibox) printer.preheat(); - - $(document).on(Printer.UPDATE,update); - -}) \ No newline at end of file +}) +function settingsLoaded() { + console.log("settingsLoaded"); + console.log("autoWarmUp: ",settings["printer.autoWarmUp"]); + if(settings["printer.autoWarmUp"]) { + printer.preheat(); + } +} \ No newline at end of file diff --git a/js/settings.js b/js/settings.js deleted file mode 100644 index 948f835..0000000 --- a/js/settings.js +++ /dev/null @@ -1,192 +0,0 @@ -var wifiboxURL;//"http://192.168.5.1/cgi-bin/d3dapi"; - -//these settings are defined in the firmware (conf_defaults.lua) and will be initialized in loadSettings() -var settings = { -"network.ap.ssid": "d3d-ap-%%MAC_ADDR_TAIL%%", -"network.ap.address": "192.168.10.1", -"network.ap.netmask": "255.255.255.0", -"printer.temperature": 220, -"printer.objectHeight": '???', -"printer.layerHeight": 0.2, -"printer.wallThickness": 0.7, -"printer.speed": 50, -"printer.travelSpeed": 200, -"printer.filamentThickness": 2.85, -"printer.useSubLayers": true, -"printer.firstLayerSlow": true, -"printer.autoWarmUp": true, -"printer.simplify.iterations": 10, -"printer.simplify.minNumPoints": 15, -"printer.simplify.minDistance": 3, -"printer.retraction.enabled": true, -"printer.retraction.speed": 250, -"printer.retraction.minDistance": 1, -"printer.retraction.amount": 2, -"printer.autoWarmUpCommand": "M104 S220 (hardcoded temperature)" -} - -var settingsForm = $("#settingsForm"); -settingsForm.submit(function(e) { - e.preventDefault(); - saveSettings(); - return false; -}) - -function initSettingsPopup(apiURL) { - console.log("f:initSettingsPopup()"); - wifiboxURL = apiURL; - - if (communicateWithWifibox) loadSettings(); - - $("#contentOverlay").hide(); - - $("div.content .btnOK").click(function(e) { - e.preventDefault(); - e.stopPropagation(); - - // TODO something like a callback or feedback that saving went well / or failed - - if (communicateWithWifibox) saveSettings(); - - $("#contentOverlay").fadeOut(375, function() { - document.body.addEventListener('touchmove',prevent,false); - }); - - console.log("button OK in settings popup pressed"); - }); -} - -function showSettings() { - console.log("f:showSettings()"); - if (!communicateWithWifibox) console.log(" communicateWithWifibox is false: settings aren't being loaded from wifibox...") - $("#contentOverlay").fadeIn(375, function() { - console.log("#contentOverlay faded in..."); - if (communicateWithWifibox) loadSettings(); - document.body.removeEventListener('touchmove',prevent,false); - }); -} - -function loadSettings() { - console.log("f:loadSettings() >> getting new data..."); - $.get(wifiboxURL + "/config/all", {}, function(data) { - settings = JSON.parse(data).data; - -// // var printer_layerHeight = settings["printer.layerHeight"]; -// // var printer_autoWarmup = settings["printer.autoWarmUp"]; -// console.log("print_layerHeight = " + settings["printer.layerHeight"]); -// console.log("printer_autoWarmup = " + settings["printer.autoWarmUp"] + ", type: " + (typeof settings["printer.autoWarmUp"])); -// console.log("printer_useSubLayers = " + settings["printer.useSubLayers"] + " type: " + (typeof settings["printer.useSubLayers"])); -// $("#formpje input[name='printer.layerHeight']").attr('value', settings["printer.layerHeight"]); - - - //update html with loaded wifi settings - $("#ipaddress").attr('value', settings["network.ap.address"]); - $("#netmask").attr('value', settings["network.ap.netmask"]); - $("#ssid").attr('value', settings["network.ap.ssid"]); - - //update html with loaded printer settings - - $("#printersettings input").each( function(index,element) { - var element = $(element); - //console.log("printer setting input: ",index,element.attr("type"),element.attr('name')); //,element); - if(element.attr("type") == "text") { - element.val(settings[element.attr('name')]); - } else if(element.attr("type") == "checkbox") { - element.prop('checked', settings[element.attr('name')]); - } - - //console.log(" val: ",$(element).val(),element); - - }); - }); -} - -function saveSettings(callback) { - console.log("settings form submitted"); -// console.log(" printer.layerHeight:" + $("#formpje input[name='printer.layerHeight']").attr('value')); -// console.log(" first layer slow (checkbox):" + $('#firstLayerSlow').prop('checked')); -// console.log(" use sublayers (checkbox):" + $('#useSubLayers').prop('checked')); - - //var printerSettings = {}; - $("#printersettings input").each( function(index,element) { - var element = $(element); - //populate settings are with values from html - if(element.attr("type") == "text") { - settings[element.attr('name')] = element.val(); - } else if(element.attr("type") == "checkbox") { - settings[element.attr('name')] = element.prop('checked') - } - }); - - $.post( - wifiboxURL + "/config", - settings, - function(data) { - var res = JSON.parse(data).data; - $.each(res, function(index, val) { - if (val != "ok") { - console.log("ERROR: value '" + index + "' not successfully set. Message: " + val); - } - }); - if (callback != undefined) { - callback(); - } - } - ); -} - - - -/************************* - * - * - * FROM DOODLE3D.INI - * - */ -//TODO: find all references to these variables, replace them and finally remove these. -var objectHeight = 20; -var layerHeight = .2; -//var wallThickness = .5; -var hop = 0; -//var speed = 70; -//var travelSpeed = 200; -var enableTraveling = true; -//var filamentThickness = 2.89; -var minScale = .3; -var maxScale = 1; -var shape = "%"; -var twists = 0; -var useSubLayers = true; -//var debug = false; // debug moved to main.js -var loglevel = 2; -var zOffset = 0; -var serverport = 8888; -var autoLoadImage = "hand.txt"; -var loadOffset = [0, 0]; // x en y ? -var showWarmUp = true; -var loopAlways = false; -var firstLayerSlow = true; -var useSubpathColors = false; -var autoWarmUp = true; -var maxObjectHeight = 150; -var maxScaleDifference = .1; -var frameRate = 60; -var quitOnEscape = true; -var screenToMillimeterScale = .3; // 0.3 -var targetTemperature = 230; -var simplifyiterations = 10; -var simplifyminNumPoints = 15; -var simplifyminDistance = 3; -var retractionspeed = 50; -var retractionminDistance = 5; -var retractionamount = 3; -var sideis3D = true; -var sidevisible = true; -var sidebounds = [900, 210, 131, 390]; -var sideborder = [880, 169, 2, 471]; -var windowbounds = [0, 0, 800, 500]; -var windowcenter = true; -var windowfullscreen = false; -var autoWarmUpCommand = "M104 S230"; -//var checkTemperatureInterval = 3; -var autoWarmUpDelay = 3; diff --git a/settings.html b/settings.html index addea62..249199a 100755 --- a/settings.html +++ b/settings.html @@ -9,15 +9,6 @@ - - - - - - - - -

Not all fields are saveable at the moment @@ -171,54 +162,6 @@ targetTemperature=230

- - - -