mirror of
https://github.com/Doodle3D/doodle3d-client.git
synced 2024-11-21 17:07:55 +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:
parent
4f080ef1e4
commit
6df5e255c2
@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
48
index.html
48
index.html
@ -74,6 +74,7 @@
|
||||
<img class="btn" id="btnInfo" src="img/buttons/btnInfo.png">
|
||||
<img class="btn" id="btnSettings" src="img/buttons/btnSettings.png">
|
||||
</div>
|
||||
<div id="displayTemp"></div>
|
||||
</div>
|
||||
<div id="drawAreaContainer">
|
||||
<canvas id="mycanvas"></canvas>
|
||||
@ -126,51 +127,8 @@
|
||||
<script src="js/doodlePrintCode.js"></script>
|
||||
<script src="js/gcodeGenerating_v01.js"></script>
|
||||
<script src="js/init_layout.js"></script>
|
||||
<script src="js/Printer.js"></script>
|
||||
<!--<script src="js/draw_logic.js"></script>-->
|
||||
<script type="text/javascript">
|
||||
|
||||
// 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>
|
||||
<script src="js/main.js"></script>
|
||||
</body>
|
||||
</html>
|
79
js/Printer.js
Normal file
79
js/Printer.js
Normal 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);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
@ -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;
|
||||
|
||||
|
51
js/main.js
Normal file
51
js/main.js
Normal 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();
|
||||
|
||||
})
|
@ -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;
|
||||
|
36
proxy.php
Normal file
36
proxy.php
Normal 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');
|
||||
?>
|
Loading…
Reference in New Issue
Block a user