0
0
mirror of https://github.com/Doodle3D/doodle3d-client.git synced 2024-11-25 10:37:56 +01:00

Merge branch 'feature/printerdriver' of https://github.com/Doodle3D/doodle3d-client into feature/printerdriver

# By Wouter R (2) and peteruithoven (1)
# Via Wouter R (2) and peteruithoven (1)
* 'feature/printerdriver' of https://github.com/Doodle3D/doodle3d-client:
  Warning text improvement
  Fix spelling error.
  Disable settings button if printer is busy or no control access.
This commit is contained in:
Adriaan Wormgoor 2013-10-23 19:10:40 +02:00
commit 7057a92da6
5 changed files with 103 additions and 66 deletions

View File

@ -173,7 +173,7 @@ function Printer() {
this.gcode = []; this.gcode = [];
btnStop.css("display","block"); // hack btnStop.css("display","block"); // hack
self.removeLeaveWarning(); self.removeLeaveWarning();
message.set("Doodle is sent to printer...",Message.INFO,true); message.set("Doodle has been sent to printer...",Message.INFO,true);
//self.targetTemperature = settings["printer.temperature"]; // slight hack //self.targetTemperature = settings["printer.temperature"]; // slight hack
} else { } else {
// only if the state hasn't bin changed (by for example pressing stop) we send more gcode // only if the state hasn't bin changed (by for example pressing stop) we send more gcode

View File

@ -26,6 +26,11 @@ var settings = {
} }
//wrapper to prevent scoping issues in showSettings()
function openSettingsWindow() {
settingsWindow.showSettings();
}
function SettingsWindow() { function SettingsWindow() {
this.wifiboxURL; this.wifiboxURL;
this.wifiboxCGIBinURL this.wifiboxCGIBinURL
@ -34,7 +39,7 @@ function SettingsWindow() {
this.timeoutTime = 3000; this.timeoutTime = 3000;
this.retryDelay = 2000; // retry setTimout delay this.retryDelay = 2000; // retry setTimout delay
this.retryRetrieveNetworkStatusDelayTime = 1000;// retry setTimout delay this.retryRetrieveNetworkStatusDelayTime = 1000;// retry setTimout delay
this.retryLoadSettingsDelay; // retry setTimout instance this.retryLoadSettingsDelay; // retry setTimout instance
this.retrySaveSettingsDelay; // retry setTimout instance this.retrySaveSettingsDelay; // retry setTimout instance
this.retryRetrieveNetworkStatusDelay;// retry setTimout instance this.retryRetrieveNetworkStatusDelay;// retry setTimout instance
@ -45,11 +50,11 @@ function SettingsWindow() {
this.networks; this.networks;
this.currentNetwork; // the ssid of the network the box is on this.currentNetwork; // the ssid of the network the box is on
this.selectedNetwork; // the ssid of the selected network in the client mode settings this.selectedNetwork; // the ssid of the selected network in the client mode settings
this.currentLocalIP = ""; this.currentLocalIP = "";
this.clientModeState = SettingsWindow.NOT_CONNECTED; this.clientModeState = SettingsWindow.NOT_CONNECTED;
this.currentAP; this.currentAP;
this.apModeState = SettingsWindow.NO_AP; this.apModeState = SettingsWindow.NO_AP;
// after switching wifi network or creating a access point we delay the status retrieval // after switching wifi network or creating a access point we delay the status retrieval
// because the webserver needs time to switch // because the webserver needs time to switch
this.retrieveNetworkStatusDelay; // setTimout delay this.retrieveNetworkStatusDelay; // setTimout delay
@ -63,28 +68,28 @@ function SettingsWindow() {
SettingsWindow.CONNECTED = "connected"; SettingsWindow.CONNECTED = "connected";
SettingsWindow.CONNECTING = "connecting"; SettingsWindow.CONNECTING = "connecting";
SettingsWindow.CONNECTING_FAILED = "connecting failed" SettingsWindow.CONNECTING_FAILED = "connecting failed"
// network access point mode states // network access point mode states
SettingsWindow.NO_AP = "no ap"; SettingsWindow.NO_AP = "no ap";
SettingsWindow.AP = "ap"; SettingsWindow.AP = "ap";
SettingsWindow.CREATING_AP = "creating ap"; SettingsWindow.CREATING_AP = "creating ap";
SettingsWindow.API_CONNECTING_FAILED = -1 SettingsWindow.API_CONNECTING_FAILED = -1
SettingsWindow.API_NOT_CONNECTED = 0 SettingsWindow.API_NOT_CONNECTED = 0
SettingsWindow.API_CONNECTING = 1 SettingsWindow.API_CONNECTING = 1
SettingsWindow.API_CONNECTED = 2 SettingsWindow.API_CONNECTED = 2
SettingsWindow.API_CREATING = 3 SettingsWindow.API_CREATING = 3
SettingsWindow.API_CREATED = 4 SettingsWindow.API_CREATED = 4
// network mode // network mode
SettingsWindow.NETWORK_MODE_NEITHER = "neither"; SettingsWindow.NETWORK_MODE_NEITHER = "neither";
SettingsWindow.NETWORK_MODE_CLIENT = "clientMode"; SettingsWindow.NETWORK_MODE_CLIENT = "clientMode";
SettingsWindow.NETWORK_MODE_ACCESS_POINT = "accessPointMode"; SettingsWindow.NETWORK_MODE_ACCESS_POINT = "accessPointMode";
this.networkMode = SettingsWindow.NETWORK_MODE_NEITHER; this.networkMode = SettingsWindow.NETWORK_MODE_NEITHER;
this.updatePanel = new UpdatePanel(); this.updatePanel = new UpdatePanel();
var self = this; var self = this;
this.init = function(wifiboxURL,wifiboxCGIBinURL) { this.init = function(wifiboxURL,wifiboxCGIBinURL) {
@ -100,7 +105,7 @@ function SettingsWindow() {
self.form.submit(function (e) { self.submitwindow(e) }); self.form.submit(function (e) { self.submitwindow(e) });
self.loadSettings(); self.loadSettings();
var btnAP = self.form.find("label[for='ap']"); var btnAP = self.form.find("label[for='ap']");
var btnClient = self.form.find("label[for='client']"); var btnClient = self.form.find("label[for='client']");
var btnRefresh = self.form.find("#refreshNetworks"); var btnRefresh = self.form.find("#refreshNetworks");
@ -116,7 +121,7 @@ function SettingsWindow() {
btnConnect.on('touchstart mousedown',self.connectToNetwork); btnConnect.on('touchstart mousedown',self.connectToNetwork);
btnCreate.on('touchstart mousedown',self.createAP); btnCreate.on('touchstart mousedown',self.createAP);
networkSelector.change(self.networkSelectorChanged); networkSelector.change(self.networkSelectorChanged);
// update panel // update panel
var $updatePanelElement = self.form.find("#updatePanel"); var $updatePanelElement = self.form.find("#updatePanel");
self.updatePanel.init(wifiboxURL,$updatePanelElement); self.updatePanel.init(wifiboxURL,$updatePanelElement);
@ -128,7 +133,7 @@ function SettingsWindow() {
self.saveSettings(self.readForm(),function(){ self.saveSettings(self.readForm(),function(){
self.hideSettings(); self.hideSettings();
}); });
clearTimeout(self.retryRetrieveNetworkStatusDelay); clearTimeout(self.retryRetrieveNetworkStatusDelay);
} }
@ -253,7 +258,7 @@ function SettingsWindow() {
self.form.find(".errorMsg").remove(); self.form.find(".errorMsg").remove();
self.form.find(".error").removeClass("error"); self.form.find(".error").removeClass("error");
} }
this.readForm = function() { this.readForm = function() {
//console.log("SettingsWindow:readForm"); //console.log("SettingsWindow:readForm");
var settings = {}; var settings = {};
@ -338,7 +343,7 @@ function SettingsWindow() {
} }
} }
}).fail(function() { }).fail(function() {
}); });
} }
} }
@ -354,22 +359,22 @@ function SettingsWindow() {
success: function(response){ success: function(response){
console.log("Settings:retrieveNetworkStatus response: ",response); console.log("Settings:retrieveNetworkStatus response: ",response);
if(response.status == "error") { if(response.status == "error") {
} else { } else {
var data = response.data; var data = response.data;
if(typeof data.status === 'string') { if(typeof data.status === 'string') {
data.status = parseInt(data.status); data.status = parseInt(data.status);
} }
//console.log(" data.status: ",data.status,data.statusMessage); //console.log(" data.status: ",data.status,data.statusMessage);
// Determine which network settings to show // Determine which network settings to show
switch(data.status) { switch(data.status) {
case SettingsWindow.API_NOT_CONNECTED: case SettingsWindow.API_NOT_CONNECTED:
//console.log(" not connected & not a access point"); //console.log(" not connected & not a access point");
self.apFieldSet.show(); self.apFieldSet.show();
self.clientFieldSet.show(); self.clientFieldSet.show();
self.networkMode = SettingsWindow.NETWORK_MODE_NEITHER; self.networkMode = SettingsWindow.NETWORK_MODE_NEITHER;
break; break;
case SettingsWindow.API_CONNECTING_FAILED: case SettingsWindow.API_CONNECTING_FAILED:
@ -377,14 +382,14 @@ function SettingsWindow() {
case SettingsWindow.API_CONNECTED: case SettingsWindow.API_CONNECTED:
//console.log(" client mode"); //console.log(" client mode");
self.form.find("#client").prop('checked',true); self.form.find("#client").prop('checked',true);
self.apFieldSet.hide(); self.apFieldSet.hide();
self.clientFieldSet.show(); self.clientFieldSet.show();
if(data.status == SettingsWindow.API_CONNECTED) { if(data.status == SettingsWindow.API_CONNECTED) {
var networkSelector = self.form.find("#network"); var networkSelector = self.form.find("#network");
networkSelector.val(data.ssid); networkSelector.val(data.ssid);
self.currentNetwork = data.ssid; self.currentNetwork = data.ssid;
self.currentLocalIP = data.localip; self.currentLocalIP = data.localip;
self.selectNetwork(data.ssid); self.selectNetwork(data.ssid);
@ -397,31 +402,31 @@ function SettingsWindow() {
case SettingsWindow.API_CREATED: case SettingsWindow.API_CREATED:
//console.log(" access point mode"); //console.log(" access point mode");
self.form.find("#ap").prop('checked',true); self.form.find("#ap").prop('checked',true);
self.apFieldSet.show(); self.apFieldSet.show();
self.clientFieldSet.hide(); self.clientFieldSet.hide();
self.currentNetwork = undefined; self.currentNetwork = undefined;
self.selectNetwork(SettingsWindow.NOT_CONNECTED); self.selectNetwork(SettingsWindow.NOT_CONNECTED);
var networkSelector = self.form.find("#network"); var networkSelector = self.form.find("#network");
networkSelector.val(SettingsWindow.NOT_CONNECTED); networkSelector.val(SettingsWindow.NOT_CONNECTED);
if(data.ssid && data.status == SettingsWindow.API_CREATED) { if(data.ssid && data.status == SettingsWindow.API_CREATED) {
self.currentAP = data.ssid; self.currentAP = data.ssid;
} }
self.networkMode = SettingsWindow.NETWORK_MODE_ACCESS_POINT; self.networkMode = SettingsWindow.NETWORK_MODE_ACCESS_POINT;
break; break;
} }
self.updatePanel.setNetworkMode(self.networkMode); self.updatePanel.setNetworkMode(self.networkMode);
// update status message // update status message
switch(data.status) { switch(data.status) {
case SettingsWindow.API_CONNECTING_FAILED: case SettingsWindow.API_CONNECTING_FAILED:
self.setClientModeState(SettingsWindow.CONNECTING_FAILED,data.statusMessage); self.setClientModeState(SettingsWindow.CONNECTING_FAILED,data.statusMessage);
self.setAPModeState(SettingsWindow.NO_AP,""); self.setAPModeState(SettingsWindow.NO_AP,"");
break; break;
case SettingsWindow.API_NOT_CONNECTED: case SettingsWindow.API_NOT_CONNECTED:
self.setClientModeState(SettingsWindow.NOT_CONNECTED,""); self.setClientModeState(SettingsWindow.NOT_CONNECTED,"");
self.setAPModeState(SettingsWindow.NO_AP,""); self.setAPModeState(SettingsWindow.NO_AP,"");
break; break;
case SettingsWindow.API_CONNECTING: case SettingsWindow.API_CONNECTING:
@ -433,15 +438,15 @@ function SettingsWindow() {
self.setAPModeState(SettingsWindow.NO_AP,""); self.setAPModeState(SettingsWindow.NO_AP,"");
break; break;
case SettingsWindow.API_CREATING: case SettingsWindow.API_CREATING:
self.setClientModeState(SettingsWindow.NOT_CONNECTED,""); self.setClientModeState(SettingsWindow.NOT_CONNECTED,"");
self.setAPModeState(SettingsWindow.CREATING_AP,""); self.setAPModeState(SettingsWindow.CREATING_AP,"");
break; break;
case SettingsWindow.API_CREATED: case SettingsWindow.API_CREATED:
self.setClientModeState(SettingsWindow.NOT_CONNECTED,""); self.setClientModeState(SettingsWindow.NOT_CONNECTED,"");
self.setAPModeState(SettingsWindow.AP,""); self.setAPModeState(SettingsWindow.AP,"");
break; break;
} }
// Keep checking for updates? // Keep checking for updates?
if(connecting) { if(connecting) {
switch(data.status) { switch(data.status) {
@ -492,7 +497,7 @@ function SettingsWindow() {
this.form.find("#passwordLabel").hide(); this.form.find("#passwordLabel").hide();
this.form.find("#password").hide(); this.form.find("#password").hide();
} }
this.setClientModeState = function(state,msg) { this.setClientModeState = function(state,msg) {
var field = this.form.find("#clientModeState"); var field = this.form.find("#clientModeState");
var btnConnect = self.form.find("#connectToNetwork"); var btnConnect = self.form.find("#connectToNetwork");
@ -503,7 +508,7 @@ function SettingsWindow() {
break; break;
case SettingsWindow.CONNECTED: case SettingsWindow.CONNECTED:
btnConnect.removeAttr("disabled"); btnConnect.removeAttr("disabled");
var fieldText = "Connected to: <b>"+this.currentNetwork+"</b>."; var fieldText = "Connected to: <b>"+this.currentNetwork+"</b>.";
if(this.currentLocalIP != undefined && this.currentLocalIP != "") { if(this.currentLocalIP != undefined && this.currentLocalIP != "") {
var a = "<a href='http://"+this.currentLocalIP+"' target='_black'>"+this.currentLocalIP+"</a>"; var a = "<a href='http://"+this.currentLocalIP+"' target='_black'>"+this.currentLocalIP+"</a>";
@ -517,7 +522,7 @@ function SettingsWindow() {
break; break;
case SettingsWindow.CONNECTING_FAILED: case SettingsWindow.CONNECTING_FAILED:
btnConnect.removeAttr("disabled"); btnConnect.removeAttr("disabled");
field.html(msg); field.html(msg);
break; break;
} }
this.clientModeState = state; this.clientModeState = state;
@ -552,10 +557,10 @@ function SettingsWindow() {
} }
console.log(" postData: ",postData); console.log(" postData: ",postData);
if (communicateWithWifibox) { if (communicateWithWifibox) {
// save network related settings and on complete, connect to network // save network related settings and on complete, connect to network
self.saveSettings(self.readForm(),function() { self.saveSettings(self.readForm(),function() {
$.ajax({ $.ajax({
url: self.wifiboxCGIBinURL + "/network/associate", url: self.wifiboxCGIBinURL + "/network/associate",
type: "POST", type: "POST",
@ -573,7 +578,7 @@ function SettingsWindow() {
}); });
} }
self.setClientModeState(SettingsWindow.CONNECTING,""); self.setClientModeState(SettingsWindow.CONNECTING,"");
// after switching wifi network or creating a access point we delay the status retrieval // after switching wifi network or creating a access point we delay the status retrieval
// because the webserver needs time to switch // because the webserver needs time to switch
clearTimeout(self.retrieveNetworkStatusDelay); clearTimeout(self.retrieveNetworkStatusDelay);
@ -583,7 +588,7 @@ function SettingsWindow() {
this.createAP = function() { this.createAP = function() {
console.log("createAP"); console.log("createAP");
if (communicateWithWifibox) { if (communicateWithWifibox) {
// save network related settings and on complete, create access point // save network related settings and on complete, create access point
self.saveSettings(self.readForm(),function() { self.saveSettings(self.readForm(),function() {
self.setAPModeState(SettingsWindow.CREATING_AP); // get latest substituted ssid self.setAPModeState(SettingsWindow.CREATING_AP); // get latest substituted ssid
@ -600,7 +605,7 @@ function SettingsWindow() {
//clearTimeout(self.retrySaveSettingsDelay); //clearTimeout(self.retrySaveSettingsDelay);
//self.retrySaveSettingsDelay = setTimeout(function() { self.saveSettings() },self.retryDelay); // retry after delay //self.retrySaveSettingsDelay = setTimeout(function() { self.saveSettings() },self.retryDelay); // retry after delay
}); });
self.setAPModeState(SettingsWindow.CREATING_AP,""); self.setAPModeState(SettingsWindow.CREATING_AP,"");
// after switching wifi network or creating a access point we delay the status retrieval // after switching wifi network or creating a access point we delay the status retrieval

View File

@ -160,11 +160,8 @@ function initButtonBehavior() {
loadSettings(); loadSettings();
}); });
}*/ }*/
btnSettings.bind('touchstart mousedown',function () { enableButton(btnSettings, openSettingsWindow);
//e.preventDefault();
//console.log("btnSettings clicked");
settingsWindow.showSettings();
});
// btnSettings.on('touchend', function(e) { // btnSettings.on('touchend', function(e) {
// e.preventDefault(); // e.preventDefault();
// console.log("btnSettings touchend"); // console.log("btnSettings touchend");
@ -214,14 +211,14 @@ function print(e) {
//setState(Printer.BUFFERING_STATE,printer.hasControl); //setState(Printer.BUFFERING_STATE,printer.hasControl);
printer.overruleState(Printer.BUFFERING_STATE); printer.overruleState(Printer.BUFFERING_STATE);
btnStop.css("display","none"); // hack btnStop.css("display","none"); // hack
// we put the gcode generation in a little delay // we put the gcode generation in a little delay
// so that for example the print button is disabled right away // so that for example the print button is disabled right away
clearTimeout(gcodeGenerateDelayer); clearTimeout(gcodeGenerateDelayer);
gcodeGenerateDelayer = setTimeout(function() { gcodeGenerateDelayer = setTimeout(function() {
var gcode = generate_gcode(); var gcode = generate_gcode();
if (sendPrintCommands) { if (sendPrintCommands) {
if(gcode.length > 0) { if(gcode.length > 0) {
@ -238,7 +235,7 @@ function print(e) {
$("#textdump").text(""); $("#textdump").text("");
$("#textdump").text(gcode.join("\n")); $("#textdump").text(gcode.join("\n"));
} }
}, gcodeGenerateDelay); }, gcodeGenerateDelay);
} else { } else {
console.log("f:print >> not enough points!"); console.log("f:print >> not enough points!");
@ -318,11 +315,11 @@ function update() {
progressbar.update(printer.currentLine, printer.totalLines); progressbar.update(printer.currentLine, printer.totalLines);
} }
function setState(newState,newHasControl) { function setState(newState,newHasControl) {
if(newState == state && newHasControl == hasControl) return; if(newState == state && newHasControl == hasControl) return;
prevState = state; prevState = state;
console.log("setState: ",prevState," > ",newState," ( ",newHasControl,")"); console.log("setState: ",prevState," > ",newState," ( ",newHasControl,")");
setDebugText("State: "+newState); setDebugText("State: "+newState);
@ -350,38 +347,60 @@ function setState(newState,newHasControl) {
// thermometer // thermometer
switch(newState) { switch(newState) {
case Printer.IDLE_STATE: case Printer.IDLE_STATE: /* fall-through */
case Printer.BUFFERING_STATE: case Printer.BUFFERING_STATE: /* fall-through */
case Printer.PRINTING_STATE: case Printer.PRINTING_STATE: /* fall-through */
case Printer.STOPPING_STATE: case Printer.STOPPING_STATE:
thermometer.show(); thermometer.show();
break; break;
default: default:
thermometer.hide(); thermometer.hide();
break; break;
} }
// progress indicator // progress indicator
switch(newState) { switch(newState) {
case Printer.PRINTING_STATE: case Printer.PRINTING_STATE:
progressbar.show(); progressbar.show();
break; break;
default: default:
progressbar.hide(); progressbar.hide();
break; break;
} }
/* settings button */
switch(newState) {
case Printer.IDLE_STATE:
enableButton(btnSettings, openSettingsWindow);
break;
case Printer.WIFIBOX_DISCONNECTED_STATE: /* fall-through */
case Printer.BUFFERING_STATE: /* fall-through */
case Printer.PRINTING_STATE: /* fall-through */
case Printer.STOPPING_STATE:
disableButton(btnSettings);
break;
default:
enableButton(btnSettings, openSettingsWindow);
break;
}
if(newState == Printer.WIFIBOX_DISCONNECTED_STATE) { if(newState == Printer.WIFIBOX_DISCONNECTED_STATE) {
message.set("Lost connection to WiFi box",Message.ERROR); message.set("Lost connection to WiFi box",Message.ERROR);
} else if(prevState == Printer.WIFIBOX_DISCONNECTED_STATE) { } else if(prevState == Printer.WIFIBOX_DISCONNECTED_STATE) {
message.set("Connected to WiFi box",Message.INFO,true); message.set("Connected to WiFi box",Message.INFO,true);
} else if(newState == Printer.DISCONNECTED_STATE) { } else if(newState == Printer.DISCONNECTED_STATE) {
message.set("Printer disconnected",Message.WARNING,true); message.set("Printer disconnected",Message.WARNING,true);
} else if(prevState == Printer.DISCONNECTED_STATE && newState == Printer.IDLE_STATE || } else if(prevState == Printer.DISCONNECTED_STATE && newState == Printer.IDLE_STATE ||
prevState == Printer.UNKNOWN_STATE && newState == Printer.IDLE_STATE) { prevState == Printer.UNKNOWN_STATE && newState == Printer.IDLE_STATE) {
message.set("Printer connected",Message.INFO,true); message.set("Printer connected",Message.INFO,true);
} else if(prevState == Printer.PRINTING_STATE && newState == Printer.STOPPING_STATE) {
console.log("stopmsg show");
message.set("Printer stopping",Message.INFO,false);
} else if(prevState == Printer.STOPPING_STATE && newState == Printer.IDLE_STATE) {
console.log("stopmsg hide");
message.hide();
} }
state = newState; state = newState;
hasControl = newHasControl; hasControl = newHasControl;
} }

View File

@ -142,7 +142,7 @@ function generate_gcode() {
console.log("pointsToPrint: ",pointsToPrint); console.log("pointsToPrint: ",pointsToPrint);
if(pointsToPrint > MAX_POINTS_TO_PRINT) { if(pointsToPrint > MAX_POINTS_TO_PRINT) {
alert("Sorry, your doodle too complex and / or to high"); alert("Sorry, your doodle is too complex or too high. Please try to simplify it.");
console.log("ERROR: to many points too convert to gcode"); console.log("ERROR: to many points too convert to gcode");
return []; return [];
} }

View File

@ -112,6 +112,19 @@ $(function() {
} }
}); });
function enableButton(elem, handler) {
//var elem = $('#'+domId);
elem.removeClass("disabled");
elem.unbind('touchstart mousedown');
elem.bind('touchstart mousedown', handler);
}
function disableButton(elem) {
//var elem = $('#'+domId);
elem.addClass("disabled");
elem.unbind('touchstart mousedown');
}
function showOrHideThermo() { function showOrHideThermo() {
console.log("f:showOrHideThermo()"); console.log("f:showOrHideThermo()");
if (showOrHide) { if (showOrHide) {