diff --git a/js_src/Printer.js b/js_src/Printer.js index fdad949..bdbd89f 100644 --- a/js_src/Printer.js +++ b/js_src/Printer.js @@ -173,7 +173,7 @@ function Printer() { this.gcode = []; btnStop.css("display","block"); // hack self.removeLeaveWarning(); - message.set("Doodle is sent to printer...",Message.INFO,true); + message.set("Doodle has been sent to printer...",Message.INFO,true); //self.targetTemperature = settings["printer.temperature"]; // slight hack } else { // only if the state hasn't bin changed (by for example pressing stop) we send more gcode diff --git a/js_src/SettingsWindow.js b/js_src/SettingsWindow.js index c345fcf..9170b8a 100644 --- a/js_src/SettingsWindow.js +++ b/js_src/SettingsWindow.js @@ -26,6 +26,11 @@ var settings = { } +//wrapper to prevent scoping issues in showSettings() +function openSettingsWindow() { + settingsWindow.showSettings(); +} + function SettingsWindow() { this.wifiboxURL; this.wifiboxCGIBinURL @@ -34,7 +39,7 @@ function SettingsWindow() { this.timeoutTime = 3000; this.retryDelay = 2000; // retry setTimout delay this.retryRetrieveNetworkStatusDelayTime = 1000;// retry setTimout delay - + this.retryLoadSettingsDelay; // retry setTimout instance this.retrySaveSettingsDelay; // retry setTimout instance this.retryRetrieveNetworkStatusDelay;// retry setTimout instance @@ -45,11 +50,11 @@ function SettingsWindow() { this.networks; this.currentNetwork; // the ssid of the network the box is on this.selectedNetwork; // the ssid of the selected network in the client mode settings - this.currentLocalIP = ""; + this.currentLocalIP = ""; this.clientModeState = SettingsWindow.NOT_CONNECTED; this.currentAP; this.apModeState = SettingsWindow.NO_AP; - + // after switching wifi network or creating a access point we delay the status retrieval // because the webserver needs time to switch this.retrieveNetworkStatusDelay; // setTimout delay @@ -63,28 +68,28 @@ function SettingsWindow() { SettingsWindow.CONNECTED = "connected"; SettingsWindow.CONNECTING = "connecting"; SettingsWindow.CONNECTING_FAILED = "connecting failed" - + // network access point mode states SettingsWindow.NO_AP = "no ap"; SettingsWindow.AP = "ap"; SettingsWindow.CREATING_AP = "creating ap"; - + SettingsWindow.API_CONNECTING_FAILED = -1 SettingsWindow.API_NOT_CONNECTED = 0 SettingsWindow.API_CONNECTING = 1 SettingsWindow.API_CONNECTED = 2 - SettingsWindow.API_CREATING = 3 - SettingsWindow.API_CREATED = 4 - + SettingsWindow.API_CREATING = 3 + SettingsWindow.API_CREATED = 4 + // network mode SettingsWindow.NETWORK_MODE_NEITHER = "neither"; SettingsWindow.NETWORK_MODE_CLIENT = "clientMode"; SettingsWindow.NETWORK_MODE_ACCESS_POINT = "accessPointMode"; - + this.networkMode = SettingsWindow.NETWORK_MODE_NEITHER; - + this.updatePanel = new UpdatePanel(); - + var self = this; this.init = function(wifiboxURL,wifiboxCGIBinURL) { @@ -100,7 +105,7 @@ function SettingsWindow() { self.form.submit(function (e) { self.submitwindow(e) }); self.loadSettings(); - + var btnAP = self.form.find("label[for='ap']"); var btnClient = self.form.find("label[for='client']"); var btnRefresh = self.form.find("#refreshNetworks"); @@ -116,7 +121,7 @@ function SettingsWindow() { btnConnect.on('touchstart mousedown',self.connectToNetwork); btnCreate.on('touchstart mousedown',self.createAP); networkSelector.change(self.networkSelectorChanged); - + // update panel var $updatePanelElement = self.form.find("#updatePanel"); self.updatePanel.init(wifiboxURL,$updatePanelElement); @@ -128,7 +133,7 @@ function SettingsWindow() { self.saveSettings(self.readForm(),function(){ self.hideSettings(); }); - + clearTimeout(self.retryRetrieveNetworkStatusDelay); } @@ -253,7 +258,7 @@ function SettingsWindow() { self.form.find(".errorMsg").remove(); self.form.find(".error").removeClass("error"); } - + this.readForm = function() { //console.log("SettingsWindow:readForm"); var settings = {}; @@ -338,7 +343,7 @@ function SettingsWindow() { } } }).fail(function() { - + }); } } @@ -354,22 +359,22 @@ function SettingsWindow() { success: function(response){ console.log("Settings:retrieveNetworkStatus response: ",response); if(response.status == "error") { - + } else { var data = response.data; - + if(typeof data.status === 'string') { data.status = parseInt(data.status); } //console.log(" data.status: ",data.status,data.statusMessage); - + // Determine which network settings to show switch(data.status) { case SettingsWindow.API_NOT_CONNECTED: //console.log(" not connected & not a access point"); self.apFieldSet.show(); self.clientFieldSet.show(); - + self.networkMode = SettingsWindow.NETWORK_MODE_NEITHER; break; case SettingsWindow.API_CONNECTING_FAILED: @@ -377,14 +382,14 @@ function SettingsWindow() { case SettingsWindow.API_CONNECTED: //console.log(" client mode"); self.form.find("#client").prop('checked',true); - + self.apFieldSet.hide(); self.clientFieldSet.show(); - + if(data.status == SettingsWindow.API_CONNECTED) { var networkSelector = self.form.find("#network"); networkSelector.val(data.ssid); - + self.currentNetwork = data.ssid; self.currentLocalIP = data.localip; self.selectNetwork(data.ssid); @@ -397,31 +402,31 @@ function SettingsWindow() { case SettingsWindow.API_CREATED: //console.log(" access point mode"); self.form.find("#ap").prop('checked',true); - + self.apFieldSet.show(); self.clientFieldSet.hide(); - + self.currentNetwork = undefined; self.selectNetwork(SettingsWindow.NOT_CONNECTED); var networkSelector = self.form.find("#network"); networkSelector.val(SettingsWindow.NOT_CONNECTED); - - if(data.ssid && data.status == SettingsWindow.API_CREATED) { + + if(data.ssid && data.status == SettingsWindow.API_CREATED) { self.currentAP = data.ssid; } self.networkMode = SettingsWindow.NETWORK_MODE_ACCESS_POINT; break; } self.updatePanel.setNetworkMode(self.networkMode); - + // update status message switch(data.status) { case SettingsWindow.API_CONNECTING_FAILED: - self.setClientModeState(SettingsWindow.CONNECTING_FAILED,data.statusMessage); + self.setClientModeState(SettingsWindow.CONNECTING_FAILED,data.statusMessage); self.setAPModeState(SettingsWindow.NO_AP,""); break; - case SettingsWindow.API_NOT_CONNECTED: - self.setClientModeState(SettingsWindow.NOT_CONNECTED,""); + case SettingsWindow.API_NOT_CONNECTED: + self.setClientModeState(SettingsWindow.NOT_CONNECTED,""); self.setAPModeState(SettingsWindow.NO_AP,""); break; case SettingsWindow.API_CONNECTING: @@ -433,15 +438,15 @@ function SettingsWindow() { self.setAPModeState(SettingsWindow.NO_AP,""); break; case SettingsWindow.API_CREATING: - self.setClientModeState(SettingsWindow.NOT_CONNECTED,""); + self.setClientModeState(SettingsWindow.NOT_CONNECTED,""); self.setAPModeState(SettingsWindow.CREATING_AP,""); break; case SettingsWindow.API_CREATED: - self.setClientModeState(SettingsWindow.NOT_CONNECTED,""); + self.setClientModeState(SettingsWindow.NOT_CONNECTED,""); self.setAPModeState(SettingsWindow.AP,""); break; } - + // Keep checking for updates? if(connecting) { switch(data.status) { @@ -492,7 +497,7 @@ function SettingsWindow() { this.form.find("#passwordLabel").hide(); this.form.find("#password").hide(); } - + this.setClientModeState = function(state,msg) { var field = this.form.find("#clientModeState"); var btnConnect = self.form.find("#connectToNetwork"); @@ -503,7 +508,7 @@ function SettingsWindow() { break; case SettingsWindow.CONNECTED: btnConnect.removeAttr("disabled"); - + var fieldText = "Connected to: "+this.currentNetwork+"."; if(this.currentLocalIP != undefined && this.currentLocalIP != "") { var a = ""+this.currentLocalIP+""; @@ -517,7 +522,7 @@ function SettingsWindow() { break; case SettingsWindow.CONNECTING_FAILED: btnConnect.removeAttr("disabled"); - field.html(msg); + field.html(msg); break; } this.clientModeState = state; @@ -552,10 +557,10 @@ function SettingsWindow() { } console.log(" postData: ",postData); if (communicateWithWifibox) { - + // save network related settings and on complete, connect to network self.saveSettings(self.readForm(),function() { - + $.ajax({ url: self.wifiboxCGIBinURL + "/network/associate", type: "POST", @@ -573,7 +578,7 @@ function SettingsWindow() { }); } self.setClientModeState(SettingsWindow.CONNECTING,""); - + // after switching wifi network or creating a access point we delay the status retrieval // because the webserver needs time to switch clearTimeout(self.retrieveNetworkStatusDelay); @@ -583,7 +588,7 @@ function SettingsWindow() { this.createAP = function() { console.log("createAP"); if (communicateWithWifibox) { - + // save network related settings and on complete, create access point self.saveSettings(self.readForm(),function() { self.setAPModeState(SettingsWindow.CREATING_AP); // get latest substituted ssid @@ -600,7 +605,7 @@ function SettingsWindow() { //clearTimeout(self.retrySaveSettingsDelay); //self.retrySaveSettingsDelay = setTimeout(function() { self.saveSettings() },self.retryDelay); // retry after delay }); - + self.setAPModeState(SettingsWindow.CREATING_AP,""); // after switching wifi network or creating a access point we delay the status retrieval diff --git a/js_src/buttonbehaviors.js b/js_src/buttonbehaviors.js index dfbb806..25cd55e 100644 --- a/js_src/buttonbehaviors.js +++ b/js_src/buttonbehaviors.js @@ -160,11 +160,8 @@ function initButtonBehavior() { loadSettings(); }); }*/ - btnSettings.bind('touchstart mousedown',function () { - //e.preventDefault(); - //console.log("btnSettings clicked"); - settingsWindow.showSettings(); - }); + enableButton(btnSettings, openSettingsWindow); + // btnSettings.on('touchend', function(e) { // e.preventDefault(); // console.log("btnSettings touchend"); @@ -214,14 +211,14 @@ function print(e) { //setState(Printer.BUFFERING_STATE,printer.hasControl); printer.overruleState(Printer.BUFFERING_STATE); - + btnStop.css("display","none"); // hack - - // we put the gcode generation in a little delay + + // we put the gcode generation in a little delay // so that for example the print button is disabled right away clearTimeout(gcodeGenerateDelayer); - gcodeGenerateDelayer = setTimeout(function() { - + gcodeGenerateDelayer = setTimeout(function() { + var gcode = generate_gcode(); if (sendPrintCommands) { if(gcode.length > 0) { @@ -238,7 +235,7 @@ function print(e) { $("#textdump").text(""); $("#textdump").text(gcode.join("\n")); } - + }, gcodeGenerateDelay); } else { console.log("f:print >> not enough points!"); @@ -318,11 +315,11 @@ function update() { progressbar.update(printer.currentLine, printer.totalLines); } -function setState(newState,newHasControl) { +function setState(newState,newHasControl) { if(newState == state && newHasControl == hasControl) return; prevState = state; - + console.log("setState: ",prevState," > ",newState," ( ",newHasControl,")"); setDebugText("State: "+newState); @@ -350,38 +347,60 @@ function setState(newState,newHasControl) { // thermometer switch(newState) { - case Printer.IDLE_STATE: - case Printer.BUFFERING_STATE: - case Printer.PRINTING_STATE: + case Printer.IDLE_STATE: /* fall-through */ + case Printer.BUFFERING_STATE: /* fall-through */ + case Printer.PRINTING_STATE: /* fall-through */ case Printer.STOPPING_STATE: - thermometer.show(); + thermometer.show(); break; default: - thermometer.hide(); + thermometer.hide(); break; } // progress indicator switch(newState) { case Printer.PRINTING_STATE: - progressbar.show(); + progressbar.show(); break; default: progressbar.hide(); break; } - + + /* settings button */ + switch(newState) { + case Printer.IDLE_STATE: + enableButton(btnSettings, openSettingsWindow); + break; + case Printer.WIFIBOX_DISCONNECTED_STATE: /* fall-through */ + case Printer.BUFFERING_STATE: /* fall-through */ + case Printer.PRINTING_STATE: /* fall-through */ + case Printer.STOPPING_STATE: + disableButton(btnSettings); + break; + default: + enableButton(btnSettings, openSettingsWindow); + break; +} + if(newState == Printer.WIFIBOX_DISCONNECTED_STATE) { message.set("Lost connection to WiFi box",Message.ERROR); } else if(prevState == Printer.WIFIBOX_DISCONNECTED_STATE) { message.set("Connected to WiFi box",Message.INFO,true); } else if(newState == Printer.DISCONNECTED_STATE) { message.set("Printer disconnected",Message.WARNING,true); - } else if(prevState == Printer.DISCONNECTED_STATE && newState == Printer.IDLE_STATE || + } else if(prevState == Printer.DISCONNECTED_STATE && newState == Printer.IDLE_STATE || prevState == Printer.UNKNOWN_STATE && newState == Printer.IDLE_STATE) { message.set("Printer connected",Message.INFO,true); + } else if(prevState == Printer.PRINTING_STATE && newState == Printer.STOPPING_STATE) { + console.log("stopmsg show"); + message.set("Printer stopping",Message.INFO,false); + } else if(prevState == Printer.STOPPING_STATE && newState == Printer.IDLE_STATE) { + console.log("stopmsg hide"); + message.hide(); } - + state = newState; hasControl = newHasControl; } diff --git a/js_src/gcodeGenerating.js b/js_src/gcodeGenerating.js index d75bc23..0ca084a 100644 --- a/js_src/gcodeGenerating.js +++ b/js_src/gcodeGenerating.js @@ -142,7 +142,7 @@ function generate_gcode() { console.log("pointsToPrint: ",pointsToPrint); if(pointsToPrint > MAX_POINTS_TO_PRINT) { - alert("Sorry, your doodle too complex and / or to high"); + alert("Sorry, your doodle is too complex or too high. Please try to simplify it."); console.log("ERROR: to many points too convert to gcode"); return []; } diff --git a/js_src/main.js b/js_src/main.js index d4981c9..0eb87d4 100644 --- a/js_src/main.js +++ b/js_src/main.js @@ -112,6 +112,19 @@ $(function() { } }); +function enableButton(elem, handler) { + //var elem = $('#'+domId); + elem.removeClass("disabled"); + elem.unbind('touchstart mousedown'); + elem.bind('touchstart mousedown', handler); +} + +function disableButton(elem) { + //var elem = $('#'+domId); + elem.addClass("disabled"); + elem.unbind('touchstart mousedown'); +} + function showOrHideThermo() { console.log("f:showOrHideThermo()"); if (showOrHide) {