diff --git a/css/d3d_btns.css b/css/d3d_btns.css index 6d6b7a9..f8bc72c 100644 --- a/css/d3d_btns.css +++ b/css/d3d_btns.css @@ -158,5 +158,11 @@ img { display:none; } +.disabled { + opacity: 0.3; + cursor: default; +} - +#btnStop.disabled { + display: none; +} \ No newline at end of file diff --git a/css/debug.css b/css/debug.css new file mode 100644 index 0000000..7aeaa36 --- /dev/null +++ b/css/debug.css @@ -0,0 +1,33 @@ +.debugContainer { + position: absolute; + top: 0px; + left: 0px; + z-index: 500; + display: none; +} + +#debug_textArea { + position:absolute; + bottom: 0; + width: 800px; + display: none; +} + +.debugBtn { + width: 25px; + height: 25px; + background-color: #03b; + float:left; +} + +.agentInfo { + background: #fff; + border: 1px #333 solid; + display: none; + float:left; + opacity: .7; +} + +.agentInfoToggle { + display: block; +} \ No newline at end of file diff --git a/index.html b/index.html index 8a444e4..b9f8334 100755 --- a/index.html +++ b/index.html @@ -15,43 +15,8 @@ - + +
@@ -72,7 +37,7 @@
- +
@@ -129,5 +94,6 @@ + \ No newline at end of file diff --git a/js/Printer.js b/js/Printer.js index c42f95c..1888c19 100644 --- a/js/Printer.js +++ b/js/Printer.js @@ -4,11 +4,16 @@ function Printer() { this.wifiboxURL; - this.checkTemperatureIntervalTime = 1000; - this.checkTemperatureInterval; - this.maxTempLastMod = 5; // max time (seconds) since the last temp info modification before the printer connection is considered lost + + + this.checkTemperatureInterval = 3000; + this.checkTemperatureDelay; + this.checkProgressInterval = 3000; + this.checkProgressDelay; + this.timeoutTime = 3000; + // Events Printer.UPDATE = "update"; @@ -20,8 +25,8 @@ function Printer() { //this.wifiboxURL = "proxy5.php"; console.log(" wifiboxURL: ",this.wifiboxURL); - var self = this; - this.checkTemperatureInterval = setInterval(function() { self.checkTemperature(); },this.checkTemperatureIntervalTime); + this.checkTemperature(); + this.checkProgress(); } this.preheat = function() { @@ -50,30 +55,74 @@ function Printer() { this.checkTemperature = function() { //console.log("Printer:checkTemperature"); - var getData = { id: 0 }; - var self = this; - $.get( this.wifiboxURL + "/printer/temperature", getData , function(e) { - //console.log("Printer:temperature response: " + e); - - if (e.success = true) { - var response = jQuery.parseJSON(e); - //console.log("response: ",response); - - if(response.status == "success") { + var getData = { id: 0 }; + var self = this; + $.ajax({ + url: this.wifiboxURL + "/printer/temperature", + data: getData, + dataType: 'json', + timeout: this.timeoutTime, + success: function(data){ + //console.log("Printer:temperature response: ",data); + if(data.status == "success") { //console.log("temp: ",response.data.hotend+"/"+response.data.hotend_target+" ("+response.data.last_mod+")"); - - self.temperature = response.data.hotend; - if(response.data.hotend_target != undefined) { - self.targetTemperature = response.data.hotend_target; + self.temperature = data.data.hotend; + if(data.data.hotend_target != undefined) { + self.targetTemperature = data.data.hotend_target; } - - self.alive = (response.data.last_mod < self.maxTempLastMod); + self.alive = (data.data.last_mod < self.maxTempLastMod); } else { self.alive = false; } //console.log(" this.alive: ",self.alive); $(document).trigger(Printer.UPDATE); - } - }); + + self.checkTemperatureDelay = setTimeout(function() { self.checkTemperature() },self.checkTemperatureInterval); + }, + error: function(jqXHR, status, errorThrown){ //the status returned will be "timeout" + //console.log("Printer:temperature error. Status: ",status,' errorThrown: ',errorThrown); + switch(status) { + case 'timeout': + self.checkTemperature(); + break; + } + } + }); + } + this.checkProgress = function() { + //console.log("Printer:checkProgress"); + var getData = { id: 0 }; + var self = this; + $.ajax({ + url: this.wifiboxURL + "/printer/progress", + data: getData, + dataType: 'json', + timeout: this.timeoutTime, + success: function(data){ + if(data.status == "success") { + + self.printing = data.data.printing; + self.currentLine = data.data.current_line; + self.num_lines = data.data.num_lines; + + if(self.printing) { + console.log("progress: ",data.data.current_line+"/"+data.data.num_lines+" ("+data.data.last_mod+")"); + } + } + //console.log(" this.alive: ",self.alive); + $(document).trigger(Printer.UPDATE); + + self.checkProgressDelay = setTimeout(function() { self.checkProgress() },self.checkProgressInterval); + }, + error: function(jqXHR, status, errorThrown){ //the status returned will be "timeout" + //console.log("Printer:progress error. Status: ",status,' errorThrown: ',errorThrown); + switch(status) { + case 'timeout': + self.checkProgress(); + break; + } + } + }); + } } \ No newline at end of file diff --git a/js/buttonbehaviors.js b/js/buttonbehaviors.js index 9c40981..b8a2fcc 100644 --- a/js/buttonbehaviors.js +++ b/js/buttonbehaviors.js @@ -7,7 +7,7 @@ var twistIncrement = Math.PI/1800; var btnOopsInterval; -//var btnNew, btnPrevious, btnNext; +var btnNew, btnPrevious, btnNext; var btnOops, btnStop, btnClear; var btnMoveUp, btnMoveDown, btnTwistLeft, btnTwistRight; var btnInfo, btnSettings; @@ -15,6 +15,12 @@ var btnDebug; // debug var displayTempEnabled = false; +var IDLE_STATE = "idle"; +var PRINTING_STATE = "printing"; + +var state = IDLE_STATE; +var prevState = state; + function initButtonBehavior() { console.log("f:initButtonBehavior >> btnNew = " + btnNew); @@ -26,7 +32,8 @@ function initButtonBehavior() { btnTwistRight = $("#btnTwistRight"); btnInfo = $("#btnInfo"); btnSettings = $("#btnSettings"); -// btnPrint= $("#btnPrint"); + btnNew = $("#btnNew"); + btnPrint= $("#btnPrint"); btnStop = $("#btnStop"); displayTemp = $("#displayTemp"); @@ -36,7 +43,7 @@ function initButtonBehavior() { //debug btnDebug = $(".debugBtn"); - if (!btnNew.addEventListener) { + /*if (!btnNew.addEventListener) { btnNew.attachEvent('onmousedown',clearDoodle); btnNew.attachEvent('ontouchstart',clearDoodle); btnPrint.attachEvent('onmousedown',print); @@ -56,7 +63,16 @@ function initButtonBehavior() { // btnPrevious.addEventListener('touchstart',prevDoodle,false); // btnNext.addEventListener('mousedown',nextDoodle,false); // btnNext.addEventListener('touchstart',nextDoodle,false); - } + }*/ + + btnNew.bind('touchstart mousedown',clearDoodle); + btnPrint.bind('touchstart mousedown',print); + + // not using these at the moment + $("#btnPrevious").css("opacity", "0.3"); + $("#btnNext").css("opacity", "0.3"); + $("#btnSave").css("opacity", "0.3"); + $("#btnInfo").css("opacity", "0.3"); btnClear.click(function(e) { e.preventDefault(); @@ -175,16 +191,15 @@ function initButtonBehavior() { btnTwistRight.on('touchstart', function(e) { startTwistRight(e) }); btnTwistRight.on('touchend', function(e) { stopTwistRight(e) }); - function openSettings() { + /*function openSettings() { console.log("f:openSettings()"); $("#contentOverlay").fadeIn(1000, function() { loadSettings(); }); - - } - btnSettings.click(function(e) { - e.preventDefault(); - console.log("btnSettings clicked"); + }*/ + btnSettings.bind('touchstart mousedown',function () { + //e.preventDefault(); + //console.log("btnSettings clicked"); showSettings(); }); // btnSettings.on('touchend', function(e) { @@ -197,8 +212,6 @@ function initButtonBehavior() { console.log("btnInfo mouse up"); }); - - // DEBUG // $(".agentInfo").css("display", "none"); btnDebug.click(function(e) { @@ -206,10 +219,11 @@ function initButtonBehavior() { $(".agentInfo").toggleClass("agentInfoToggle"); e.preventDefault(); }) - - btnStop.click(function(e) { - printer.stop() - }); + + btnStop.bind('touchstart mousedown',stopPrint); +} +function stopPrint() { + printer.stop(); } @@ -225,6 +239,8 @@ function print(e) { $("#textdump").text(""); if (_points.length > 2) { + + setState(PRINTING_STATE); var gencode = generate_gcode(); startPrint(gencode); @@ -302,7 +318,7 @@ function previewTwistRight() { -function updatePrinterInfo() { +function update() { if(!displayTempEnabled && printer.alive) { displayTemp.show(); displayTempEnabled = true; @@ -314,4 +330,34 @@ function updatePrinterInfo() { if(displayTempEnabled) { displayTemp.text(printer.temperature+"/"+printer.targetTemperature); } + + var btnPrint= $("#btnPrint"); + + setState(printer.printing? PRINTING_STATE : IDLE_STATE); +} + + +function setState(newState) { + if(newState == state) return; + + switch(newState) { + case IDLE_STATE: + + btnPrint.removeClass("disabled"); // enable print button + btnStop.addClass("disabled"); // disable stop button + btnPrint.bind('touchstart mousedown',print); + + break; + case PRINTING_STATE: + + btnPrint.addClass("disabled"); // disable print button + btnStop.removeClass("disabled"); // enable stop button + btnPrint.unbind('touchstart mousedown'); + + break; + } + + prevState = state; + state = newState; + } \ No newline at end of file diff --git a/js/gcodeGenerating_v01.js b/js/gcodeGenerating_v01.js index 3661137..a6b1bc7 100755 --- a/js/gcodeGenerating_v01.js +++ b/js/gcodeGenerating_v01.js @@ -6,8 +6,7 @@ gcodeStart.push("G1 E10 F250 (flow)"); gcodeStart.push("G92 X-100 Y-100 Z0 E10"); gcodeStart.push("G1 Z3 F5000 (prevent diagonal line)"); gcodeStart.push("G90 (absolute)"); -gcodeStart.push("M106 (fan on)"); - +//gcodeStart.push("M106 (fan on)"); var gcodeEnd= []; gcodeEnd.push("G1 X-100 Y-100 F15000 (fast homing)"); gcodeEnd.push("M107"); @@ -80,7 +79,7 @@ function generate_gcode(callback) { if (layer == 0) { gcode.push("M107"); //fan off - if (firstLayerSlow) gcode.push("M220 S40"); //slow speed + if (firstLayerSlow) gcode.push("M220 S20"); //slow speed } else if (layer == 2) { ////////LET OP, pas bij layer 2 weer op normale snelheid ipv layer 1 gcode.push("M106"); //fan on gcode.push("M220 S100"); //normal speed @@ -121,8 +120,6 @@ function generate_gcode(callback) { var sublayer = (layer == 0) ? 0.0 : layer + (useSubLayers ? (curLayerCommand/totalLayerCommands) : 0); var z = (sublayer + 1) * settings["printer.layerHeight"] + zOffset; - // TODO if (z > layerheight*2) do M106 (enable fan) - var isTraveling = !isLoop && i==0; var doRetract = prev.distance(to) > retractionminDistance; diff --git a/js/main.js b/js/main.js index 39f6143..11fe884 100644 --- a/js/main.js +++ b/js/main.js @@ -1,21 +1,18 @@ -// not using these at the moment -$("#btnPrevious").css("opacity", "0.3"); -$("#btnNext").css("opacity", "0.3"); -$("#btnSave").css("opacity", "0.3"); -$("#btnInfo").css("opacity", "0.3"); -//$("#btnSettings").css("opacity", "0.3"); - - var debug = true; +var debug = false; var printer = new Printer(); -var updateTemperatureInterval; + +var $canvas; +var canvas; +var $preview; +var preview; $(function() { console.log("ready"); //var wifiboxURL = "http://" + window.location.host + "/cgi-bin/d3dapi"; var wifiboxURL = "http://192.168.5.1/cgi-bin/d3dapi"; console.log("wifibox URL: " + wifiboxURL); - + initLayouting(); initDoodleDrawing(); @@ -39,13 +36,6 @@ $(function() { printer.init(); printer.preheat(); - $(document).on(Printer.UPDATE,updatePrinterInfo); -// $("#mycanvas").css("scale", 0.5); - - - - - //debug -// generate_gcode(); + $(document).on(Printer.UPDATE,update); }) \ No newline at end of file diff --git a/js/settings.js b/js/settings.js index d96f8de..e35ce1d 100644 --- a/js/settings.js +++ b/js/settings.js @@ -22,7 +22,7 @@ var settings = { "printer.retraction.speed": 250, "printer.retraction.minDistance": 1, "printer.retraction.amount": 2, -"printer.autoWarmUpCommand": "M104 S230 (hardcoded temperature)" +"printer.autoWarmUpCommand": "M104 S220 (hardcoded temperature)" } var settingsForm = $("#settingsForm");