Added timeout & retry to preheat/heatup

This commit is contained in:
peteruithoven 2013-08-12 16:52:31 +02:00
parent c6818eae45
commit 6ea0dd6a84
1 changed files with 22 additions and 7 deletions

View File

@ -32,13 +32,26 @@ function Printer() {
this.preheat = function() { this.preheat = function() {
console.log("Printer:preheat"); console.log("Printer:preheat");
var postData = { id: 0 }; var postData = { id: 0 };
$.post( this.wifiboxURL + "/printer/heatup", postData , function(e) { var self = this;
console.log("Printer:preheat response: " + e); $.ajax({
url: this.wifiboxURL + "/printer/heatup",
if (e.success = true) { type: "POST",
console.log(" success"); 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() { this.stop = function() {
@ -83,6 +96,7 @@ function Printer() {
//console.log("Printer:temperature error. Status: ",status,' errorThrown: ',errorThrown); //console.log("Printer:temperature error. Status: ",status,' errorThrown: ',errorThrown);
switch(status) { switch(status) {
case 'timeout': case 'timeout':
console.log("retrieving printer/temperature timeout");
self.checkTemperature(); self.checkTemperature();
break; break;
} }
@ -119,6 +133,7 @@ function Printer() {
switch(status) { switch(status) {
case 'timeout': case 'timeout':
self.checkProgress(); self.checkProgress();
console.log("retrieving printer/progress timeout");
break; break;
} }
} }