From 9fb9ee2bc401220417eb2bc88798a6adbb6e26bc Mon Sep 17 00:00:00 2001 From: peteruithoven Date: Mon, 14 Oct 2013 17:40:56 +0200 Subject: [PATCH] More robust state override --- js/Printer.js | 29 ++++++++++++++++++++++++----- js/buttonbehaviors.js | 6 ++++-- settings.html | 2 +- 3 files changed, 29 insertions(+), 8 deletions(-) diff --git a/js/Printer.js b/js/Printer.js index b06e734..497241c 100644 --- a/js/Printer.js +++ b/js/Printer.js @@ -45,6 +45,8 @@ function Printer() { this.maxGCodeSize = 10; // max size of gcode in MB's (estimation) + this.stateOverruled = false; + // Events Printer.UPDATE = "update"; @@ -152,8 +154,10 @@ function Printer() { //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 - if(self.state == Printer.STATE_PRINTING || self.state == Printer.STATE_BUFFERING) { - console.log("sending next part"); + + console.log("Printer:sendPrintPart:gcode part received (state: ",self.state,")"); + if(self.state == Printer.PRINTING_STATE || self.state == Printer.BUFFERING_STATE) { + console.log("Printer:sendPrintPart:sending next part"); self.sendPrintPart(sendIndex + sendLength, sendLength); } } @@ -195,7 +199,9 @@ function Printer() { } this.checkStatus = function() { - //console.log("Printer:checkStatus"); + console.log("Printer:checkStatus"); + this.stateOverruled = false; + console.log(" stateOverruled: ",this.stateOverruled); var self = this; if (communicateWithWifibox) { $.ajax({ @@ -203,7 +209,7 @@ function Printer() { dataType: 'json', timeout: this.timeoutTime, success: function(response){ - console.log("Printer:status: ",response.data.state," response: ",response); + console.log(" Printer:status: ",response.data.state); //," response: ",response); self.handleStatusUpdate(response); @@ -223,12 +229,17 @@ function Printer() { } } this.handleStatusUpdate = function(response) { + console.log("Printer:handleStatusUpdate"); var data = response.data; if(response.status != "success") { self.state = Printer.UNKNOWN_STATE; } else { // state - self.state = data.state; + console.log(" stateOverruled: ",this.stateOverruled); + if(!this.stateOverruled) { + self.state = data.state; + console.log(" state > ",self.state); + } // temperature self.temperature = data.hotend; @@ -248,4 +259,12 @@ function Printer() { } $(document).trigger(Printer.UPDATE); } + this.overruleState = function(newState) { + this.stateOverruled = true; + console.log(" stateOverruled: ",this.stateOverruled); + + self.state = newState; + + $(document).trigger(Printer.UPDATE); + } } \ No newline at end of file diff --git a/js/buttonbehaviors.js b/js/buttonbehaviors.js index 16fcfb8..284e1dd 100644 --- a/js/buttonbehaviors.js +++ b/js/buttonbehaviors.js @@ -191,7 +191,8 @@ function stopPrint() { console.log("f:stopPrint() >> sendPrintCommands = " + sendPrintCommands); if (!confirm("Weet je zeker dat je de huidige print wilt stoppen?")) return; if (sendPrintCommands) printer.stop(); - setState(Printer.STOPPING_STATE,printer.hasControl); + //setState(Printer.STOPPING_STATE,printer.hasControl); + printer.overruleState(Printer.STOPPING_STATE); } @@ -209,7 +210,8 @@ function print(e) { $("#textdump").text(""); if (_points.length > 2) { - setState(Printer.BUFFERING_STATE,printer.hasControl); + //setState(Printer.BUFFERING_STATE,printer.hasControl); + printer.overruleState(Printer.BUFFERING_STATE); var gcode = generate_gcode(); //startPrint(gencode); diff --git a/settings.html b/settings.html index 1af0fac..84ec703 100755 --- a/settings.html +++ b/settings.html @@ -97,7 +97,7 @@ Access point settings
* The text %%MAC_ADDR_TAIL%% will be replaced by the last 6 digits of your Doodle3D Wi-Fi box's MAC address. -
+