From 6ea0dd6a84b90c24e2ab8d0cc347aca4d3387482 Mon Sep 17 00:00:00 2001 From: peteruithoven Date: Mon, 12 Aug 2013 16:52:31 +0200 Subject: [PATCH] Added timeout & retry to preheat/heatup --- js/Printer.js | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/js/Printer.js b/js/Printer.js index 1888c19..1b1a2ba 100644 --- a/js/Printer.js +++ b/js/Printer.js @@ -32,13 +32,26 @@ function Printer() { this.preheat = function() { console.log("Printer:preheat"); var postData = { id: 0 }; - $.post( this.wifiboxURL + "/printer/heatup", postData , function(e) { - console.log("Printer:preheat response: " + e); - - if (e.success = true) { - console.log(" success"); - } - }); + 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); + }, + error: function(jqXHR, status, errorThrown){ //the status returned will be "timeout" + //console.log("Printer:temperature error. Status: ",status,' errorThrown: ',errorThrown); + switch(status) { + case 'timeout': + console.log("retrieving printer/heatup timeout"); + self.preheat(); + break; + } + } + }); } this.stop = function() { @@ -83,6 +96,7 @@ function Printer() { //console.log("Printer:temperature error. Status: ",status,' errorThrown: ',errorThrown); switch(status) { case 'timeout': + console.log("retrieving printer/temperature timeout"); self.checkTemperature(); break; } @@ -119,6 +133,7 @@ function Printer() { switch(status) { case 'timeout': self.checkProgress(); + console.log("retrieving printer/progress timeout"); break; } }