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

Checking printing progress and disabling/enabling print and stop buttons

Cleaning up a bit of the mess
This commit is contained in:
peteruithoven 2013-08-09 22:25:14 +02:00
parent de8af029c5
commit 85d91a2f36
8 changed files with 190 additions and 103 deletions

View File

@ -158,5 +158,11 @@ img {
display:none; display:none;
} }
.disabled {
opacity: 0.3;
cursor: default;
}
#btnStop.disabled {
display: none;
}

33
css/debug.css Normal file
View File

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

View File

@ -15,43 +15,8 @@
<link href="css/fixedPosInterface.css" rel="stylesheet" media="screen"> <link href="css/fixedPosInterface.css" rel="stylesheet" media="screen">
<link href="css/d3d_btns.css" rel="stylesheet" media="screen"> <link href="css/d3d_btns.css" rel="stylesheet" media="screen">
<link href="css/settingsPopup.css" rel="stylesheet" media="screen"> <link href="css/settingsPopup.css" rel="stylesheet" media="screen">
<style type="text/css"> <link href="css/debug.css" rel="stylesheet" media="screen">
.debugContainer {
position: absolute;
top: 0px;
left: 0px;
z-index: 500;
display: none;
}
#debug_textArea {
position:absolute;
bottom: 0;
width: 800px;
}
.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;
}
</style>
</head> </head>
<body> <body>
<div class="debugContainer"> <div class="debugContainer">
@ -72,7 +37,7 @@
<img class="btn" id="btnSave" src="img/buttons/btnSave.png"> <img class="btn" id="btnSave" src="img/buttons/btnSave.png">
<div class="btn" id="btnOops"></div> <div class="btn" id="btnOops"></div>
<img class="btn" id="btnPrint" src="img/buttons/btnPrint.png"> <img class="btn" id="btnPrint" src="img/buttons/btnPrint.png">
<img class="btn" id="btnStop" src="img/buttons/btnStop.png"> <img class="btn disabled" id="btnStop" src="img/buttons/btnStop.png">
<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>
@ -129,5 +94,6 @@
<script src="js/Printer.js"></script> <script src="js/Printer.js"></script>
<!--<script src="js/draw_logic.js"></script>--> <!--<script src="js/draw_logic.js"></script>-->
<script src="js/main.js"></script> <script src="js/main.js"></script>
</body> </body>
</html> </html>

View File

