0
0
mirror of https://github.com/Doodle3D/doodle3d-client.git synced 2024-11-29 11:54:55 +01:00
doodle3d-client/js/main.js

171 lines
5.4 KiB
JavaScript
Raw Normal View History

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
var printer = new Printer();
var progressbar = new Progressbar();
var thermometer = new Thermometer();
2013-08-27 15:34:28 +02:00
var settingsWindow = new SettingsWindow();
var message = new Message();
var firstTimeSettingsLoaded = true;
2013-09-18 22:35:38 +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
var $drawAreaContainer, $doodleCanvas, doodleCanvas, doodleCanvasContext, $previewContainer;
var showhideInterval;
var showOrHide = false;
var clientInfo = {};
2014-01-10 14:04:36 +01:00
var POPUP_SHOW_DURATION = 175;
2014-01-13 15:52:40 +01:00
var BUTTON_GROUP_SHOW_DURATION = 80;
2014-01-10 14:04:36 +01:00
$(function() {
console.log("ready");
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");
if (wifiboxIsRemote) {
// var hostname = "http://10.0.0.45";
2013-12-05 18:03:21 +01:00
var hostname = "http://192.168.5.1";
wifiboxURL = hostname+"/d3dapi";
wifiboxCGIBinURL = hostname+"/cgi-bin/d3dapi";
} else {
2013-10-02 14:45:54 +02:00
wifiboxURL = "http://" + window.location.host + "/d3dapi";
wifiboxCGIBinURL = "http://" + window.location.host + "/cgi-bin/d3dapi";
}
2013-09-27 16:04:56 +02:00
if (!communicateWithWifibox) {
sendPrintCommands = false; // 'communicateWithWifibox = false' implies this
}
console.log("debugMode: " + debugMode);
console.log("sendPrintCommands: " + sendPrintCommands);
console.log("communicateWithWifibox: " + communicateWithWifibox);
console.log("wifiboxIsRemote: " + wifiboxIsRemote);
console.log("wifibox URL: " + wifiboxURL);
// rudimentary client info
clientInfo.isMobileDevice = isMobileDevice();
clientInfo.isSmartphone = isSmartphone();
initDoodleDrawing();
initPreviewRendering();
initLayouting();
2014-01-09 17:05:03 +01:00
// initSidebars();
initButtonBehavior();
initKeyboard();
2014-01-09 17:05:03 +01:00
// initVerticalShapes();
initWordArt();
initShapeDialog();
disableDragging();
if (!clientInfo.isSmartphone) initHelp();
thermometer.init($("#thermometerCanvas"), $("#thermometerContainer"));
progressbar.init($("#progressbarCanvas"), $("#progressbarCanvasContainer"));
message.init($("#message"));
printer.init();
2013-08-27 15:34:28 +02:00
$(document).on(Printer.UPDATE,update);
2013-09-27 16:04:56 +02:00
settingsWindow.init(wifiboxURL,wifiboxCGIBinURL);
$(document).on(SettingsWindow.SETTINGS_LOADED, settingsLoaded);
2013-09-27 16:04:56 +02:00
2013-09-18 22:35:38 +02:00
if(debugMode) {
console.log("debug mode is true");
$("body").css("overflow", "auto");
$("#debug_textArea").css("display", "block");
2013-12-05 12:47:03 +01:00
//$("#preview_tmp").css("display", "block");
$("#debug_display").css("display", "block");
// show and hide the progressguage and thermometer
//showhideInterval = setInterval(showOrHideThermo, 2500);
// $("#debugContainer").css("display", "block");
/* 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);
//*/
}
});
2014-01-09 17:05:03 +01:00
function disableDragging() {
$(document).bind("dragstart", function(event) {
console.log("dragstart");
event.preventDefault();
});
}
function enableButton(elem, handler) {
//var elem = $('#'+domId);
elem.removeClass("disabled");
elem.unbind('click');
elem.bind('click', handler);
}
function disableButton(elem) {
//var elem = $('#'+domId);
elem.addClass("disabled");
elem.unbind('click');
}
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"]) {
if(firstTimeSettingsLoaded) {
printer.preheat();
firstTimeSettingsLoaded = false;
}
2013-08-27 15:34:28 +02:00
}
2013-09-27 16:04:56 +02:00
}
function setDebugText(text) {
$("#debug_display").text(text);
}