2013-08-16 22:28:58 +02:00
|
|
|
var debugMode = false; // debug mode
|
|
|
|
var sendPrintCommands = true; // if Doodle3d should send print commands to the 3d printer
|
|
|
|
var communicateWithWifibox = true; // if Doodle3d should try interfacing with the wifibox (in case one is not connected)
|
2013-08-20 10:55:08 +02:00
|
|
|
var wifiboxIsRemote = false; // when you want to run the client on a computer and have it remotely connect to the wifibox
|
2013-08-27 15:34:28 +02:00
|
|
|
var autoUpdate = true; // auto retrieve updates about temperature and progress from printer
|
2013-08-07 20:47:47 +02:00
|
|
|
|
2013-09-17 13:08:52 +02:00
|
|
|
var printer = new Printer();
|
2013-10-16 23:11:06 +02:00
|
|
|
var progressbar = new Progressbar();
|
2013-09-17 13:08:52 +02:00
|
|
|
var thermometer = new Thermometer();
|
2013-08-27 15:34:28 +02:00
|
|
|
var settingsWindow = new SettingsWindow();
|
2013-10-18 19:11:10 +02:00
|
|
|
var message = new Message();
|
2013-09-17 13:08:52 +02:00
|
|
|
|
2013-10-11 12:39:05 +02:00
|
|
|
var firstTimeSettingsLoaded = true;
|
2013-09-18 22:35:38 +02:00
|
|
|
|
2013-10-16 12:31:22 +02:00
|
|
|
var wifiboxURL; // Using the uhttpd lua handler as default, because of better performance
|
|
|
|
var wifiboxCGIBinURL; // CGI-bin, for some network stuff, where it needs to restart the webserver for example
|
2013-09-18 18:56:32 +02:00
|
|
|
|
2013-09-18 10:46:36 +02:00
|
|
|
var $drawAreaContainer, $doodleCanvas, doodleCanvas, doodleCanvasContext, $previewContainer;
|
|
|
|
|
2013-10-22 12:04:46 +02:00
|
|
|
var showhideInterval;
|
|
|
|
var showOrHide = false;
|
|
|
|
|
2013-10-23 11:29:12 +02:00
|
|
|
var numSavedSketches = -1;
|
|
|
|
var currentSketchId = -1;
|
|
|
|
var isModified = false;
|
|
|
|
|
2013-08-07 20:47:47 +02:00
|
|
|
$(function() {
|
|
|
|
console.log("ready");
|
2013-08-16 22:28:58 +02:00
|
|
|
|
2013-09-18 10:46:36 +02:00
|
|
|
|
2013-09-18 16:02:51 +02:00
|
|
|
//TODO give this a more logical place in code
|
2013-09-18 10:46:36 +02:00
|
|
|
|
2013-08-16 22:28:58 +02:00
|
|
|
if (getURLParameter("d") != "null") debugMode = (getURLParameter("d") == "1");
|
|
|
|
if (getURLParameter("p") != "null") sendPrintCommands = (getURLParameter("p") == "1");
|
|
|
|
if (getURLParameter("c") != "null") communicateWithWifibox = (getURLParameter("c") == "1");
|
|
|
|
if (getURLParameter("r") != "null") wifiboxIsRemote = (getURLParameter("r") == "1");
|
2013-08-27 15:34:28 +02:00
|
|
|
if (getURLParameter("u") != "null") autoUpdate = (getURLParameter("u") == "1");
|
2013-10-23 11:29:12 +02:00
|
|
|
|
2013-08-19 17:55:01 +02:00
|
|
|
if (wifiboxIsRemote) {
|
2013-10-16 12:31:22 +02:00
|
|
|
wifiboxURL = "http://192.168.5.1/d3dapi";
|
|
|
|
wifiboxCGIBinURL = "http://192.168.5.1/cgi-bin/d3dapi";
|
2013-08-19 17:55:01 +02:00
|
|
|
} else {
|
2013-10-02 14:45:54 +02:00
|
|
|
wifiboxURL = "http://" + window.location.host + "/d3dapi";
|
2013-10-16 12:31:22 +02:00
|
|
|
wifiboxCGIBinURL = "http://" + window.location.host + "/cgi-bin/d3dapi";
|
2013-08-19 17:55:01 +02:00
|
|
|
}
|
2013-09-27 16:04:56 +02:00
|
|
|
|
2013-08-19 17:55:01 +02:00
|
|
|
if (!communicateWithWifibox) {
|
2013-08-16 22:28:58 +02:00
|
|
|
sendPrintCommands = false; // 'communicateWithWifibox = false' implies this
|
|
|
|
}
|
|
|
|
console.log("debugMode: " + debugMode);
|
|
|
|
console.log("sendPrintCommands: " + sendPrintCommands);
|
|
|
|
console.log("communicateWithWifibox: " + communicateWithWifibox);
|
|
|
|
console.log("wifiboxIsRemote: " + wifiboxIsRemote);
|
2013-08-07 20:47:47 +02:00
|
|
|
console.log("wifibox URL: " + wifiboxURL);
|
2013-08-09 22:25:14 +02:00
|
|
|
|
2013-08-07 20:47:47 +02:00
|
|
|
initDoodleDrawing();
|
|
|
|
initPreviewRendering();
|
2013-10-11 11:42:27 +02:00
|
|
|
initLayouting();
|
|
|
|
initSidebars();
|
2013-08-07 20:47:47 +02:00
|
|
|
initButtonBehavior();
|
2013-09-18 22:35:38 +02:00
|
|
|
initVerticalShapes();
|
2013-08-07 20:47:47 +02:00
|
|
|
|
2013-09-18 10:57:46 +02:00
|
|
|
thermometer.init($("#thermometerCanvas"), $("#thermometerContainer"));
|
2013-10-16 23:11:06 +02:00
|
|
|
progressbar.init($("#progressbarCanvas"), $("#progressbarCanvasContainer"));
|
|
|
|
|
2013-10-18 19:11:10 +02:00
|
|
|
message.init($("#message"));
|
2013-10-23 11:29:12 +02:00
|
|
|
|
2013-09-17 13:08:52 +02:00
|
|
|
printer.init();
|
2013-08-27 15:34:28 +02:00
|
|
|
$(document).on(Printer.UPDATE,update);
|
2013-09-27 16:04:56 +02:00
|
|
|
|
2013-10-16 12:31:22 +02:00
|
|
|
settingsWindow.init(wifiboxURL,wifiboxCGIBinURL);
|
2013-10-11 11:42:27 +02:00
|
|
|
$(document).on(SettingsWindow.SETTINGS_LOADED, settingsLoaded);
|
2013-09-27 16:04:56 +02:00
|
|
|
|
2013-10-23 11:29:12 +02:00
|
|
|
getSavedSketchStatus();
|
|
|
|
setSketchModified(false);
|
|
|
|
|
2013-09-18 22:35:38 +02:00
|
|
|
if(debugMode) {
|
2013-08-16 22:28:58 +02:00
|
|
|
console.log("debug mode is true");
|
2013-08-07 20:47:47 +02:00
|
|
|
$("body").css("overflow", "auto");
|
|
|
|
$("#debug_textArea").css("display", "block");
|
2013-08-21 17:37:20 +02:00
|
|
|
$("#preview_tmp").css("display", "block");
|
2013-10-23 11:29:12 +02:00
|
|
|
|
2013-10-11 12:39:05 +02:00
|
|
|
$("#debug_display").css("display", "block");
|
2013-10-21 10:28:04 +02:00
|
|
|
|
|
|
|
// show and hide the progressguage and thermometer
|
2013-10-22 15:33:08 +02:00
|
|
|
//showhideInterval = setInterval(showOrHideThermo, 2500);
|
2013-10-21 10:28:04 +02:00
|
|
|
|
2013-10-11 11:42:27 +02:00
|
|
|
// $("#debugContainer").css("display", "block");
|
2013-09-07 16:06:59 +02:00
|
|
|
|
|
|
|
/* TEMP CODE!! -> artificially populates the startgcode and endgcode textareas in the settings window */
|
|
|
|
// todo remove this temporary code...
|
|
|
|
/*
|
|
|
|
setTimeout(function() {
|
|
|
|
$("#startgcode").text("");
|
|
|
|
$("#startgcode").append("G21 (mm) \n");
|
|
|
|
$("#startgcode").append("G91 (relative) \n");
|
|
|
|
$("#startgcode").append("G28 X0 Y0 Z0 (physical home) \n");
|
|
|
|
$("#startgcode").append("M104 S230 (temperature) \n");
|
|
|
|
$("#startgcode").append("G1 E10 F250 (flow) \n");
|
|
|
|
$("#startgcode").append("G92 X-100 Y-100 Z0 E10 \n");
|
|
|
|
$("#startgcode").append("G1 Z3 F5000 (prevent diagonal line) \n");
|
|
|
|
$("#startgcode").append("G90 (absolute) \n");
|
|
|
|
$("#startgcode").append("M106 (fan on)");
|
|
|
|
console.log("$('#startgcode'): " + $("#startgcode").val());
|
|
|
|
|
|
|
|
$("#endgcode").text("");
|
|
|
|
$("#endgcode").append("G1 X-100 Y-100 F15000 (fast homing) \n");
|
|
|
|
$("#endgcode").append("M107 \n");
|
|
|
|
$("#endgcode").append("M84 (disable axes) \n");
|
|
|
|
console.log("$('#endgcode'): " + $("#endgcode").val());
|
|
|
|
}, 1000);
|
|
|
|
//*/
|
2013-08-07 20:47:47 +02:00
|
|
|
}
|
2013-10-16 23:11:06 +02:00
|
|
|
});
|
|
|
|
|
2013-10-23 11:29:12 +02:00
|
|
|
function enableButton(domId, handler) {
|
|
|
|
var elem = $(domId)
|
|
|
|
elem.removeClass("disabled");
|
|
|
|
elem.unbind('touchstart mousedown');
|
|
|
|
elem.bind('touchstart mousedown', handler);
|
|
|
|
}
|
|
|
|
|
|
|
|
function disableButton(domId) {
|
|
|
|
var elem = $(domId)
|
|
|
|
elem.addClass("disabled");
|
|
|
|
elem.unbind('touchstart mousedown');
|
|
|
|
}
|
|
|
|
|
|
|
|
function getSavedSketchStatus() {
|
|
|
|
$.ajax({
|
|
|
|
url: wifiboxURL + "/sketch/status",
|
|
|
|
dataType: 'json',
|
|
|
|
type: 'GET',
|
|
|
|
//timeout: this.timeoutTime,
|
|
|
|
success: function(response) {
|
|
|
|
if (response.status == 'error' || response.status == 'fail') {
|
|
|
|
console.log("getSavedSketchStatus fail/error: " + response.msg + " -- ", response);
|
|
|
|
} else {
|
|
|
|
console.log("getSavedSketchStatus success: num. saved: " + response.data.number_of_sketches + ", space available: " + response.data.available);
|
|
|
|
numSavedSketches = response.data.number_of_sketches;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}).fail(function() {
|
|
|
|
console.log("getSavedSketchStatus failed: ", response);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function setSketchModified(isModified, doNotClearCurrent) {
|
|
|
|
console.log("setModified: " + isModified + (typeof(doNotClearCurrent) !== 'undefined' ? " (doNotClearCurrent: "+doNotClearCurrent+")" : "")); //TEMP
|
|
|
|
|
|
|
|
if (isModified) { enableButton(btnSave, saveSketch); }
|
|
|
|
else { disableButton(btnSave); }
|
|
|
|
|
|
|
|
if (typeof(doNotClearCurrent) !== 'undefined' && !doNotClearCurrent) setCurrentSketchId(-1);
|
|
|
|
sketchModified = isModified;
|
|
|
|
}
|
|
|
|
|
|
|
|
function setCurrentSketchId(sId) {
|
|
|
|
console.log("setCurrentSketchId: " + sId + " / " + numberOfSketches);
|
|
|
|
var enablePrev = false, enableNext = false;
|
|
|
|
if (numberOfSketches == 0) {
|
|
|
|
/* variables are initialized to false, so nothing to be done here */
|
|
|
|
} else if (numberOfSketches > 0) {
|
|
|
|
//if we are not at a saved sketch, consider all saved sketches as 'previous' ones
|
|
|
|
enablePrev = currentSketchId > 1 || currentSketchId == -1;
|
|
|
|
enableNext = currentSketchId < numberOfSketches;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (enablePrev) { enableButton(btnPrevious, prevDoodle); }
|
|
|
|
else { disableButton(btnPrevious); }
|
|
|
|
|
|
|
|
if (enableNext) { enableButton(btnNext, nextDoodle); }
|
|
|
|
else { disableButton(btnNext); }
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-10-16 23:32:50 +02:00
|
|
|
function showOrHideThermo() {
|
|
|
|
console.log("f:showOrHideThermo()");
|
|
|
|
if (showOrHide) {
|
|
|
|
thermometer.hide();
|
|
|
|
progressbar.hide();
|
|
|
|
} else {
|
|
|
|
thermometer.show();
|
|
|
|
progressbar.show();
|
|
|
|
|
|
|
|
}
|
|
|
|
showOrHide = !showOrHide;
|
|
|
|
}
|
|
|
|
|
2013-08-27 15:34:28 +02:00
|
|
|
function settingsLoaded() {
|
|
|
|
console.log("settingsLoaded");
|
2013-09-27 16:04:56 +02:00
|
|
|
console.log("autoHeatup: ",settings["printer.heatup.enabled"]);
|
|
|
|
if(settings["printer.heatup.enabled"]) {
|
2013-10-11 12:39:05 +02:00
|
|
|
if(firstTimeSettingsLoaded) {
|
2013-09-18 18:56:32 +02:00
|
|
|
printer.preheat();
|
2013-10-11 12:39:05 +02:00
|
|
|
firstTimeSettingsLoaded = false;
|
2013-09-18 18:56:32 +02:00
|
|
|
}
|
2013-08-27 15:34:28 +02:00
|
|
|
}
|
2013-09-27 16:04:56 +02:00
|
|
|
}
|
2013-10-11 12:39:05 +02:00
|
|
|
|
|
|
|
function setDebugText(text) {
|
|
|
|
$("#debug_display").text(text);
|
2013-10-23 11:29:12 +02:00
|
|
|
}
|