From ea2d50fd606b68c8c98bce72e3199ce422ad862c Mon Sep 17 00:00:00 2001 From: Wouter R Date: Fri, 22 Nov 2013 16:51:26 +0100 Subject: [PATCH 01/15] Lower number of lines to send per gcode part to 500, this should fix failure to convert to x3g code for Makerbots (which took about 8 seconds while ajax timeouts are 5 seconds). Bump version to 0.9.1. --- Makefile | 2 +- js_src/Printer.js | 110 +++++++++++++++++++------------------- js_src/gcodeGenerating.js | 32 +++++------ www/index.html | 2 + 4 files changed, 74 insertions(+), 72 deletions(-) diff --git a/Makefile b/Makefile index 84a769a..d69859c 100644 --- a/Makefile +++ b/Makefile @@ -4,7 +4,7 @@ include $(TOPDIR)/rules.mk PKG_NAME := doodle3d-client -PKG_VERSION := 0.9.0 +PKG_VERSION := 0.9.1 PKG_RELEASE := 1 PKG_BUILD_DIR := $(BUILD_DIR)/$(PKG_NAME) diff --git a/js_src/Printer.js b/js_src/Printer.js index aedb569..dcae80c 100644 --- a/js_src/Printer.js +++ b/js_src/Printer.js @@ -11,7 +11,7 @@ function setPrintprogress(val) { //*/ function Printer() { - + Printer.WIFIBOX_DISCONNECTED_STATE = "wifibox disconnected"; Printer.UNKNOWN_STATE = "unknown"; // happens when a printer is connection but there isn't communication yet Printer.DISCONNECTED_STATE = "disconnected"; // printer disconnected @@ -21,40 +21,40 @@ function Printer() { Printer.STOPPING_STATE = "stopping"; // when you stop (abort) a print it prints the endcode Printer.ON_BEFORE_UNLOAD_MESSAGE = "You're doodle is still being send to the printer, leaving will result in a incomplete 3D print"; - + this.temperature = 0; this.targetTemperature = 0; this.currentLine = 0; this.totalLines = 0; this.bufferedLines = 0; this.state = Printer.UNKNOWN_STATE; - this.hasControl = true; // whether this client has control access - - this.wifiboxURL; - + this.hasControl = true; // whether this client has control access + + this.wifiboxURL; + this.checkStatusInterval = 3000; this.checkStatusDelay; this.timeoutTime = 3000; this.sendPrintPartTimeoutTime = 5000; - + this.gcode; // gcode to be printed - this.sendLength = 1500; // max amount of gcode lines per post (limited because WiFi box can't handle to much) + this.sendLength = 500; // max amount of gcode lines per post (limited because WiFi box can't handle to much) this.retryDelay = 2000; // retry setTimout delay this.retrySendPrintPartDelay; // retry setTimout instance this.retryCheckStatusDelay; // retry setTimout instance this.retryStopDelay; // retry setTimout instance this.retryPreheatDelay; // retry setTimout instance - + Printer.MAX_GCODE_SIZE = 10; // max size of gcode in MB's (estimation) - + this.stateOverruled = false; - + // Events Printer.UPDATE = "update"; - + var self = this; - + this.init = function() { console.log("Printer:init"); //this.wifiboxURL = "http://" + window.location.host + "/cgi-bin/d3dapi"; @@ -62,21 +62,21 @@ function Printer() { this.wifiboxURL = wifiboxURL; //this.wifiboxURL = "proxy5.php"; console.log(" wifiboxURL: ",this.wifiboxURL); - + if(autoUpdate) { this.startStatusCheckInterval(); } } - + this.preheat = function() { console.log("Printer:preheat"); - + if( this.state == Printer.BUFFERING_STATE || this.state == Printer.PRINTING_STATE || this.state == Printer.STOPPING_STATE) { return; } - + var self = this; if (communicateWithWifibox) { $.ajax({ @@ -91,7 +91,7 @@ function Printer() { self.retryPreheatDelay = setTimeout(function() { self.preheat() },self.retryDelay); // retry after delay } } - }).fail(function() { + }).fail(function() { console.log("Printer:preheat: failed"); clearTimeout(self.retryPreheatDelay); self.retryPreheatDelay = setTimeout(function() { self.preheat() },self.retryDelay); // retry after delay @@ -100,41 +100,41 @@ function Printer() { console.log ("Printer >> f:preheat() >> communicateWithWifibox is false, so not executing this function"); } } - + this.print = function(gcode) { console.log("Printer:print"); console.log(" gcode total # of lines: " + gcode.length); - + message.set("Sending doodle to printer...",Message.NOTICE); self.addLeaveWarning(); - + /*for (i = 0; i < gcode.length; i++) { gcode[i] += " (" + i + ")"; }*/ - + this.sendIndex = 0; this.gcode = gcode; - + //console.log(" gcode[20]: ",gcode[20]); var gcodeLineSize = this.byteSize(gcode[20]); //console.log(" gcodeLineSize: ",gcodeLineSize); var gcodeSize = gcodeLineSize*gcode.length/1024/1024; // estimate gcode size in MB's console.log(" gcodeSize: ",gcodeSize); - + if(gcodeSize > Printer.MAX_GCODE_SIZE) { alert("Error: Printer:print: gcode file is probably too big ("+gcodeSize+"MB) (max: "+Printer.MAX_GCODE_SIZE+"MB)"); console.log("Error: Printer:print: gcode file is probably too big ("+gcodeSize+"MB) (max: "+Printer.MAX_GCODE_SIZE+"MB)"); - + this.overruleState(Printer.IDLE_STATE); this.startStatusCheckInterval(); message.hide(); self.removeLeaveWarning(); - + return; } - + //this.targetTemperature = settings["printer.temperature"]; // slight hack - + this.sendPrintPart(this.sendIndex, this.sendLength); } this.byteSize = function(s){ @@ -142,10 +142,10 @@ function Printer() { } this.sendPrintPart = function(sendIndex,sendLength) { console.log("Printer:sendPrintPart sendIndex: " + sendIndex + "/" + this.gcode.length + ", sendLength: " + sendLength); - + var firstOne = (sendIndex == 0)? true : false; var start = firstOne; // start printing right away - + var completed = false; if (this.gcode.length < (sendIndex + sendLength)) { console.log(" sending less than max sendLength (and last)"); @@ -154,7 +154,7 @@ function Printer() { completed = true; } var gcodePart = this.gcode.slice(sendIndex, sendIndex+sendLength); - + var postData = { gcode: gcodePart.join("\n"), first: firstOne, start: start}; var self = this; if (communicateWithWifibox) { @@ -166,7 +166,7 @@ function Printer() { timeout: this.sendPrintPartTimeoutTime, success: function(data){ console.log("Printer:sendPrintPart response: ",data); - + if(data.status == "success") { if (completed) { console.log("Printer:sendPrintPart:gcode sending completed"); @@ -177,8 +177,8 @@ 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 - - console.log("Printer:sendPrintPart:gcode part received (state: ",self.state,")"); + + 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); @@ -186,22 +186,22 @@ function Printer() { } } // after we know the first gcode packed has bin received or failed - // (and the driver had time to update the printer.state) + // (and the driver had time to update the printer.state) // we start checking the status again if(sendIndex == 0) { self.startStatusCheckInterval(); } } - }).fail(function() { + }).fail(function() { console.log("Printer:sendPrintPart: failed"); clearTimeout(self.retrySendPrintPartDelay); self.retrySendPrintPartDelay = setTimeout(function() { console.log("request printer:sendPrintPart failed retry"); - self.sendPrintPart(sendIndex, sendLength) + 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) + // (and the driver had time to update the printer.state) // we start checking the status again self.startStatusCheckInterval(); }); @@ -209,7 +209,7 @@ function Printer() { console.log ("Printer >> f:sendPrintPart() >> communicateWithWifibox is false, so not executing this function"); } } - + this.stop = function() { console.log("Printer:stop"); endCode = generateEndCode(); @@ -225,19 +225,19 @@ 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) + // (and the driver had time to update the printer.state) // we start checking the status again self.startStatusCheckInterval(); } - }).fail(function() { + }).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) + // (and the driver had time to update the printer.state) // we start checking the status again self.startStatusCheckInterval(); }); @@ -269,9 +269,9 @@ function Printer() { timeout: this.timeoutTime, success: function(response){ //console.log(" Printer:status: ",response.data.state); //," response: ",response); - + self.handleStatusUpdate(response); - + clearTimeout(self.checkStatusDelay); clearTimeout(self.retryCheckStatusDelay); self.checkStatusDelay = setTimeout(function() { self.checkStatus() }, self.checkStatusInterval); @@ -300,11 +300,11 @@ function Printer() { self.state = data.state; //console.log(" state > ",self.state); } - + // temperature self.temperature = data.hotend; self.targetTemperature = data.hotend_target; - + // progress self.currentLine = data.current_line; self.totalLines = data.total_lines; @@ -312,7 +312,7 @@ function Printer() { // access self.hasControl = data.has_control; - + if(self.state == Printer.PRINTING_STATE || self.state == Printer.STOPPING_STATE) { console.log("progress: ",self.currentLine+"/"+self.totalLines+" ("+self.bufferedLines+") ("+self.state+")"); } @@ -322,14 +322,14 @@ function Printer() { this.overruleState = function(newState) { this.stateOverruled = true; console.log(" stateOverruled: ",this.stateOverruled); - + self.state = newState; - + $(document).trigger(Printer.UPDATE); - + this.stopStatusCheckInterval(); } - + this.removeLeaveWarning = function() { window.onbeforeunload = null; } @@ -339,4 +339,4 @@ function Printer() { return Printer.ON_BEFORE_UNLOAD_MESSAGE; }; } -} \ No newline at end of file +} diff --git a/js_src/gcodeGenerating.js b/js_src/gcodeGenerating.js index 8d19f59..d992600 100644 --- a/js_src/gcodeGenerating.js +++ b/js_src/gcodeGenerating.js @@ -25,13 +25,13 @@ gcodeEnd.push("G90"); // absolute positioning gcodeEnd.push("M117 Done "); // display message (20 characters to clear whole screen)*/ -var MAX_POINTS_TO_PRINT = 200000; //400000; //80000; //40000; +var MAX_POINTS_TO_PRINT = 200000; //400000; //80000; //40000; var gcode = []; function generate_gcode() { console.log("f:generategcode()"); - + gcode = []; console.log("settings: ",settings); @@ -56,13 +56,13 @@ function generate_gcode() { var preheatBedTemperature = settings["printer.heatup.bed.temperature"]; var printerBedWidth = settings["printer.bed.width"]; var printerBedHeight = settings["printer.bed.height"]; - + var gCodeOffsetX = printerBedWidth/2; //110; // mm var gCodeOffsetY = printerBedHeight/2; //110; // mm - + var startCode = generateStartCode(); var endCode = generateEndCode(); - + /* console.log("f:generate_gcode >> EFFE CHECKEN:"); console.log(" speed: " + speed); @@ -104,13 +104,13 @@ function generate_gcode() { // console.log("f:generategcode() >> paths: " + paths.toString()); // console.log("paths.toString(): " + paths.toString()); // return; - + //gcode.push("M104 S" + temperature); // set target temperature and do not wait for the extruder to reach it //gcode.push("M109 S" + temperature); // set target temperature and wait for the extruder to reach it - + // add gcode begin commands gcode = gcode.concat(startCode); - + //gcode.push("M109 S" + temperature); // set target temperature and wait for the extruder to reach it var layers = maxObjectHeight / layerHeight; //maxObjectHeight instead of objectHeight @@ -134,15 +134,15 @@ function generate_gcode() { //console.log(" numLayers: ",(layers*(objectHeight/maxObjectHeight))); //console.log(" pointsToPrint: ",pointsToPrint); //console.log(" MAX_POINTS_TO_PRINT: ",MAX_POINTS_TO_PRINT); - + console.log("pointsToPrint: ",pointsToPrint); - + if(pointsToPrint > MAX_POINTS_TO_PRINT) { 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"); return []; } - + for (var layer = 0; layer < layers; layer++) { var p = JSON.parse(JSON.stringify(points)); // [].concat(points); @@ -254,13 +254,13 @@ function generate_gcode() { } // add gcode end commands gcode = gcode.concat(endCode); - + return gcode; } function generateStartCode() { var printerType = settings["printer.type"]; - + var startCode = ""; if(settingsWindow.isMarlinPrinter(printerType)) { startCode = settings["printer.startcode.marlin"]; @@ -273,7 +273,7 @@ function generateStartCode() { } function generateEndCode() { var printerType = settings["printer.type"]; - + var endCode = ""; if(settingsWindow.isMarlinPrinter(printerType)) { endCode = settings["printer.endcode.marlin"]; @@ -292,9 +292,9 @@ function subsituteVariables(gcode) { var preheatTemperature = settings["printer.heatup.temperature"]; var preheatBedTemperature = settings["printer.heatup.bed.temperature"]; var printerType = settings["printer.type"]; - + switch (printerType) { - case "makerbot_replicator2": printerType = "r2x"; break; + case "makerbot_replicator2": printerType = "r2x"; break; //FIXME: this should be r2, with a separate type for r2x case "makerbot_thingomatic": printerType = "t6"; break; } diff --git a/www/index.html b/www/index.html index 9fda06e..2965c91 100644 --- a/www/index.html +++ b/www/index.html @@ -150,6 +150,8 @@ + + From c2d6c2274ee294d28eed0ca6b71133d1547ea507 Mon Sep 17 00:00:00 2001 From: Wouter R Date: Fri, 22 Nov 2013 18:01:53 +0100 Subject: [PATCH 02/15] Default makerbot printer type to replicator 2. --- js_src/gcodeGenerating.js | 1 + 1 file changed, 1 insertion(+) diff --git a/js_src/gcodeGenerating.js b/js_src/gcodeGenerating.js index d992600..7002d78 100644 --- a/js_src/gcodeGenerating.js +++ b/js_src/gcodeGenerating.js @@ -296,6 +296,7 @@ function subsituteVariables(gcode) { switch (printerType) { case "makerbot_replicator2": printerType = "r2x"; break; //FIXME: this should be r2, with a separate type for r2x case "makerbot_thingomatic": printerType = "t6"; break; + default: printerType = "r2"; break; } gcode = gcode.replace(/{printingTemp}/gi ,temperature); From eb2736afcb8283b4a3c7fca06e1be6ef62e4d291 Mon Sep 17 00:00:00 2001 From: Wouter R Date: Fri, 29 Nov 2013 23:25:14 +0100 Subject: [PATCH 03/15] Add openwrt option to enable/disable minification of javascript files (enabled by default). Bump version to 0.9.2. --- Makefile | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index d69859c..f4ed59f 100644 --- a/Makefile +++ b/Makefile @@ -4,7 +4,7 @@ include $(TOPDIR)/rules.mk PKG_NAME := doodle3d-client -PKG_VERSION := 0.9.1 +PKG_VERSION := 0.9.2 PKG_RELEASE := 1 PKG_BUILD_DIR := $(BUILD_DIR)/$(PKG_NAME) @@ -22,6 +22,16 @@ define Package/doodle3d-client/description This package provides the Doodle3D web client, which interacts with the wifibox package using a REST API. endef +define Package/doodle3d-client/config + config DOODLE3D_CLIENT_MINIFY_JS + depends on PACKAGE_doodle3d-client + bool "Minify javascript" + default y + help + All javascript files are concatenated into one file; this file enables minification + of that file. Disable this to make on-the-fly modifications easier. +endef + define Build/Prepare mkdir -p $(PKG_BUILD_DIR) $(CP) less $(PKG_BUILD_DIR)/ @@ -35,7 +45,11 @@ endef define Build/Compile npm install - grunt less autoprefixer cssmin concat uglify +ifeq ($(CONFIG_DOODLE3D_CLIENT_MINIFY_JS),y) + grunt less autoprefixer cssmin concat uglify +else + grunt less autoprefixer cssmin concat +endif endef define Package/doodle3d-client/install @@ -56,7 +70,16 @@ define Package/doodle3d-client/install $(CP) $(PKG_BUILD_DIR)/www/img/* $(1)/www/img/ - $(CP) $(PKG_BUILD_DIR)/www/js/doodle3d-client.min.js $(1)/www/js/ +ifeq ($(CONFIG_DOODLE3D_CLIENT_MINIFY_JS),y) + $(CP) $(PKG_BUILD_DIR)/www/js/doodle3d-client.min.js $(1)/www/js/ +else + #NOTE: if using a symlink here installation with openwrt make fails + # when trying to build with minification after package has been built + # without minification (dangling symlink breaks openwrt's final copy command) + $(CP) $(PKG_BUILD_DIR)/www/js/doodle3d-client.js $(1)/www/js/doodle3d-client.min.js + #$(LN) -s /www/js/doodle3d-client.js $(1)/www/js/doodle3d-client.min.js +endif + $(CP) $(PKG_BUILD_DIR)/www/js/libs/* $(1)/www/js/libs/ $(CP) $(PKG_BUILD_DIR)/www/library $(1)/www/ From 965119de33c5e41d00136d5b96df09d033c1dbd2 Mon Sep 17 00:00:00 2001 From: peteruithoven Date: Sun, 1 Dec 2013 18:38:02 +0100 Subject: [PATCH 04/15] First version of new PrinterPanel. --- Gruntfile.js | 1 + js_src/PrinterPanel.js | 73 +++++++++++++++++++++++++++++++++++++++ js_src/SettingsWindow.js | 54 +++++++++-------------------- js_src/gcodeGenerating.js | 15 ++------ www/settings.html | 66 ++++++++++++----------------------- 5 files changed, 115 insertions(+), 94 deletions(-) create mode 100644 js_src/PrinterPanel.js diff --git a/Gruntfile.js b/Gruntfile.js index 05b2e5c..a008876 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -18,6 +18,7 @@ module.exports = function(grunt) { src: [ 'js_src/SettingsWindow.js', 'js_src/UpdatePanel.js', + 'js_src/PrinterPanel.js', 'js_src/Help.js', 'js_src/d3dServerInterfacing.js', 'js_src/verticalShapes.js', diff --git a/js_src/PrinterPanel.js b/js_src/PrinterPanel.js new file mode 100644 index 0000000..0e50997 --- /dev/null +++ b/js_src/PrinterPanel.js @@ -0,0 +1,73 @@ +function PrinterPanel() { + this.wifiboxURL; + this.element; + + this.retryDelay = 1000; + this.retryDelayer; // setTimout instance + //this.timeoutTime = 3000; + + this.printerType; + this.printerSettingsNames; + + var self = this; + + this.init = function(wifiboxURL,element) { + self.wifiboxURL = wifiboxURL; + self.element = element; + + self.printerSelector = element.find("#printerType"); + self.printerSelector.change(self.printerSelectorChanged); + + var formElements = element.find("[name]"); + self.printerSettingsNames = []; + formElements.each( function(index,element) { + self.printerSettingsNames.push(element.name); + }); + } + this.printerSelectorChanged = function(e) { + console.log("PrinterPanel:printerSelectorChanged"); + console.log("self: ", self); + self.printerType = self.printerSelector.find("option:selected").val(); + self.savePrinterType(self.loadPrinterSettings); + } + + this.savePrinterType = function(complete) { + console.log("PrinterPanel:savePrinterType"); + var postData = {}; + postData[self.printerSelector.attr("name")] = self.printerType; + console.log("postData: ",postData); + $.ajax({ + url: self.wifiboxURL + "/config/", + type: "POST", + dataType: 'json', + data: postData, + success: function(response){ + console.log("PrinterPanel:savePrinterType response: ",response); + if(complete) complete(); + } + }).fail(function() { + console.log("PrinterPanel:savePrinterType: failed"); + }); + } + this.loadPrinterSettings = function() { + console.log("PrinterPanel:loadPrinterSettings"); + console.log(" self.printerSettingsNames: ",self.printerSettingsNames); + var getData = {}; + $.each(self.printerSettingsNames, function(key, val) { + getData[val] = ""; + }); + console.log("getData: ",getData); + $.ajax({ + url: self.wifiboxURL + "/config/", + dataType: 'json', + data: getData, + success: function(response){ + console.log("PrinterPanel:loadPrinterSettings response: ",response); + + self.fillForm(response.data,self.element); + } + }).fail(function() { + console.log("PrinterPanel:loadPrinterSettings: failed"); + }); + } +} \ No newline at end of file diff --git a/js_src/SettingsWindow.js b/js_src/SettingsWindow.js index 4b38378..952d143 100644 --- a/js_src/SettingsWindow.js +++ b/js_src/SettingsWindow.js @@ -90,6 +90,7 @@ function SettingsWindow() { this.networkMode = SettingsWindow.NETWORK_MODE_NEITHER; this.updatePanel = new UpdatePanel(); + this.printerPanel = new PrinterPanel(); var self = this; @@ -109,7 +110,7 @@ function SettingsWindow() { self.loadSettings(); - self.printerSelector = self.form.find("#printerType"); + var btnAP = self.form.find("label[for='ap']"); var btnClient = self.form.find("label[for='client']"); var btnRefresh = self.form.find("#refreshNetworks"); @@ -118,8 +119,6 @@ function SettingsWindow() { var networkSelector = self.form.find("#network"); self.apFieldSet = self.form.find("#apSettings"); self.clientFieldSet = self.form.find("#clientSettings"); - self.gcodeSettings = self.form.find("#gcodeSettings"); - self.x3gSettings = self.form.find("#x3gSettings"); self.btnRestoreSettings = self.form.find("#restoreSettings"); btnAP.on('touchstart mousedown',self.showAPSettings); @@ -127,14 +126,18 @@ function SettingsWindow() { btnRefresh.on('touchstart mousedown',self.refreshNetworks); btnConnect.on('touchstart mousedown',self.connectToNetwork); btnCreate.on('touchstart mousedown',self.createAP); - self.printerSelector.change(self.printerSelectorChanged); networkSelector.change(self.networkSelectorChanged); self.btnRestoreSettings.on('touchstart mousedown',self.resetSettings); - // update panel var $updatePanelElement = self.form.find("#updatePanel"); self.updatePanel.init(wifiboxURL,$updatePanelElement); + + // printer panel + var $printerPanelElement = self.form.find("#printerPanel"); + self.printerPanel.init(wifiboxURL,$printerPanelElement); + self.printerPanel.fillForm = self.fillForm; + }); } this.submitwindow = function(e) { @@ -185,7 +188,7 @@ function SettingsWindow() { console.log("Settings:loadSettings response: ",response); settings = response.data; console.log(" settings: ",settings); - self.fillForm(); + self.fillForm(settings); $(document).trigger(SettingsWindow.SETTINGS_LOADED); if(complete) complete(); } @@ -198,16 +201,16 @@ function SettingsWindow() { this.refreshNetworks(); this.retrieveNetworkStatus(false); } - this.fillForm = function() { - console.log("SettingsWindow:fillForm"); - + this.fillForm = function(settings,form) { + if(!form) form = this.form; // if no form specified, fill whole form + //fill form with loaded settings - var selects = this.form.find("select"); + var selects = form.find("select"); selects.each( function(index,element) { var element = $(element); element.val(settings[element.attr('name')]); }); - var inputs = this.form.find("input"); + var inputs = form.find("input"); inputs.each( function(index,element) { var element = $(element); //console.log("printer setting input: ",index,element.attr("type"),element.attr('name')); //,element); @@ -221,13 +224,12 @@ function SettingsWindow() { break; } }); - var textareas = this.form.find("textarea"); + var textareas = form.find("textarea"); textareas.each( function(index,element) { var element = $(element); var value = settings[element.attr('name')]; element.val(value); }); - self.printerSelectorChanged(); } this.saveSettings = function(newSettings,complete) { @@ -288,7 +290,7 @@ function SettingsWindow() { } else { settings = response.data; console.log(" settings: ",settings); - self.fillForm(); + self.fillForm(settings); $(document).trigger(SettingsWindow.SETTINGS_LOADED); self.btnRestoreSettings.removeAttr("disabled"); @@ -345,30 +347,6 @@ function SettingsWindow() { //console.log(settings); return settings; } - - this.printerSelectorChanged = function(e) { - var selectedOption = self.printerSelector.find("option:selected"); - if(self.isMarlinPrinter(selectedOption.val())) { - self.x3gSettings.hide(); - self.gcodeSettings.show(); - } else { - self.gcodeSettings.hide(); - self.x3gSettings.show(); - } - } - - this.isMarlinPrinter = function(printer) { - switch(printer) { - case "makerbot_generic": - case "makerbot_replicator2": - case "makerbot_thingomatic": - return false; - break; - default: - return true; - break; - } - } this.signin = function() { $.ajax({ diff --git a/js_src/gcodeGenerating.js b/js_src/gcodeGenerating.js index 8d19f59..e41d95f 100644 --- a/js_src/gcodeGenerating.js +++ b/js_src/gcodeGenerating.js @@ -261,12 +261,7 @@ function generate_gcode() { function generateStartCode() { var printerType = settings["printer.type"]; - var startCode = ""; - if(settingsWindow.isMarlinPrinter(printerType)) { - startCode = settings["printer.startcode.marlin"]; - } else { - startCode = settings["printer.startcode.x3g"]; - } + var startCode = settings["printer.startcode"]; startCode = subsituteVariables(startCode); startCode = startCode.split("\n"); return startCode; @@ -274,12 +269,7 @@ function generateStartCode() { function generateEndCode() { var printerType = settings["printer.type"]; - var endCode = ""; - if(settingsWindow.isMarlinPrinter(printerType)) { - endCode = settings["printer.endcode.marlin"]; - } else { - endCode = settings["printer.endcode.x3g"]; - } + var endCode = settings["printer.endcode"]; endCode = subsituteVariables(endCode); endCode = endCode.split("\n"); return endCode; @@ -296,6 +286,7 @@ function subsituteVariables(gcode) { switch (printerType) { case "makerbot_replicator2": printerType = "r2x"; break; case "makerbot_thingomatic": printerType = "t6"; break; + case "makerbot_generic": printerType = "r2"; break; } gcode = gcode.replace(/{printingTemp}/gi ,temperature); diff --git a/www/settings.html b/www/settings.html index aac0987..a4323c7 100644 --- a/www/settings.html +++ b/www/settings.html @@ -12,7 +12,7 @@
-
+
3D printer
mm
mm
+
+ GCODE settings +
+
+ +
+
+
+ +
+ + The following texts are replaced: +
+
{printingTemp}
Printing temperature
+
{printingBedTemp}
Printing bed temperature
+
{preheatTemp}
Preheat temperature
+
{preheatBedTemp}
Preheat bed temperature
+
{printerType}
Printer type
+
+
+
@@ -133,49 +154,6 @@
-
- GCODE settings - GCode settings for all printers that use Marlin firmware -
-
- -
-
-
- -
- - The following texts are replaced: -
-
{printingTemp}
Printing temperature
-
{printingBedTemp}
Printing bed temperature
-
{preheatTemp}
Preheat temperature
-
{preheatBedTemp}
Preheat bed temperature
-
-
-
-
- GCODE settings - GCODE settings for Makerbots. -
-
- -
-
-
- -
- - The following texts are replaced: -
-
{printingTemp}
Printing temperature
-
{printingBedTemp}
Printing bed temperature
-
{preheatTemp}
Preheat temperature
-
{preheatBedTemp}
Preheat bed temperature
-
{printerType}
Printer type
-
-
-
Debug From ff397700b7556620669d93a6bad36fb2e83ec88f Mon Sep 17 00:00:00 2001 From: peteruithoven Date: Wed, 4 Dec 2013 13:42:37 +0100 Subject: [PATCH 05/15] Made gcodePanel collapsible using coolfieldset --- js_src/PrinterPanel.js | 3 ++ js_src/libs/jquery-coolfieldset.js | 57 +++++++++++++++++++++++++++++ www/css/settings.css | 24 ++++++++++++ www/img/buttons/collapsed.gif | Bin 0 -> 106 bytes www/img/buttons/expanded.gif | Bin 0 -> 107 bytes www/index.html | 1 + www/settings.html | 36 +++++++++--------- 7 files changed, 104 insertions(+), 17 deletions(-) create mode 100644 js_src/libs/jquery-coolfieldset.js create mode 100644 www/img/buttons/collapsed.gif create mode 100644 www/img/buttons/expanded.gif diff --git a/js_src/PrinterPanel.js b/js_src/PrinterPanel.js index 0e50997..00663cc 100644 --- a/js_src/PrinterPanel.js +++ b/js_src/PrinterPanel.js @@ -23,6 +23,9 @@ function PrinterPanel() { formElements.each( function(index,element) { self.printerSettingsNames.push(element.name); }); + + var gcodePanel = element.find("#gcodePanel"); + gcodePanel.coolfieldset({collapsed:true}); } this.printerSelectorChanged = function(e) { console.log("PrinterPanel:printerSelectorChanged"); diff --git a/js_src/libs/jquery-coolfieldset.js b/js_src/libs/jquery-coolfieldset.js new file mode 100644 index 0000000..d0976a5 --- /dev/null +++ b/js_src/libs/jquery-coolfieldset.js @@ -0,0 +1,57 @@ +/** + * jQuery Plugin for creating collapsible fieldset + * @requires jQuery 1.2 or later + * + * Copyright (c) 2010 Lucky + * Licensed under the GPL license: + * http://www.gnu.org/licenses/gpl.html + * + * "animation" and "speed" options are added by Mitch Kuppinger + */ + +(function($) { + function hideFieldsetContent(obj, options){ + if(options.animation==true) + obj.find('div').slideUp(options.speed); + else + obj.find('div').hide(); + + obj.removeClass("expanded"); + obj.addClass("collapsed"); + } + + function showFieldsetContent(obj, options){ + if(options.animation==true) + obj.find('div').slideDown(options.speed); + else + obj.find('div').show(); + + obj.removeClass("collapsed"); + obj.addClass("expanded"); + } + + $.fn.coolfieldset = function(options){ + var setting={collapsed:false, animation:true, speed:'medium'}; + $.extend(setting, options); + + this.each(function(){ + var fieldset=$(this); + fieldset.addClass("collapsible"); + var legend=fieldset.children('legend'); + + if(setting.collapsed==true){ + hideFieldsetContent(fieldset, setting); + } else { + showFieldsetContent(fieldset, setting); + } + + legend.bind('touchstart mousedown', function() { + if(fieldset.hasClass("collapsed")) { + showFieldsetContent(fieldset, setting); + } else { + hideFieldsetContent(fieldset, setting); + } + }); + }); + } +})(jQuery); \ No newline at end of file diff --git a/www/css/settings.css b/www/css/settings.css index cf5d48a..8e80f71 100644 --- a/www/css/settings.css +++ b/www/css/settings.css @@ -35,10 +35,34 @@ form fieldset fieldset{ clear: left; float: left; } +form fieldset.collapsed { + border-radius: 0; + -webkit-border-radius: 0; + -moz-border-radius: 0; + border-width: 1px 0 0 0; + float:none; +} +form fieldset.collapsible { + padding: 0; +} +form fieldset.collapsible div{ + margin: 8px; +} form fieldset legend { margin-left: 10px; font-weight: bold; } +form fieldset.collapsible legend { + padding-left: 10px; + cursor: pointer; +} +form fieldset.expanded legend { + background: transparent url(../img/buttons/expanded.gif) no-repeat center left; +} +form fieldset.collapsed legend { + background: transparent url(../img/buttons/collapsed.gif) no-repeat center left; +} + form label { min-width: 150px; display: block; diff --git a/www/img/buttons/collapsed.gif b/www/img/buttons/collapsed.gif new file mode 100644 index 0000000000000000000000000000000000000000..108ff044e9623718c005b653b5046a4d947f1f1b GIT binary patch literal 106 zcmZ?wbhEHb-X>9@8IC@|NnoG90pMQ$->A0 n)T#rL0hz(TA}+w`qRo_ggPUoi1BVQoYM<)!#+zojf(+IGAN(2z literal 0 HcmV?d00001 diff --git a/www/img/buttons/expanded.gif b/www/img/buttons/expanded.gif new file mode 100644 index 0000000000000000000000000000000000000000..f520c08d400427536999d6de056be910c955b501 GIT binary patch literal 107 zcmZ?wbhEHbNJv<}etmy`e?dWkfPldM{rm6VzptR6aQ^)H z|NsAk)PaHGPZmZ71|9|-5D#Pq1B=9jlbW16!aW-qCvmF<9G)6*FfkxVa6--> + diff --git a/www/settings.html b/www/settings.html index a4323c7..666c10e 100644 --- a/www/settings.html +++ b/www/settings.html @@ -54,24 +54,26 @@ mm
GCODE settings -
-
- -
-
-
- +
+
+
+ +
+
+
+ +
+ + The following texts are replaced: +
+
{printingTemp}
Printing temperature
+
{printingBedTemp}
Printing bed temperature
+
{preheatTemp}
Preheat temperature
+
{preheatBedTemp}
Preheat bed temperature
+
{printerType}
Printer type
+
+
- - The following texts are replaced: -
-
{printingTemp}
Printing temperature
-
{printingBedTemp}
Printing bed temperature
-
{preheatTemp}
Preheat temperature
-
{preheatBedTemp}
Preheat bed temperature
-
{printerType}
Printer type
-
-
From dd6c1d8034bc289a02caecac8257ede9bfab3dcc Mon Sep 17 00:00:00 2001 From: peteruithoven Date: Wed, 4 Dec 2013 14:56:17 +0100 Subject: [PATCH 06/15] Added Ultimaker2 --- www/settings.html | 1 + 1 file changed, 1 insertion(+) diff --git a/www/settings.html b/www/settings.html index 666c10e..37e38d9 100644 --- a/www/settings.html +++ b/www/settings.html @@ -18,6 +18,7 @@ + +
@@ -135,6 +136,7 @@ + diff --git a/www/settings.html b/www/settings.html index 37e38d9..d738b77 100644 --- a/www/settings.html +++ b/www/settings.html @@ -160,6 +160,7 @@
Debug +
Restore From ff6df2f041c5f184e6b1bf8359afe326e6c04c3b Mon Sep 17 00:00:00 2001 From: Rick Companje Date: Thu, 5 Dec 2013 11:50:02 +0100 Subject: [PATCH 08/15] some extra keyboard shortcuts --- js_src/Keyboard.js | 8 ++++++-- js_src/gcodeGenerating.js | 2 ++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/js_src/Keyboard.js b/js_src/Keyboard.js index 67e936d..cef211c 100644 --- a/js_src/Keyboard.js +++ b/js_src/Keyboard.js @@ -10,6 +10,7 @@ function initKeyboard() { switch (ch) { case 'c': clearDoodle(); break; + case 'n': clearDoodle(); break; case 'p': print(); break; case 'u': oopsUndo(); break; case 'e': settingsWindow.downloadGcode(); break; @@ -18,8 +19,11 @@ function initKeyboard() { case 'C': drawCircle(250,180,80,64); break; //x,y,r,res case 'T': drawCircle(250,180,80,3); break; //triangle case 'X': drawCircle(250,180,80,6); break; //hexagon - case 'H': previewUp(true); break; - case 'h': previewDown(true); break; + case 'h': previewUp(true); break; + case 'H': previewDown(true); break; + case 's': saveSketch(); break; + case 'L': nextDoodle(); break; + case 'l': prevDoodle(); break; case '[': previewTwistLeft(); break; case ']': previewTwistRight(); break; case '\'': resetTwist(); break; diff --git a/js_src/gcodeGenerating.js b/js_src/gcodeGenerating.js index 7afaa21..35eab62 100644 --- a/js_src/gcodeGenerating.js +++ b/js_src/gcodeGenerating.js @@ -145,6 +145,8 @@ function generate_gcode() { for (var layer = 0; layer < layers; layer++) { + gcode.push(";LAYER:"+layer); + var p = JSON.parse(JSON.stringify(points)); // [].concat(points); if (p.length < 2) return; From 4799a7e95e663a5f28df920fd5fbf93e29a0c849 Mon Sep 17 00:00:00 2001 From: Rick Companje Date: Thu, 5 Dec 2013 12:47:03 +0100 Subject: [PATCH 09/15] made preview_tmp hidden in debugMode --- js_src/main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js_src/main.js b/js_src/main.js index 8b4c086..f3347d5 100644 --- a/js_src/main.js +++ b/js_src/main.js @@ -76,7 +76,7 @@ $(function() { console.log("debug mode is true"); $("body").css("overflow", "auto"); $("#debug_textArea").css("display", "block"); - $("#preview_tmp").css("display", "block"); + //$("#preview_tmp").css("display", "block"); $("#debug_display").css("display", "block"); From c3fa844966fee10e5aebbacda7e362786a59d66c Mon Sep 17 00:00:00 2001 From: peteruithoven Date: Thu, 5 Dec 2013 16:37:10 +0100 Subject: [PATCH 10/15] Added makerbot_replicator2x --- js_src/gcodeGenerating.js | 3 ++- www/settings.html | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/js_src/gcodeGenerating.js b/js_src/gcodeGenerating.js index 35eab62..08f7808 100644 --- a/js_src/gcodeGenerating.js +++ b/js_src/gcodeGenerating.js @@ -284,7 +284,8 @@ function subsituteVariables(gcode) { var printerType = settings["printer.type"]; switch (printerType) { - case "makerbot_replicator2": printerType = "r2x"; break; //FIXME: this should be r2, with a separate type for r2x + case "makerbot_replicator2": printerType = "r2"; break; + case "makerbot_replicator2x": printerType = "r2x"; break; case "makerbot_thingomatic": printerType = "t6"; break; case "makerbot_generic": printerType = "r2"; break; } diff --git a/www/settings.html b/www/settings.html index d738b77..0e5ba3a 100644 --- a/www/settings.html +++ b/www/settings.html @@ -20,6 +20,7 @@ + From 2edba7a4c923c1858ee672bf65c0b7b6e3405c0d Mon Sep 17 00:00:00 2001 From: Rick Companje Date: Thu, 5 Dec 2013 17:32:29 +0100 Subject: [PATCH 11/15] SettingsWindow printerType dropdown is now populated by API call --- js_src/SettingsWindow.js | 191 +++++++++++++------------- js_src/gcodeGenerating.js | 110 ++------------- js_src/libs/jquery-coolfieldset.js | 3 +- js_src/main.js | 5 +- www/img/buttons/btnOk.png | Bin 5198 -> 12653 bytes www/img/buttons/btnOk_settings.png | Bin 3568 -> 0 bytes www/img/buttons/btnReset_settings.png | Bin 7564 -> 0 bytes www/index.html | 2 +- www/settings.html | 21 ++- 9 files changed, 129 insertions(+), 203 deletions(-) delete mode 100644 www/img/buttons/btnOk_settings.png delete mode 100644 www/img/buttons/btnReset_settings.png diff --git a/js_src/SettingsWindow.js b/js_src/SettingsWindow.js index 02f420d..f38c8b4 100644 --- a/js_src/SettingsWindow.js +++ b/js_src/SettingsWindow.js @@ -1,30 +1,5 @@ //these settings are defined in the firmware (conf_defaults.lua) and will be initialized in loadSettings() -var settings = { -"network.ap.ssid": "d3d-ap-%%MAC_ADDR_TAIL%%", -"network.ap.address": "192.168.10.1", -"network.ap.netmask": "255.255.255.0", -"printer.temperature": 220, -"printer.maxObjectHeight": 150, -"printer.layerHeight": 0.2, -"printer.wallThickness": 0.7, -"printer.screenToMillimeterScale": 0.3, -"printer.speed": 50, -"printer.travelSpeed": 200, -"printer.filamentThickness": 2.85, -"printer.enableTraveling": true, -"printer.useSubLayers": true, -"printer.firstLayerSlow": true, -"printer.autoWarmUp": true, -"printer.simplify.iterations": 10, -"printer.simplify.minNumPoints": 15, -"printer.simplify.minDistance": 3, -"printer.retraction.enabled": true, -"printer.retraction.speed": 50, -"printer.retraction.minDistance": 1, -"printer.retraction.amount": 5, -"printer.autoWarmUpCommand": "M104 S220 (hardcoded temperature)" -} - +var settings = { } //wrapper to prevent scoping issues in showSettings() function openSettingsWindow() { @@ -45,52 +20,52 @@ function SettingsWindow() { this.retrySaveSettingsDelay; // retry setTimout instance this.retryResetSettingsDelay // retry setTimout instance this.retryRetrieveNetworkStatusDelay;// retry setTimout instance - + this.apFieldSet; this.clientFieldSet; this.networks; 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.currentLocalIP = ""; - this.clientModeState = SettingsWindow.NOT_CONNECTED; - this.currentAP; - this.apModeState = SettingsWindow.NO_AP; + this.selectedNetwork; // the ssid of the selected network in the client mode settings + this.currentLocalIP = ""; + this.clientModeState = SettingsWindow.NOT_CONNECTED; + this.currentAP; + this.apModeState = SettingsWindow.NO_AP; - // after switching wifi network or creating a access point we delay the status retrieval - // because the webserver needs time to switch - this.retrieveNetworkStatusDelay; // setTimout delay - this.retrieveNetworkStatusDelayTime = 1000; + // after switching wifi network or creating a access point we delay the status retrieval + // because the webserver needs time to switch + this.retrieveNetworkStatusDelay; // setTimout delay + this.retrieveNetworkStatusDelayTime = 1000; // Events SettingsWindow.SETTINGS_LOADED = "settingsLoaded"; - // network client mode states - SettingsWindow.NOT_CONNECTED = "not connected"; // also used as first item in networks list - SettingsWindow.CONNECTED = "connected"; - SettingsWindow.CONNECTING = "connecting"; - SettingsWindow.CONNECTING_FAILED = "connecting failed" + // network client mode states + SettingsWindow.NOT_CONNECTED = "not connected"; // also used as first item in networks list + SettingsWindow.CONNECTED = "connected"; + SettingsWindow.CONNECTING = "connecting"; + SettingsWindow.CONNECTING_FAILED = "connecting failed" - // network access point mode states - SettingsWindow.NO_AP = "no ap"; - SettingsWindow.AP = "ap"; - SettingsWindow.CREATING_AP = "creating ap"; + // network access point mode states + SettingsWindow.NO_AP = "no ap"; + SettingsWindow.AP = "ap"; + SettingsWindow.CREATING_AP = "creating ap"; - SettingsWindow.API_CONNECTING_FAILED = -1 - SettingsWindow.API_NOT_CONNECTED = 0 - SettingsWindow.API_CONNECTING = 1 - SettingsWindow.API_CONNECTED = 2 - SettingsWindow.API_CREATING = 3 - SettingsWindow.API_CREATED = 4 + SettingsWindow.API_CONNECTING_FAILED = -1 + SettingsWindow.API_NOT_CONNECTED = 0 + SettingsWindow.API_CONNECTING = 1 + SettingsWindow.API_CONNECTED = 2 + SettingsWindow.API_CREATING = 3 + SettingsWindow.API_CREATED = 4 - // network mode - SettingsWindow.NETWORK_MODE_NEITHER = "neither"; - SettingsWindow.NETWORK_MODE_CLIENT = "clientMode"; - SettingsWindow.NETWORK_MODE_ACCESS_POINT = "accessPointMode"; + // network mode + SettingsWindow.NETWORK_MODE_NEITHER = "neither"; + SettingsWindow.NETWORK_MODE_CLIENT = "clientMode"; + SettingsWindow.NETWORK_MODE_ACCESS_POINT = "accessPointMode"; - this.networkMode = SettingsWindow.NETWORK_MODE_NEITHER; + this.networkMode = SettingsWindow.NETWORK_MODE_NEITHER; - this.updatePanel = new UpdatePanel(); - this.printerPanel = new PrinterPanel(); + this.updatePanel = new UpdatePanel(); + this.printerPanel = new PrinterPanel(); var self = this; @@ -101,45 +76,61 @@ function SettingsWindow() { this.window = $("#settings"); this.btnOK = this.window.find(".btnOK"); enableButton(this.btnOK,this.submitwindow); - - this.window.find(".settingsContainer").load("settings.html", function() { - console.log("Settings:finished loading settings.html, now loading settings..."); - self.form = self.window.find("form"); + this.window.find(".settingsContainer").load("settings.html", function() { + console.log("Settings:finished loading settings.html, now loading settings..."); + + self.form = self.window.find("form"); self.form.submit(function (e) { self.submitwindow(e) }); - self.loadSettings(); - - - var btnAP = self.form.find("label[for='ap']"); - var btnClient = self.form.find("label[for='client']"); - var btnRefresh = self.form.find("#refreshNetworks"); - var btnConnect = self.form.find("#connectToNetwork"); - var btnCreate = self.form.find("#createAP"); - var networkSelector = self.form.find("#network"); - self.apFieldSet = self.form.find("#apSettings"); - self.clientFieldSet = self.form.find("#clientSettings"); - self.btnRestoreSettings = self.form.find("#restoreSettings"); - - btnAP.on('touchstart mousedown',self.showAPSettings); - btnClient.on('touchstart mousedown',self.showClientSettings); - btnRefresh.on('touchstart mousedown',self.refreshNetworks); - btnConnect.on('touchstart mousedown',self.connectToNetwork); - btnCreate.on('touchstart mousedown',self.createAP); - networkSelector.change(self.networkSelectorChanged); - self.btnRestoreSettings.on('touchstart mousedown',self.resetSettings); - - // update panel - var $updatePanelElement = self.form.find("#updatePanel"); - self.updatePanel.init(wifiboxURL,$updatePanelElement); - - // printer panel - var $printerPanelElement = self.form.find("#printerPanel"); - self.printerPanel.init(wifiboxURL,$printerPanelElement); - self.printerPanel.fillForm = self.fillForm; - - }); - } + $.ajax({ + url: self.wifiboxURL + "/printer/listall", + dataType: 'json', + timeout: self.timeoutTime, + success: function(response) { + console.log("Settings:printer/listall response: ",response.data.printers); + + $.each(response.data.printers, function(key, value) { + // console.log(key,value); + $('#printerType').append($('