@ -4,11 +4,16 @@ function Printer() {
this.wifiboxURL; 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.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 // Events
Printer.UPDATE = "update"; Printer.UPDATE = "update";
@ -20,8 +25,8 @@ function Printer() {
//this.wifiboxURL = "proxy5.php"; //this.wifiboxURL = "proxy5.php";
console.log(" wifiboxURL: ",this.wifiboxURL); console.log(" wifiboxURL: ",this.wifiboxURL);
var self = this; this.checkTemperature();
this.checkTemperatureInterval = setInterval(function() { self.checkTemperature(); },this.checkTemperatureIntervalTime); this.checkProgress();
} }
this.preheat = function() { this.preheat = function() {
@ -50,30 +55,74 @@ function Printer() {
this.checkTemperature = function() { this.checkTemperature = function() {
//console.log("Printer:checkTemperature"); //console.log("Printer:checkTemperature");
var getData = { id: 0 }; var getData = { id: 0 };
var self = this; var self = this;
$.get( this.wifiboxURL + "/printer/temperature", getData , function(e) { $.ajax({
//console.log("Printer:temperature response: " + e); url: this.wifiboxURL + "/printer/temperature",
data: getData,
if (e.success = true) { dataType: 'json',
var response = jQuery.parseJSON(e); timeout: this.timeoutTime,
//console.log("response: ",response); success: function(data){
//console.log("Printer:temperature response: ",data);
if(response.status == "success") { if(data.status == "success") {
//console.log("temp: ",response.data.hotend+"/"+response.data.hotend_target+" ("+response.data.last_mod+")"); //console.log("temp: ",response.data.hotend+"/"+response.data.hotend_target+" ("+response.data.last_mod+")");
self.temperature = data.data.hotend;
self.temperature = response.data.hotend; if(data.data.hotend_target != undefined) {
if(response.data.hotend_target != undefined) { self.targetTemperature = data.data.hotend_target;
self.targetTemperature = response.data.hotend_target;
} }
self.alive = (data.data.last_mod < self.maxTempLastMod);
self.alive = (response.data.last_mod < self.maxTempLastMod);
} else { } else {
self.alive = false; self.alive = false;
} }
//console.log(" this.alive: ",self.alive); //console.log(" this.alive: ",self.alive);
$(document).trigger(Printer.UPDATE); $(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;
}
}
});
} }
} }

View File

@ -7,7 +7,7 @@ var twistIncrement = Math.PI/1800;
var btnOopsInterval; var btnOopsInterval;
//var btnNew, btnPrevious, btnNext; var btnNew, btnPrevious, btnNext;
var btnOops, btnStop, btnClear; var btnOops, btnStop, btnClear;
var btnMoveUp, btnMoveDown, btnTwistLeft, btnTwistRight; var btnMoveUp, btnMoveDown, btnTwistLeft, btnTwistRight;
var btnInfo, btnSettings; var btnInfo, btnSettings;
@ -15,6 +15,12 @@ var btnDebug; // debug
var displayTempEnabled = false; var displayTempEnabled = false;
var IDLE_STATE = "idle";
var PRINTING_STATE = "printing";
var state = IDLE_STATE;
var prevState = state;
function initButtonBehavior() { function initButtonBehavior() {
console.log("f:initButtonBehavior >> btnNew = " + btnNew); console.log("f:initButtonBehavior >> btnNew = " + btnNew);
@ -26,7 +32,8 @@ function initButtonBehavior() {
btnTwistRight = $("#btnTwistRight"); btnTwistRight = $("#btnTwistRight");
btnInfo = $("#btnInfo"); btnInfo = $("#btnInfo");
btnSettings = $("#btnSettings"); btnSettings = $("#btnSettings");
// btnPrint= $("#btnPrint"); btnNew = $("#btnNew");
btnPrint= $("#btnPrint");
btnStop = $("#btnStop"); btnStop = $("#btnStop");
displayTemp = $("#displayTemp"); displayTemp = $("#displayTemp");
@ -36,7 +43,7 @@ function initButtonBehavior() {
//debug //debug
btnDebug = $(".debugBtn"); btnDebug = $(".debugBtn");
if (!btnNew.addEventListener) { /*if (!btnNew.addEventListener) {
btnNew.attachEvent('onmousedown',clearDoodle); btnNew.attachEvent('onmousedown',clearDoodle);
btnNew.attachEvent('ontouchstart',clearDoodle); btnNew.attachEvent('ontouchstart',clearDoodle);
btnPrint.attachEvent('onmousedown',print); btnPrint.attachEvent('onmousedown',print);
@ -56,7 +63,16 @@ function initButtonBehavior() {
// btnPrevious.addEventListener('touchstart',prevDoodle,false); // btnPrevious.addEventListener('touchstart',prevDoodle,false);
// btnNext.addEventListener('mousedown',nextDoodle,false); // btnNext.addEventListener('mousedown',nextDoodle,false);
// btnNext.addEventListener('touchstart',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) { btnClear.click(function(e) {
e.preventDefault(); e.preventDefault();
@ -175,16 +191,15 @@ function initButtonBehavior() {
btnTwistRight.on('touchstart', function(e) { startTwistRight(e) }); btnTwistRight.on('touchstart', function(e) { startTwistRight(e) });
btnTwistRight.on('touchend', function(e) { stopTwistRight(e) }); btnTwistRight.on('touchend', function(e) { stopTwistRight(e) });
function openSettings() { /*function openSettings() {
console.log("f:openSettings()"); console.log("f:openSettings()");
$("#contentOverlay").fadeIn(1000, function() { $("#contentOverlay").fadeIn(1000, function() {
loadSettings(); loadSettings();
}); });
}*/
} btnSettings.bind('touchstart mousedown',function () {
btnSettings.click(function(e) { //e.preventDefault();
e.preventDefault(); //console.log("btnSettings clicked");
console.log("btnSettings clicked");
showSettings(); showSettings();
}); });
// btnSettings.on('touchend', function(e) { // btnSettings.on('touchend', function(e) {
@ -197,8 +212,6 @@ function initButtonBehavior() {
console.log("btnInfo mouse up"); console.log("btnInfo mouse up");
}); });
// DEBUG // DEBUG
// $(".agentInfo").css("display", "none"); // $(".agentInfo").css("display", "none");
btnDebug.click(function(e) { btnDebug.click(function(e) {
@ -207,9 +220,10 @@ function initButtonBehavior() {
e.preventDefault(); e.preventDefault();
}) })
btnStop.click(function(e) { btnStop.bind('touchstart mousedown',stopPrint);
printer.stop() }
}); function stopPrint() {
printer.stop();
} }
@ -225,6 +239,8 @@ function print(e) {
$("#textdump").text(""); $("#textdump").text("");
if (_points.length > 2) { if (_points.length > 2) {
setState(PRINTING_STATE);
var gencode = generate_gcode(); var gencode = generate_gcode();
startPrint(gencode); startPrint(gencode);
@ -302,7 +318,7 @@ function previewTwistRight() {
function updatePrinterInfo() { function update() {
if(!displayTempEnabled && printer.alive) { if(!displayTempEnabled && printer.alive) {
displayTemp.show(); displayTemp.show();
displayTempEnabled = true; displayTempEnabled = true;
@ -314,4 +330,34 @@ function updatePrinterInfo() {
if(displayTempEnabled) { if(displayTempEnabled) {
displayTemp.text(printer.temperature+"/"+printer.targetTemperature); 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;
} }

View File

@ -6,8 +6,7 @@ gcodeStart.push("G1 E10 F250 (flow)");
gcodeStart.push("G92 X-100 Y-100 Z0 E10"); gcodeStart.push("G92 X-100 Y-100 Z0 E10");
gcodeStart.push("G1 Z3 F5000 (prevent diagonal line)"); gcodeStart.push("G1 Z3 F5000 (prevent diagonal line)");
gcodeStart.push("G90 (absolute)"); gcodeStart.push("G90 (absolute)");
gcodeStart.push("M106 (fan on)"); //gcodeStart.push("M106 (fan on)");
var gcodeEnd= []; var gcodeEnd= [];
gcodeEnd.push("G1 X-100 Y-100 F15000 (fast homing)"); gcodeEnd.push("G1 X-100 Y-100 F15000 (fast homing)");
gcodeEnd.push("M107"); gcodeEnd.push("M107");
@ -80,7 +79,7 @@ function generate_gcode(callback) {
if (layer == 0) { if (layer == 0) {
gcode.push("M107"); //fan off 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 } else if (layer == 2) { ////////LET OP, pas bij layer 2 weer op normale snelheid ipv layer 1
gcode.push("M106"); //fan on gcode.push("M106"); //fan on
gcode.push("M220 S100"); //normal speed 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 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;

View File

@ -1,14 +1,11 @@
// not using these at the moment var debug = false;
$("#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 printer = new Printer();
var updateTemperatureInterval;
var $canvas;
var canvas;
var $preview;
var preview;
$(function() { $(function() {
console.log("ready"); console.log("ready");
@ -39,13 +36,6 @@ $(function() {
printer.init(); printer.init();
printer.preheat(); printer.preheat();
$(document).on(Printer.UPDATE,updatePrinterInfo); $(document).on(Printer.UPDATE,update);
// $("#mycanvas").css("scale", 0.5);
//debug
// generate_gcode();
}) })

View File

@ -22,7 +22,7 @@ var settings = {
"printer.retraction.speed": 250, "printer.retraction.speed": 250,
"printer.retraction.minDistance": 1, "printer.retraction.minDistance": 1,
"printer.retraction.amount": 2, "printer.retraction.amount": 2,
"printer.autoWarmUpCommand": "M104 S230 (hardcoded temperature)" "printer.autoWarmUpCommand": "M104 S220 (hardcoded temperature)"
} }
var settingsForm = $("#settingsForm"); var settingsForm = $("#settingsForm");