From 96e14615c86e9cb6d9392983242360f998a94a0f Mon Sep 17 00:00:00 2001 From: peteruithoven Date: Mon, 19 Aug 2013 17:55:01 +0200 Subject: [PATCH] fixed isRemote mode. Pressing stop button brings interface directly in IDLE mode. --- js/Printer.js | 128 +++++++++++++++++++++++------------------- js/buttonbehaviors.js | 1 + js/main.js | 12 ++-- 3 files changed, 79 insertions(+), 62 deletions(-) diff --git a/js/Printer.js b/js/Printer.js index 2393a33..b54a162 100644 --- a/js/Printer.js +++ b/js/Printer.js @@ -1,6 +1,7 @@ function Printer() { this.temperature = 0; this.targetTemperature = 0; + this.printing; this.wifiboxURL; @@ -45,24 +46,28 @@ function Printer() { console.log("Printer:preheat"); var postData = { id: 0 }; var self = this; - $.ajax({ - url: this.wifiboxURL + "/printer/heatup", - type: "POST", - data: postData, - dataType: 'json', - timeout: this.timeoutTime, - success: function(data){ - console.log("Printer:preheat response: ",data); - if(data.status == "error") { - clearTimeout(self.retryPreheatDelay); - self.retryPreheatDelay = setTimeout(function() { self.preheat() },self.retryDelay); // retry after delay - } - } - }).fail(function() { - console.log("Printer:preheat: failed"); - clearTimeout(self.retryPreheatDelay); - self.retryPreheatDelay = setTimeout(function() { self.preheat() },self.retryDelay); // retry after delay - }); + if (communicateWithWifibox) { + $.ajax({ + url: this.wifiboxURL + "/printer/heatup", + type: "POST", + data: postData, + dataType: 'json', + timeout: this.timeoutTime, + success: function(data){ + console.log("Printer:preheat response: ",data); + if(data.status == "error") { + clearTimeout(self.retryPreheatDelay); + self.retryPreheatDelay = setTimeout(function() { self.preheat() },self.retryDelay); // retry after delay + } + } + }).fail(function() { + console.log("Printer:preheat: failed"); + clearTimeout(self.retryPreheatDelay); + self.retryPreheatDelay = setTimeout(function() { self.preheat() },self.retryDelay); // retry after delay + }); + } else { + console.log ("Printer >> f:preheat() >> communicateWithWifibox is false, so not executing this function"); + } } this.print = function(gcode) { @@ -106,29 +111,33 @@ function Printer() { var postData = { id: 0, gcode: gcodePart.join("\n"), first: firstOne, last: lastOne}; var self = this; - $.ajax({ - url: this.wifiboxURL + "/printer/print", - type: "POST", - data: postData, - dataType: 'json', - timeout: this.timeoutTime, - success: function(data){ - console.log("Printer:sendPrintPart response: ",data); - - if(data.status == "success") { - if (lastOne) { - console.log("Printer:sendPrintPart:gcode sending completed"); - this.gcode = []; - } else { - self.sendPrintPart(sendIndex + sendLength, sendLength); - } - } - } - }).fail(function() { - console.log("Printer:sendPrintPart: failed"); - clearTimeout(self.retrySendPrintPartDelay); - self.retrySendPrintPartDelay = setTimeout(function() { self.sendPrintPart(sendIndex, sendLength) },self.retryDelay); // retry after delay - }); + if (communicateWithWifibox) { + $.ajax({ + url: this.wifiboxURL + "/printer/print", + type: "POST", + data: postData, + dataType: 'json', + timeout: this.timeoutTime, + success: function(data){ + console.log("Printer:sendPrintPart response: ",data); + + if(data.status == "success") { + if (lastOne) { + console.log("Printer:sendPrintPart:gcode sending completed"); + this.gcode = []; + } else { + self.sendPrintPart(sendIndex + sendLength, sendLength); + } + } + } + }).fail(function() { + console.log("Printer:sendPrintPart: failed"); + clearTimeout(self.retrySendPrintPartDelay); + self.retrySendPrintPartDelay = setTimeout(function() { self.sendPrintPart(sendIndex, sendLength) },self.retryDelay); // retry after delay + }); + } else { + console.log ("Printer >> f:sendPrintPart() >> communicateWithWifibox is false, so not executing this function"); + } } @@ -136,23 +145,26 @@ function Printer() { console.log("Printer:stop"); var postData = { id: 0 }; var self = this; - $.ajax({ - url: this.wifiboxURL + "/printer/stop", - type: "POST", - data: postData, - dataType: 'json', - timeout: this.timeoutTime, - success: function(data){ - console.log("Printer:stop response: ", data); - - setTimeout(function() { console.log("send: ",gcodeEnd); self.print(gcodeEnd) },self.sendStopGCodeDelay); - } - }).fail(function() { - console.log("Printer:stop: failed"); - clearTimeout(self.retryStopDelay); - self.retryStopDelay = setTimeout(function() { self.stop() },self.retryDelay); // retry after delay - }); - + if (communicateWithWifibox) { + $.ajax({ + url: this.wifiboxURL + "/printer/stop", + type: "POST", + data: postData, + dataType: 'json', + timeout: this.timeoutTime, + success: function(data){ + console.log("Printer:stop response: ", data); + + setTimeout(function() { console.log("send: ",gcodeEnd); self.print(gcodeEnd) },self.sendStopGCodeDelay); + } + }).fail(function() { + console.log("Printer:stop: failed"); + clearTimeout(self.retryStopDelay); + self.retryStopDelay = setTimeout(function() { self.stop() },self.retryDelay); // retry after delay + }); + } else { + console.log ("Printer >> f:communicateWithWifibox() >> communicateWithWifibox is false, so not executing this function"); + } } this.checkTemperature = function() { diff --git a/js/buttonbehaviors.js b/js/buttonbehaviors.js index 57ef2d2..5639ade 100644 --- a/js/buttonbehaviors.js +++ b/js/buttonbehaviors.js @@ -229,6 +229,7 @@ function initButtonBehavior() { function stopPrint() { console.log("f:stopPrint() >> sendPrintCommands = " + sendPrintCommands); if (sendPrintCommands) printer.stop(); + setState(IDLE_STATE); } diff --git a/js/main.js b/js/main.js index 06e515b..d518481 100644 --- a/js/main.js +++ b/js/main.js @@ -13,10 +13,14 @@ $(function() { if (getURLParameter("c") != "null") communicateWithWifibox = (getURLParameter("c") == "1"); if (getURLParameter("r") != "null") wifiboxIsRemote = (getURLParameter("r") == "1"); - if (communicateWithWifibox) { - wifiboxURL = "http://" + window.location.host + "/cgi-bin/d3dapi"; - } else { - wifiboxURL = "http://192.168.5.1/cgi-bin/d3dapi"; + + if (wifiboxIsRemote) { + wifiboxURL = "http://192.168.5.1/cgi-bin/d3dapi"; + } else { + wifiboxURL = "http://" + window.location.host + "/cgi-bin/d3dapi"; + } + + if (!communicateWithWifibox) { sendPrintCommands = false; // 'communicateWithWifibox = false' implies this } console.log("debugMode: " + debugMode);