0
0
mirror of https://github.com/Doodle3D/doodle3d-client.git synced 2024-11-22 09:17:56 +01:00

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)
This commit is contained in:
peteruithoven 2013-08-07 20:47:47 +02:00
parent 4f080ef1e4
commit 6df5e255c2
8 changed files with 204 additions and 47 deletions

View File

@ -149,7 +149,14 @@ img {
-webkit-user-select: none; -webkit-user-select: none;
cursor: hand; cursor: hand;
} }
#displayTemp {
position: absolute;
right: 55px;
top: 334px;
font-weight: bold;
background: white;
display:none;
}

View File

@ -74,6 +74,7 @@
<img class="btn" id="btnInfo" src="img/buttons/btnInfo.png"> <img class="btn" id="btnInfo" src="img/buttons/btnInfo.png">
<img class="btn" id="btnSettings" src="img/buttons/btnSettings.png"> <img class="btn" id="btnSettings" src="img/buttons/btnSettings.png">
</div> </div>
<div id="displayTemp"></div>
</div> </div>
<div id="drawAreaContainer"> <div id="drawAreaContainer">
<canvas id="mycanvas"></canvas> <canvas id="mycanvas"></canvas>
@ -126,51 +127,8 @@
<script src="js/doodlePrintCode.js"></script> <script src="js/doodlePrintCode.js"></script>
<script src="js/gcodeGenerating_v01.js"></script> <script src="js/gcodeGenerating_v01.js"></script>
<script src="js/init_layout.js"></script> <script src="js/init_layout.js"></script>
<script src="js/Printer.js"></script>
<!--<script src="js/draw_logic.js"></script>--> <!--<script src="js/draw_logic.js"></script>-->
<script type="text/javascript"> <script src="js/main.js"></script>
// 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;
$(function() {
console.log("ready");
var wifiboxURL = "http://" + window.location.host + "/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");
}
// $("#mycanvas").css("scale", 0.5);
//debug
// generate_gcode();
})
</script>
</body> </body>
</html> </html>

79
js/Printer.js Normal file
View File

@ -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);
}
});
}
}

View File

@ -13,6 +13,8 @@ var btnMoveUp, btnMoveDown, btnTwistLeft, btnTwistRight;
var btnInfo, btnSettings; var btnInfo, btnSettings;
var btnDebug; // debug var btnDebug; // debug
var displayTempEnabled = false;
function initButtonBehavior() { function initButtonBehavior() {
console.log("f:initButtonBehavior >> btnNew = " + btnNew); console.log("f:initButtonBehavior >> btnNew = " + btnNew);
@ -25,6 +27,8 @@ function initButtonBehavior() {
btnInfo = $("#btnInfo"); btnInfo = $("#btnInfo");
btnSettings = $("#btnSettings"); btnSettings = $("#btnSettings");
// btnPrint= $("#btnPrint"); // btnPrint= $("#btnPrint");
btnStop = $("#btnStop");
displayTemp = $("#displayTemp");
// btnPrevious = $("#btnPrevious"); // btnPrevious = $("#btnPrevious");
// btnNext = $("#btnNext"); // btnNext = $("#btnNext");
@ -202,6 +206,10 @@ function initButtonBehavior() {
$(".agentInfo").toggleClass("agentInfoToggle"); $(".agentInfo").toggleClass("agentInfoToggle");
e.preventDefault(); e.preventDefault();
}) })
btnStop.click(function(e) {
printer.stop()
});
} }
@ -291,3 +299,19 @@ function previewTwistRight() {
// } // }
redrawPreview(); 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);
}
}

View File

@ -121,6 +121,8 @@ function generate_gcode(callback) {
var sublayer = (layer == 0) ? 0.0 : layer + (useSubLayers ? (curLayerCommand/totalLayerCommands) : 0); var sublayer = (layer == 0) ? 0.0 : layer + (useSubLayers ? (curLayerCommand/totalLayerCommands) : 0);
var z = (sublayer + 1) * settings["printer.layerHeight"] + zOffset; var z = (sublayer + 1) * settings["printer.layerHeight"] + zOffset;
// TODO if (z > layerheight*2) do M106 (enable fan)
var isTraveling = !isLoop && i==0; var isTraveling = !isLoop && i==0;
var doRetract = prev.distance(to) > retractionminDistance; var doRetract = prev.distance(to) > retractionminDistance;

51
js/main.js Normal file
View File

@ -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();
})

View File

@ -185,5 +185,5 @@ var windowbounds = [0, 0, 800, 500];
var windowcenter = true; var windowcenter = true;
var windowfullscreen = false; var windowfullscreen = false;
var autoWarmUpCommand = "M104 S230"; var autoWarmUpCommand = "M104 S230";
var checkTemperatureInterval = 3; //var checkTemperatureInterval = 3;
var autoWarmUpDelay = 3; var autoWarmUpDelay = 3;

36
proxy.php Normal file
View File

@ -0,0 +1,36 @@
<?php
/*$url = $_GET['url'];
if ( !$url ) {
$url = $_POST['url'];
}*/
$target_url = "http://192.168.5.1/cgi-bin/d3dapi/";
$target_api = str_replace("/proxy5.php/","",$_SERVER["REQUEST_URI"]);
$target_url .= $target_api;
//echo "target_url: ".$target_url;
$postdata = file_get_contents("php://input");
$ok = true;
$c = curl_init();
curl_setopt($c, CURLOPT_HTTPHEADER, array('Content-Type' => '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');
?>