0
0
mirror of https://github.com/Doodle3D/doodle3d-client.git synced 2024-11-21 17:07:55 +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;
}
.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/d3d_btns.css" rel="stylesheet" media="screen">
<link href="css/settingsPopup.css" rel="stylesheet" media="screen">
<style type="text/css">
.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>
<link href="css/debug.css" rel="stylesheet" media="screen">
</head>
<body>
<div class="debugContainer">
@ -72,7 +37,7 @@
<img class="btn" id="btnSave" src="img/buttons/btnSave.png">
<div class="btn" id="btnOops"></div>
<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="btnSettings" src="img/buttons/btnSettings.png">
</div>
@ -129,5 +94,6 @@
<script src="js/Printer.js"></script>
<!--<script src="js/draw_logic.js"></script>-->
<script src="js/main.js"></script>
</body>
</html>

View File

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

View File

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

View File

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

View File

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

View File

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