From 6df5e255c2950eaa1cb45cb84ed93dafc648225c Mon Sep 17 00:00:00 2001 From: peteruithoven Date: Wed, 7 Aug 2013 20:47:47 +0200 Subject: [PATCH] Basic feedback and more control Display temperature Only show temperature when connected with printer Move index.html javascript to main.js stop button (Still having issues in firmware) OOP style printer control Added a proxy.php file to forward cross domain posts and get's. (should not be necessary) --- css/d3d_btns.css | 9 ++++- index.html | 48 ++---------------------- js/Printer.js | 79 +++++++++++++++++++++++++++++++++++++++ js/buttonbehaviors.js | 24 ++++++++++++ js/gcodeGenerating_v01.js | 2 + js/main.js | 51 +++++++++++++++++++++++++ js/settings.js | 2 +- proxy.php | 36 ++++++++++++++++++ 8 files changed, 204 insertions(+), 47 deletions(-) create mode 100644 js/Printer.js create mode 100644 js/main.js create mode 100644 proxy.php diff --git a/css/d3d_btns.css b/css/d3d_btns.css index e29816b..6d6b7a9 100644 --- a/css/d3d_btns.css +++ b/css/d3d_btns.css @@ -149,7 +149,14 @@ img { -webkit-user-select: none; cursor: hand; } - +#displayTemp { + position: absolute; + right: 55px; + top: 334px; + font-weight: bold; + background: white; + display:none; +} diff --git a/index.html b/index.html index 15df187..cdcf27d 100755 --- a/index.html +++ b/index.html @@ -74,6 +74,7 @@ +
@@ -126,51 +127,8 @@ + - + \ No newline at end of file diff --git a/js/Printer.js b/js/Printer.js new file mode 100644 index 0000000..c42f95c --- /dev/null +++ b/js/Printer.js @@ -0,0 +1,79 @@ +function Printer() { + this.temperature = 0; + this.targetTemperature = 0; + + 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 + + // Events + Printer.UPDATE = "update"; + + this.init = function() { + console.log("Printer:init"); + //this.wifiboxURL = "http://" + window.location.host + "/cgi-bin/d3dapi"; + //this.wifiboxURL = "http://192.168.5.1/cgi-bin/d3dapi"; + this.wifiboxURL = wifiboxURL; + //this.wifiboxURL = "proxy5.php"; + console.log(" wifiboxURL: ",this.wifiboxURL); + + var self = this; + this.checkTemperatureInterval = setInterval(function() { self.checkTemperature(); },this.checkTemperatureIntervalTime); + } + + this.preheat = function() { + console.log("Printer:preheat"); + var postData = { id: 0 }; + $.post( this.wifiboxURL + "/printer/heatup", postData , function(e) { + console.log("Printer:preheat response: " + e); + + if (e.success = true) { + console.log(" success"); + } + }); + } + + this.stop = function() { + console.log("Printer:stop"); + var postData = { id: 0 }; + $.post( this.wifiboxURL + "/printer/stop", postData , function(e) { + console.log("Printer:stop response: " + e); + + if (e.success = true) { + console.log(" success"); + } + }); + } + + 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") { + //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.alive = (response.data.last_mod < self.maxTempLastMod); + } else { + self.alive = false; + } + //console.log(" this.alive: ",self.alive); + $(document).trigger(Printer.UPDATE); + } + }); + } +} \ No newline at end of file diff --git a/js/buttonbehaviors.js b/js/buttonbehaviors.js index bdbe429..9c40981 100644 --- a/js/buttonbehaviors.js +++ b/js/buttonbehaviors.js @@ -13,6 +13,8 @@ var btnMoveUp, btnMoveDown, btnTwistLeft, btnTwistRight; var btnInfo, btnSettings; var btnDebug; // debug +var displayTempEnabled = false; + function initButtonBehavior() { console.log("f:initButtonBehavior >> btnNew = " + btnNew); @@ -25,6 +27,8 @@ function initButtonBehavior() { btnInfo = $("#btnInfo"); btnSettings = $("#btnSettings"); // btnPrint= $("#btnPrint"); + btnStop = $("#btnStop"); + displayTemp = $("#displayTemp"); // btnPrevious = $("#btnPrevious"); // btnNext = $("#btnNext"); @@ -202,6 +206,10 @@ function initButtonBehavior() { $(".agentInfo").toggleClass("agentInfoToggle"); e.preventDefault(); }) + + btnStop.click(function(e) { + printer.stop() + }); } @@ -290,4 +298,20 @@ function previewTwistRight() { rStep += twistIncrement; // } redrawPreview(); +} + + + +function updatePrinterInfo() { + if(!displayTempEnabled && printer.alive) { + displayTemp.show(); + displayTempEnabled = true; + } else if(displayTempEnabled && !printer.alive) { + displayTemp.hide(); + displayTempEnabled = false; + } + + if(displayTempEnabled) { + displayTemp.text(printer.temperature+"/"+printer.targetTemperature); + } } \ No newline at end of file diff --git a/js/gcodeGenerating_v01.js b/js/gcodeGenerating_v01.js index 82c68be..3661137 100755 --- a/js/gcodeGenerating_v01.js +++ b/js/gcodeGenerating_v01.js @@ -121,6 +121,8 @@ 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 new file mode 100644 index 0000000..49cb854 --- /dev/null +++ b/js/main.js @@ -0,0 +1,51 @@ +// 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 printer = new Printer(); +var updateTemperatureInterval; + +$(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(); + initPreviewRendering(); + + initButtonBehavior(); + + initSettingsPopup(wifiboxURL); + + $("#settings .settings").load("settings.html", function() { + console.log("finished loading settings.html, now loading settings..."); + loadSettings(); + }); + + if(debug) { + console.log("debug mode"); + $("body").css("overflow", "auto"); + $("#debug_textArea").css("display", "block"); + } + + printer.init(); + printer.preheat(); + + $(document).on(Printer.UPDATE,updatePrinterInfo); +// $("#mycanvas").css("scale", 0.5); + + + + + //debug +// generate_gcode(); + +}) \ No newline at end of file diff --git a/js/settings.js b/js/settings.js index 919468e..a863b16 100644 --- a/js/settings.js +++ b/js/settings.js @@ -185,5 +185,5 @@ var windowbounds = [0, 0, 800, 500]; var windowcenter = true; var windowfullscreen = false; var autoWarmUpCommand = "M104 S230"; -var checkTemperatureInterval = 3; +//var checkTemperatureInterval = 3; var autoWarmUpDelay = 3; diff --git a/proxy.php b/proxy.php new file mode 100644 index 0000000..2d78f74 --- /dev/null +++ b/proxy.php @@ -0,0 +1,36 @@ + 'application/xml')); +curl_setopt($c, CURLOPT_URL, $target_url); +curl_setopt($c, CURLOPT_POST, true); +curl_setopt($c, CURLOPT_POSTFIELDS,$postdata); +$result = curl_exec ($c); +curl_close ($c); +if(! +$result) +{ + $ok = false; + $error = "Failed to forward HTTP request to: {$target_url}\r\n" . var_export(error_get_last(),true) . "\r\n{$postdata}"; + error_log($error); + error_log($error, 1, "my-email-address@my-test-domain.com"); +} + +if(! +$ok) + header('HTTP/1.1 500 Internal Server Error'); +else + header('HTTP/1.1 200 OK'); +?> \ No newline at end of file