2013-07-26 22:39:28 +02:00
|
|
|
var btnMoveUpInterval;
|
|
|
|
var btnMoveDownInterval;
|
|
|
|
|
|
|
|
var btnTwistLeftInterval;
|
|
|
|
var btnTwistRightInterval;
|
|
|
|
var twistIncrement = Math.PI/1800;
|
|
|
|
|
|
|
|
var btnOopsInterval;
|
|
|
|
|
2013-08-09 22:25:14 +02:00
|
|
|
var btnNew, btnPrevious, btnNext;
|
2013-07-26 22:39:28 +02:00
|
|
|
var btnOops, btnStop, btnClear;
|
|
|
|
var btnMoveUp, btnMoveDown, btnTwistLeft, btnTwistRight;
|
|
|
|
var btnInfo, btnSettings;
|
2013-10-11 11:42:27 +02:00
|
|
|
//var btnDebug; // debug
|
2013-07-26 22:39:28 +02:00
|
|
|
|
2013-10-11 12:39:05 +02:00
|
|
|
var state;
|
|
|
|
var prevState;
|
2013-10-11 16:17:58 +02:00
|
|
|
var hasControl;
|
2013-08-09 22:25:14 +02:00
|
|
|
|
2013-10-14 18:51:37 +02:00
|
|
|
var gcodeGenerateDelayer;
|
|
|
|
var gcodeGenerateDelay = 50;
|
|
|
|
|
2013-07-26 22:39:28 +02:00
|
|
|
function initButtonBehavior() {
|
2013-10-11 11:42:27 +02:00
|
|
|
console.log("f:initButtonBehavior");
|
2013-07-26 22:39:28 +02:00
|
|
|
|
2013-10-11 11:42:27 +02:00
|
|
|
// btnClear= $(".btnClear");
|
|
|
|
btnOops = $(".btnOops");
|
2013-07-26 22:39:28 +02:00
|
|
|
btnMoveUp = $("#btnMoveUp");
|
|
|
|
btnMoveDown = $("#btnMoveDown");
|
|
|
|
btnTwistLeft = $("#btnTwistLeft");
|
|
|
|
btnTwistRight = $("#btnTwistRight");
|
2013-10-11 11:42:27 +02:00
|
|
|
btnInfo = $(".btnInfo");
|
|
|
|
btnSettings = $(".btnSettings");
|
|
|
|
btnNew = $(".btnNew");
|
|
|
|
btnPrint= $(".btnPrint");
|
|
|
|
btnStop = $(".btnStop");
|
2013-07-26 22:39:28 +02:00
|
|
|
|
2013-10-11 11:42:27 +02:00
|
|
|
btnPrevious = $(".btnPrevious");
|
|
|
|
btnNext = $(".btnNext");
|
2013-07-26 22:39:28 +02:00
|
|
|
|
|
|
|
//debug
|
2013-10-11 11:42:27 +02:00
|
|
|
//btnDebug = $(".debugBtn");
|
2013-07-26 22:39:28 +02:00
|
|
|
|
2013-10-11 11:42:27 +02:00
|
|
|
btnNew.on('touchstart mousedown', clearDoodle);
|
|
|
|
btnPrint.on('touchstart mousedown', print);
|
2013-08-09 22:25:14 +02:00
|
|
|
|
|
|
|
// not using these at the moment
|
|
|
|
$("#btnPrevious").css("opacity", "0.3");
|
2013-10-11 11:42:27 +02:00
|
|
|
btnNext.css("opacity", "0.3");
|
2013-08-09 22:25:14 +02:00
|
|
|
$("#btnSave").css("opacity", "0.3");
|
2013-10-23 06:49:14 +02:00
|
|
|
// btnInfo.css("opacity", "0.3");
|
2013-07-26 22:39:28 +02:00
|
|
|
|
2013-10-11 11:42:27 +02:00
|
|
|
// btnClear.click(function(e) {
|
|
|
|
// e.preventDefault();
|
|
|
|
// // console.log("clear");
|
|
|
|
//
|
|
|
|
// clearDoodle();
|
|
|
|
// });
|
2013-07-26 22:39:28 +02:00
|
|
|
|
2013-07-27 18:19:50 +02:00
|
|
|
function startOops(e) {
|
2013-07-26 22:39:28 +02:00
|
|
|
// console.log("btnOops mouse down");
|
2013-07-27 18:19:50 +02:00
|
|
|
e.preventDefault();
|
2013-07-26 22:39:28 +02:00
|
|
|
btnOopsInterval = setInterval( function() {
|
|
|
|
oopsUndo();
|
|
|
|
}, 1000/50);
|
2013-07-27 18:19:50 +02:00
|
|
|
}
|
|
|
|
function stopOops(e) {
|
2013-07-26 22:39:28 +02:00
|
|
|
// console.log("btnOops mouse up");
|
2013-07-27 18:19:50 +02:00
|
|
|
e.preventDefault();
|
2013-07-26 22:39:28 +02:00
|
|
|
clearInterval(btnOopsInterval);
|
2013-07-27 18:19:50 +02:00
|
|
|
}
|
|
|
|
btnOops.on('touchstart', function(e) { startOops(e); });
|
|
|
|
btnOops.on('touchend', function(e) { stopOops(e); });
|
|
|
|
btnOops.mousedown(function(e) { startOops(e); });
|
|
|
|
btnOops.mouseup(function(e) { stopOops(e); });
|
2013-07-26 22:39:28 +02:00
|
|
|
|
2013-07-27 18:19:50 +02:00
|
|
|
function startMoveUp(e) {
|
2013-07-26 22:39:28 +02:00
|
|
|
e.preventDefault();
|
|
|
|
// console.log("btnMoveUp mouse down");
|
2013-08-16 22:27:26 +02:00
|
|
|
previewUp(true);
|
2013-07-26 22:39:28 +02:00
|
|
|
clearInterval(btnMoveUpInterval);
|
|
|
|
btnMoveUpInterval = setInterval( function() {
|
2013-08-16 22:27:26 +02:00
|
|
|
previewUp(true);
|
2013-07-26 22:39:28 +02:00
|
|
|
}, 1000/30);
|
2013-07-27 18:19:50 +02:00
|
|
|
}
|
|
|
|
function stopMoveUp(e) {
|
2013-07-26 22:39:28 +02:00
|
|
|
e.preventDefault();
|
2013-07-27 18:19:50 +02:00
|
|
|
console.log("btnMoveUp mouse up");
|
2013-07-26 22:39:28 +02:00
|
|
|
clearInterval(btnMoveUpInterval);
|
2013-08-16 22:27:26 +02:00
|
|
|
previewUp();
|
2013-07-27 18:19:50 +02:00
|
|
|
}
|
|
|
|
btnMoveUp.mousedown(function(e) { startMoveUp(e) });
|
|
|
|
btnMoveUp.mouseup(function(e) { stopMoveUp(e) });
|
|
|
|
btnMoveUp.on('touchstart', function(e) { startMoveUp(e) });
|
|
|
|
btnMoveUp.on('touchend', function(e) { stopMoveUp(e) });
|
2013-07-26 22:39:28 +02:00
|
|
|
|
2013-07-27 18:19:50 +02:00
|
|
|
function startMoveDown(e) {
|
2013-07-26 22:39:28 +02:00
|
|
|
e.preventDefault();
|
|
|
|
// console.log("btnMoveDown mouse down");
|
2013-08-16 22:27:26 +02:00
|
|
|
previewDown(true);
|
2013-07-26 22:39:28 +02:00
|
|
|
clearInterval(btnMoveDownInterval);
|
|
|
|
btnMoveDownInterval = setInterval( function() {
|
2013-08-16 22:27:26 +02:00
|
|
|
previewDown(true);
|
2013-07-26 22:39:28 +02:00
|
|
|
}, 1000/30);
|
2013-07-27 18:19:50 +02:00
|
|
|
}
|
|
|
|
function stopMoveDown(e) {
|
2013-07-26 22:39:28 +02:00
|
|
|
e.preventDefault();
|
2013-07-27 18:19:50 +02:00
|
|
|
console.log("btnMoveDown mouse up");
|
2013-07-26 22:39:28 +02:00
|
|
|
clearInterval(btnMoveDownInterval);
|
2013-08-16 22:27:26 +02:00
|
|
|
previewDown();
|
2013-07-27 18:19:50 +02:00
|
|
|
}
|
|
|
|
btnMoveDown.mousedown(function(e) { startMoveDown(e) });
|
|
|
|
btnMoveDown.mouseup(function(e) { stopMoveDown(e) });
|
|
|
|
btnMoveDown.on('touchstart', function(e) { startMoveDown(e) });
|
|
|
|
btnMoveDown.on('touchend', function(e) { stopMoveDown(e) });
|
2013-07-26 22:39:28 +02:00
|
|
|
|
2013-07-27 18:19:50 +02:00
|
|
|
function startTwistLeft(e) {
|
2013-07-26 22:39:28 +02:00
|
|
|
e.preventDefault();
|
|
|
|
// console.log("btnTwistLeft mouse down");
|
2013-08-16 22:27:26 +02:00
|
|
|
previewTwistLeft(true);
|
2013-07-26 22:39:28 +02:00
|
|
|
clearInterval(btnTwistLeftInterval);
|
|
|
|
btnTwistLeftInterval = setInterval( function() {
|
2013-08-16 22:27:26 +02:00
|
|
|
previewTwistLeft(true);
|
2013-07-26 22:39:28 +02:00
|
|
|
}, 1000/30);
|
2013-07-27 18:19:50 +02:00
|
|
|
}
|
|
|
|
function stopTwistLeft(e) {
|
2013-07-26 22:39:28 +02:00
|
|
|
e.preventDefault();
|
|
|
|
// console.log("btnTwistLeft mouse up");
|
|
|
|
clearInterval(btnTwistLeftInterval);
|
2013-08-16 22:27:26 +02:00
|
|
|
previewTwistLeft();
|
2013-07-27 18:19:50 +02:00
|
|
|
}
|
|
|
|
btnTwistLeft.mousedown(function(e) { startTwistLeft(e) });
|
|
|
|
btnTwistLeft.mouseup(function(e) { stopTwistLeft(e) });
|
|
|
|
btnTwistLeft.on('touchstart', function(e) { startTwistLeft(e) });
|
|
|
|
btnTwistLeft.on('touchend', function(e) { stopTwistLeft(e) });
|
2013-07-26 22:39:28 +02:00
|
|
|
|
2013-07-27 18:19:50 +02:00
|
|
|
function startTwistRight(e) {
|
2013-07-26 22:39:28 +02:00
|
|
|
e.preventDefault();
|
|
|
|
// console.log("btnTwistRight mouse down");
|
2013-08-16 22:27:26 +02:00
|
|
|
previewTwistRight(true);
|
2013-07-26 22:39:28 +02:00
|
|
|
clearInterval(btnTwistRightInterval);
|
|
|
|
btnTwistRightInterval = setInterval( function() {
|
2013-08-16 22:27:26 +02:00
|
|
|
previewTwistRight(true);
|
2013-07-26 22:39:28 +02:00
|
|
|
}, 1000/30);
|
2013-07-27 18:19:50 +02:00
|
|
|
}
|
|
|
|
function stopTwistRight(e) {
|
2013-07-26 22:39:28 +02:00
|
|
|
e.preventDefault();
|
|
|
|
// console.log("btnTwistRight mouse up");
|
|
|
|
clearInterval(btnTwistRightInterval);
|
2013-08-30 09:52:02 +02:00
|
|
|
previewTwistRight();
|
2013-07-27 18:19:50 +02:00
|
|
|
}
|
|
|
|
btnTwistRight.mousedown(function(e) { startTwistRight(e) });
|
|
|
|
btnTwistRight.mouseup(function(e) { stopTwistRight(e) });
|
|
|
|
btnTwistRight.on('touchstart', function(e) { startTwistRight(e) });
|
|
|
|
btnTwistRight.on('touchend', function(e) { stopTwistRight(e) });
|
2013-07-26 22:39:28 +02:00
|
|
|
|
2013-08-09 22:25:14 +02:00
|
|
|
/*function openSettings() {
|
2013-07-28 02:46:32 +02:00
|
|
|
console.log("f:openSettings()");
|
|
|
|
$("#contentOverlay").fadeIn(1000, function() {
|
|
|
|
loadSettings();
|
|
|
|
});
|
2013-08-09 22:25:14 +02:00
|
|
|
}*/
|
2013-10-23 18:42:47 +02:00
|
|
|
enableButton(btnSettings, openSettingsWindow);
|
|
|
|
|
2013-07-28 02:46:32 +02:00
|
|
|
// btnSettings.on('touchend', function(e) {
|
|
|
|
// e.preventDefault();
|
|
|
|
// console.log("btnSettings touchend");
|
|
|
|
// });
|
2013-07-26 22:39:28 +02:00
|
|
|
|
|
|
|
btnInfo.mouseup(function(e) {
|
|
|
|
e.preventDefault();
|
|
|
|
console.log("btnInfo mouse up");
|
2013-10-23 18:10:25 +02:00
|
|
|
if (!clientInfo.isSmartphone) helpTours.startTour(helpTours.WELCOMETOUR);
|
2013-07-26 22:39:28 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
// DEBUG
|
2013-10-11 11:42:27 +02:00
|
|
|
/*
|
2013-07-26 22:39:28 +02:00
|
|
|
// $(".agentInfo").css("display", "none");
|
|
|
|
btnDebug.click(function(e) {
|
|
|
|
console.log("debugClick");
|
|
|
|
$(".agentInfo").toggleClass("agentInfoToggle");
|
|
|
|
e.preventDefault();
|
|
|
|
})
|
2013-10-11 11:42:27 +02:00
|
|
|
//*/
|
2013-08-09 22:25:14 +02:00
|
|
|
|
2013-10-12 17:30:39 +02:00
|
|
|
//btnStop.on('touchstart mousedown',stopPrint);
|
2013-08-09 22:25:14 +02:00
|
|
|
}
|
|
|
|
function stopPrint() {
|
2013-08-16 22:27:26 +02:00
|
|
|
console.log("f:stopPrint() >> sendPrintCommands = " + sendPrintCommands);
|
2013-10-16 18:32:24 +02:00
|
|
|
//if (!confirm("Weet je zeker dat je huidige print wilt stoppen?")) return;
|
2013-08-16 22:27:26 +02:00
|
|
|
if (sendPrintCommands) printer.stop();
|
2013-10-14 17:40:56 +02:00
|
|
|
//setState(Printer.STOPPING_STATE,printer.hasControl);
|
|
|
|
printer.overruleState(Printer.STOPPING_STATE);
|
2013-07-26 22:39:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function prevDoodle(e) {
|
|
|
|
console.log("f:prevDoodle()");
|
2013-08-16 22:27:26 +02:00
|
|
|
console.log("f:prevDoodle()");
|
2013-07-26 22:39:28 +02:00
|
|
|
}
|
|
|
|
function nextDoodle(e) {
|
|
|
|
console.log("f:nextDoodle()");
|
|
|
|
}
|
|
|
|
|
|
|
|
function print(e) {
|
2013-08-16 22:27:26 +02:00
|
|
|
console.log("f:print() >> sendPrintCommands = " + sendPrintCommands);
|
|
|
|
|
2013-10-14 18:51:37 +02:00
|
|
|
//$(".btnPrint").css("display","none");
|
2013-10-14 17:46:55 +02:00
|
|
|
|
2013-09-07 16:06:59 +02:00
|
|
|
if (_points.length > 2) {
|
2013-08-16 22:27:26 +02:00
|
|
|
|
2013-10-14 18:51:37 +02:00
|
|
|
//setState(Printer.BUFFERING_STATE,printer.hasControl);
|
2013-10-14 17:40:56 +02:00
|
|
|
printer.overruleState(Printer.BUFFERING_STATE);
|
2013-10-23 18:42:47 +02:00
|
|
|
|
2013-10-16 18:32:24 +02:00
|
|
|
btnStop.css("display","none"); // hack
|
2013-10-23 18:42:47 +02:00
|
|
|
|
|
|
|
// we put the gcode generation in a little delay
|
2013-10-14 18:51:37 +02:00
|
|
|
// so that for example the print button is disabled right away
|
|
|
|
clearTimeout(gcodeGenerateDelayer);
|
2013-10-23 18:42:47 +02:00
|
|
|
gcodeGenerateDelayer = setTimeout(function() {
|
|
|
|
|
2013-10-14 18:51:37 +02:00
|
|
|
var gcode = generate_gcode();
|
2013-10-16 22:25:15 +02:00
|
|
|
if (sendPrintCommands) {
|
|
|
|
if(gcode.length > 0) {
|
|
|
|
printer.print(gcode);
|
|
|
|
} else {
|
|
|
|
printer.overruleState(Printer.IDLE_STATE);
|
|
|
|
printer.startStatusCheckInterval();
|
|
|
|
}
|
2013-10-14 18:51:37 +02:00
|
|
|
} else {
|
|
|
|
console.log("sendPrintCommands is false: not sending print command to 3dprinter");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (debugMode) {
|
|
|
|
$("#textdump").text("");
|
|
|
|
$("#textdump").text(gcode.join("\n"));
|
|
|
|
}
|
2013-10-23 18:42:47 +02:00
|
|
|
|
2013-10-14 18:51:37 +02:00
|
|
|
}, gcodeGenerateDelay);
|
2013-08-16 22:27:26 +02:00
|
|
|
} else {
|
2013-09-07 16:06:59 +02:00
|
|
|
console.log("f:print >> not enough points!");
|
2013-08-16 22:27:26 +02:00
|
|
|
}
|
2013-09-07 16:06:59 +02:00
|
|
|
|
2013-10-14 18:51:37 +02:00
|
|
|
//alert("Je tekening zal nu geprint worden");
|
|
|
|
//$(".btnPrint").css("display","block");
|
2013-10-14 17:46:55 +02:00
|
|
|
|
2013-09-07 16:06:59 +02:00
|
|
|
|
|
|
|
// $.post("/doodle3d.of", { data:output }, function(data) {
|
|
|
|
// btnPrint.disabled = false;
|
|
|
|
// });
|
2013-07-26 22:39:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function clearMainView() {
|
|
|
|
// console.log("f:clearMainView()");
|
|
|
|
ctx.save();
|
|
|
|
ctx.clearRect(0,0,canvas.width, canvas.height);
|
|
|
|
ctx.restore();
|
|
|
|
}
|
2013-09-17 13:08:52 +02:00
|
|
|
function resetPreview() {
|
|
|
|
// console.log("f:resetPreview()");
|
|
|
|
|
|
|
|
// clear preview canvas
|
2013-07-26 22:39:28 +02:00
|
|
|
previewCtx.save();
|
|
|
|
previewCtx.clearRect(0,0,canvas.width, canvas.height);
|
|
|
|
previewCtx.restore();
|
2013-09-17 13:08:52 +02:00
|
|
|
|
|
|
|
// reset height and rotation to default values
|
|
|
|
numLayers = previewDefaults.numLayers; // current number of preview layers
|
|
|
|
rStep = previewDefaults.rotation; // Math.PI/180; //Math.PI/40; //
|
2013-07-26 22:39:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function oopsUndo() {
|
|
|
|
// console.log("f:oopsUndo()");
|
|
|
|
_points.pop();
|
2013-07-27 18:19:50 +02:00
|
|
|
redrawDoodle();
|
2013-07-26 22:39:28 +02:00
|
|
|
redrawPreview();
|
|
|
|
}
|
2013-08-16 22:27:26 +02:00
|
|
|
function previewUp(redrawLess) {
|
2013-07-26 22:39:28 +02:00
|
|
|
// console.log("f:previewUp()");
|
2013-09-07 16:06:59 +02:00
|
|
|
if (numLayers < maxNumLayers) {
|
2013-07-26 22:39:28 +02:00
|
|
|
numLayers++;
|
|
|
|
}
|
2013-08-21 17:37:20 +02:00
|
|
|
// redrawPreview(redrawLess);
|
2013-08-21 18:08:32 +02:00
|
|
|
redrawRenderedPreview(redrawLess);
|
2013-07-26 22:39:28 +02:00
|
|
|
}
|
2013-08-16 22:27:26 +02:00
|
|
|
function previewDown(redrawLess) {
|
2013-07-26 22:39:28 +02:00
|
|
|
// console.log("f:previewDown()");
|
2013-09-07 16:06:59 +02:00
|
|
|
if (numLayers > minNumLayers) {
|
2013-07-26 22:39:28 +02:00
|
|
|
numLayers--;
|
|
|
|
}
|
2013-08-21 17:37:20 +02:00
|
|
|
// redrawPreview(redrawLess);
|
2013-08-21 18:08:32 +02:00
|
|
|
redrawRenderedPreview(redrawLess);
|
2013-07-26 22:39:28 +02:00
|
|
|
}
|
2013-08-16 22:27:26 +02:00
|
|
|
function previewTwistLeft(redrawLess) {
|
|
|
|
if (redrawLess == undefined) redrawLess = false;
|
2013-07-26 22:39:28 +02:00
|
|
|
// console.log("f:previewTwistLeft()");
|
2013-09-17 13:08:52 +02:00
|
|
|
if (rStep > -previewRotationLimit) rStep -= twistIncrement;
|
2013-08-21 17:37:20 +02:00
|
|
|
// redrawPreview(redrawLess);
|
2013-08-21 18:08:32 +02:00
|
|
|
redrawRenderedPreview(redrawLess);
|
2013-07-26 22:39:28 +02:00
|
|
|
}
|
2013-08-16 22:27:26 +02:00
|
|
|
function previewTwistRight(redrawLess) {
|
2013-07-26 22:39:28 +02:00
|
|
|
// console.log("f:previewTwistRight()");
|
2013-09-17 13:08:52 +02:00
|
|
|
if (rStep < previewRotationLimit) rStep += twistIncrement;
|
2013-08-21 17:37:20 +02:00
|
|
|
// redrawPreview(redrawLess);
|
2013-08-21 18:08:32 +02:00
|
|
|
redrawRenderedPreview(redrawLess);
|
2013-08-07 20:47:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-08-09 22:25:14 +02:00
|
|
|
function update() {
|
2013-10-11 16:17:58 +02:00
|
|
|
setState(printer.state,printer.hasControl);
|
2013-10-14 16:40:48 +02:00
|
|
|
|
2013-10-11 12:39:05 +02:00
|
|
|
thermometer.update(printer.temperature, printer.targetTemperature);
|
2013-10-17 14:40:33 +02:00
|
|
|
progressbar.update(printer.currentLine, printer.totalLines);
|
2013-08-09 22:25:14 +02:00
|
|
|
}
|
|
|
|
|
2013-10-23 18:42:47 +02:00
|
|
|
function setState(newState,newHasControl) {
|
2013-10-11 16:17:58 +02:00
|
|
|
if(newState == state && newHasControl == hasControl) return;
|
2013-10-14 16:40:48 +02:00
|
|
|
|
2013-10-18 19:11:10 +02:00
|
|
|
prevState = state;
|
2013-10-23 18:42:47 +02:00
|
|
|
|
2013-10-18 19:11:10 +02:00
|
|
|
console.log("setState: ",prevState," > ",newState," ( ",newHasControl,")");
|
2013-10-11 12:39:05 +02:00
|
|
|
setDebugText("State: "+newState);
|
2013-10-14 16:40:48 +02:00
|
|
|
|
2013-10-11 12:39:05 +02:00
|
|
|
// print button
|
2013-10-11 16:17:58 +02:00
|
|
|
var printEnabled = (newState == Printer.IDLE_STATE && newHasControl);
|
|
|
|
if(printEnabled) {
|
2013-08-09 22:25:14 +02:00
|
|
|
btnPrint.removeClass("disabled"); // enable print button
|
2013-10-11 15:33:51 +02:00
|
|
|
btnPrint.unbind('touchstart mousedown');
|
2013-08-09 22:25:14 +02:00
|
|
|
btnPrint.bind('touchstart mousedown',print);
|
2013-10-11 16:17:58 +02:00
|
|
|
} else {
|
2013-08-09 22:25:14 +02:00
|
|
|
btnPrint.addClass("disabled"); // disable print button
|
|
|
|
btnPrint.unbind('touchstart mousedown');
|
2013-10-11 12:39:05 +02:00
|
|
|
}
|
2013-10-14 16:40:48 +02:00
|
|
|
|
2013-10-11 12:39:05 +02:00
|
|
|
// stop button
|
2013-10-11 16:17:58 +02:00
|
|
|
var stopEnabled = ((newState == Printer.PRINTING_STATE || newState == Printer.BUFFERING_STATE) && newHasControl);
|
|
|
|
if(stopEnabled) {
|
|
|
|
btnStop.removeClass("disabled");
|
2013-10-12 17:30:39 +02:00
|
|
|
btnStop.unbind('touchstart mousedown');
|
|
|
|
btnStop.bind('touchstart mousedown',stopPrint);
|
2013-10-11 16:17:58 +02:00
|
|
|
} else {
|
|
|
|
btnStop.addClass("disabled");
|
2013-10-12 17:30:39 +02:00
|
|
|
btnStop.unbind('touchstart mousedown');
|
2013-10-11 12:39:05 +02:00
|
|
|
}
|
2013-10-14 16:40:48 +02:00
|
|
|
|
2013-10-11 12:39:05 +02:00
|
|
|
// thermometer
|
|
|
|
switch(newState) {
|
2013-10-23 18:42:47 +02:00
|
|
|
case Printer.IDLE_STATE: /* fall-through */
|
|
|
|
case Printer.BUFFERING_STATE: /* fall-through */
|
|
|
|
case Printer.PRINTING_STATE: /* fall-through */
|
2013-10-18 19:11:10 +02:00
|
|
|
case Printer.STOPPING_STATE:
|
2013-10-23 18:42:47 +02:00
|
|
|
thermometer.show();
|
2013-10-11 12:39:05 +02:00
|
|
|
break;
|
|
|
|
default:
|
2013-10-23 18:42:47 +02:00
|
|
|
thermometer.hide();
|
2013-10-11 12:39:05 +02:00
|
|
|
break;
|
|
|
|
}
|
2013-10-14 16:40:48 +02:00
|
|
|
|
2013-10-11 12:39:05 +02:00
|
|
|
// progress indicator
|
|
|
|
switch(newState) {
|
2013-10-14 16:40:48 +02:00
|
|
|
case Printer.PRINTING_STATE:
|
2013-10-23 18:42:47 +02:00
|
|
|
progressbar.show();
|
2013-10-11 12:39:05 +02:00
|
|
|
break;
|
|
|
|
default:
|
2013-10-17 14:40:33 +02:00
|
|
|
progressbar.hide();
|
2013-08-09 22:25:14 +02:00
|
|
|
break;
|
|
|
|
}
|
2013-10-23 18:42:47 +02:00
|
|
|
|
|
|
|
/* settings button */
|
|
|
|
switch(newState) {
|
2013-10-23 23:40:26 +02:00
|
|
|
case Printer.IDLE_STATE:
|
|
|
|
enableButton(btnSettings, openSettingsWindow);
|
|
|
|
break;
|
|
|
|
case Printer.WIFIBOX_DISCONNECTED_STATE: /* fall-through */
|
|
|
|
case Printer.BUFFERING_STATE: /* fall-through */
|
|
|
|
case Printer.PRINTING_STATE: /* fall-through */
|
|
|
|
case Printer.STOPPING_STATE:
|
|
|
|
disableButton(btnSettings);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
enableButton(btnSettings, openSettingsWindow);
|
|
|
|
break;
|
|
|
|
}
|
2013-10-23 18:42:47 +02:00
|
|
|
|
2013-10-18 19:11:10 +02:00
|
|
|
if(newState == Printer.WIFIBOX_DISCONNECTED_STATE) {
|
|
|
|
message.set("Lost connection to WiFi box",Message.ERROR);
|
|
|
|
} else if(prevState == Printer.WIFIBOX_DISCONNECTED_STATE) {
|
|
|
|
message.set("Connected to WiFi box",Message.INFO,true);
|
|
|
|
} else if(newState == Printer.DISCONNECTED_STATE) {
|
|
|
|
message.set("Printer disconnected",Message.WARNING,true);
|
2013-10-23 18:42:47 +02:00
|
|
|
} else if(prevState == Printer.DISCONNECTED_STATE && newState == Printer.IDLE_STATE ||
|
2013-10-18 19:11:10 +02:00
|
|
|
prevState == Printer.UNKNOWN_STATE && newState == Printer.IDLE_STATE) {
|
|
|
|
message.set("Printer connected",Message.INFO,true);
|
2013-10-23 18:42:47 +02:00
|
|
|
} else if(prevState == Printer.PRINTING_STATE && newState == Printer.STOPPING_STATE) {
|
|
|
|
console.log("stopmsg show");
|
|
|
|
message.set("Printer stopping",Message.INFO,false);
|
|
|
|
} else if(prevState == Printer.STOPPING_STATE && newState == Printer.IDLE_STATE) {
|
|
|
|
console.log("stopmsg hide");
|
|
|
|
message.hide();
|
2013-10-18 19:11:10 +02:00
|
|
|
}
|
2013-10-23 18:42:47 +02:00
|
|
|
|
2013-08-09 22:25:14 +02:00
|
|
|
state = newState;
|
2013-10-11 16:17:58 +02:00
|
|
|
hasControl = newHasControl;
|
2013-10-14 16:40:48 +02:00
|
|
|
}
|