From d5aef3bf951fe5353e6a88426fb454ffbbeac7e1 Mon Sep 17 00:00:00 2001 From: peteruithoven Date: Wed, 16 Oct 2013 18:27:10 +0200 Subject: [PATCH] stop status checks on override and start them again when there is a first response --- js/Printer.js | 44 +++++++++++++++++++++++++++++++++++--------- 1 file changed, 35 insertions(+), 9 deletions(-) diff --git a/js/Printer.js b/js/Printer.js index dbbfa87..7d38027 100644 --- a/js/Printer.js +++ b/js/Printer.js @@ -61,7 +61,7 @@ function Printer() { console.log(" wifiboxURL: ",this.wifiboxURL); if(autoUpdate) { - this.checkStatus(); + this.startStatusCheckInterval(); } } @@ -163,6 +163,12 @@ function Printer() { } } } + // after we know the first gcode packed has bin received or failed + // (and the driver had time to update the printer.state) + // we start checking the status again + if(sendIndex == 0) { + self.startStatusCheckInterval(); + } } }).fail(function() { console.log("Printer:sendPrintPart: failed"); @@ -171,6 +177,11 @@ function Printer() { console.log("request printer:sendPrintPart failed retry"); self.sendPrintPart(sendIndex, sendLength) },self.retryDelay); // retry after delay + + // after we know the gcode packed has bin received or failed + // (and the driver had time to update the printer.state) + // we start checking the status again + self.startStatusCheckInterval(); }); } else { console.log ("Printer >> f:sendPrintPart() >> communicateWithWifibox is false, so not executing this function"); @@ -188,17 +199,38 @@ function Printer() { timeout: this.timeoutTime, success: function(data){ console.log("Printer:stop response: ", data); + + // after we know the stop has bin received or failed + // (and the driver had time to update the printer.state) + // we start checking the status again + self.startStatusCheckInterval(); } }).fail(function() { console.log("Printer:stop: failed"); clearTimeout(self.retryStopDelay); self.retryStopDelay = setTimeout(function() { self.stop() },self.retryDelay); // retry after delay + + // after we know the stop has bin received or failed + // (and the driver had time to update the printer.state) + // we start checking the status again + self.startStatusCheckInterval(); }); } else { console.log ("Printer >> f:communicateWithWifibox() >> communicateWithWifibox is false, so not executing this function"); } } - + this.startStatusCheckInterval = function() { + console.log("Printer:startStatusCheckInterval"); + self.checkStatus(); + clearTimeout(self.checkStatusDelay); + clearTimeout(self.retryCheckStatusDelay); + self.checkStatusDelay = setTimeout(function() { self.checkStatus() }, self.checkStatusInterval); + } + this.stopStatusCheckInterval = function() { + console.log("Printer:stopStatusCheckInterval"); + clearTimeout(self.checkStatusDelay); + clearTimeout(self.retryCheckStatusDelay); + } this.checkStatus = function() { console.log("Printer:checkStatus"); this.stateOverruled = false; @@ -268,12 +300,6 @@ function Printer() { $(document).trigger(Printer.UPDATE); - this.resetStatusCheckInterval(); - } - this.resetStatusCheckInterval = function() { - console.log("resetStatusCheckInterval"); - clearTimeout(self.checkStatusDelay); - clearTimeout(self.retryCheckStatusDelay); - self.checkStatusDelay = setTimeout(function() { self.checkStatus() }, self.checkStatusInterval); + this.stopStatusCheckInterval(); } } \ No newline at end of file