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

Settings refactoring

This commit is contained in:
peteruithoven 2013-08-27 15:34:28 +02:00
parent 733ddea616
commit c15c023829
7 changed files with 240 additions and 277 deletions

View File

@ -84,7 +84,7 @@
</div>
<script src="js/libs/jquery-1.8.3.min.js"></script>
<!--<script src="js/libs/bootstrap.min.js"></script>-->
<script src="js/settings.js"></script>
<script src="js/SettingsWindow.js"></script>
<script src="js/d3dServerInterfacing.js"></script>
<script src="js/buttonbehaviors.js"></script>
<script src="js/canvasDrawing_v01.js"></script>

View File

@ -38,8 +38,10 @@ function Printer() {
//this.wifiboxURL = "proxy5.php";
console.log(" wifiboxURL: ",this.wifiboxURL);
this.checkTemperature();
this.checkProgress();
if(autoUpdate) {
this.checkTemperature();
this.checkProgress();
}
}
this.preheat = function() {

216
js/SettingsWindow.js Normal file
View File

@ -0,0 +1,216 @@
//these settings are defined in the firmware (conf_defaults.lua) and will be initialized in loadSettings()
var settings = {
"network.ap.ssid": "d3d-ap-%%MAC_ADDR_TAIL%%",
"network.ap.address": "192.168.10.1",
"network.ap.netmask": "255.255.255.0",
"printer.temperature": 220,
"printer.objectHeight": '???',
"printer.layerHeight": 0.2,
"printer.wallThickness": 0.7,
"printer.speed": 50,
"printer.travelSpeed": 200,
"printer.filamentThickness": 2.85,
"printer.useSubLayers": true,
"printer.firstLayerSlow": true,
"printer.autoWarmUp": true,
"printer.simplify.iterations": 10,
"printer.simplify.minNumPoints": 15,
"printer.simplify.minDistance": 3,
"printer.retraction.enabled": true,
"printer.retraction.speed": 250,
"printer.retraction.minDistance": 1,
"printer.retraction.amount": 2,
"printer.autoWarmUpCommand": "M104 S220 (hardcoded temperature)"
}
function SettingsWindow() {
this.wifiboxURL;
this.window;
this.form;
this.timeoutTime = 3000;
this.retryDelay = 2000; // retry setTimout delay
this.retryLoadSettingsDelay; // retry setTimout instance
this.retrySaveSettingsDelay; // retry setTimout instance
// Events
SettingsWindow.SETTINGS_LOADED = "settingsLoaded";
var self = this;
this.init = function(wifiboxURL) {
this.wifiboxURL = wifiboxURL;
this.window = $("#settings");
this.window.find(".btnOK").click(this.submitwindow);
this.window.find(".settings").load("settings.html", function() {
console.log("Settings:finished loading settings.html, now loading settings...");
self.form = self.window.find("form");
self.form.submit(function (e) { self.submitwindow(e) });
self.loadSettings();
});
}
this.submitwindow = function(e) {
e.preventDefault();
e.stopPropagation();
self.saveSettings();
self.hideSettings();
}
this.showSettings = function() {
console.log("f:showSettings()");
this.loadSettings(); // reload settings
$("#contentOverlay").fadeIn(375, function() {
document.body.removeEventListener('touchmove',prevent,false);
});
}
this.hideSettings = function() {
$("#contentOverlay").fadeOut(375, function() {
document.body.addEventListener('touchmove',prevent,false);
});
}
this.loadSettings = function() {
if (!communicateWithWifibox) {
console.log(" communicateWithWifibox is false: settings aren't being loaded from wifibox...")
return;
}
console.log("Settings:loadSettings() >> getting new data...");
$.ajax({
url: this.wifiboxURL + "/config/all",
dataType: 'json',
timeout: this.timeoutTime,
success: function(data){
console.log("Settings:loadSettings response: ",data);
// TODO: no request status?
settings = data.data;
console.log(" settings: ",settings);
self.fillForm();
$(document).trigger(SettingsWindow.SETTINGS_LOADED);
}
}).fail(function() {
console.log("Settings:loadSettings: failed");
clearTimeout(self.retryLoadSettingsDelay);
self.retryLoadSettingsDelay = setTimeout(function() { self.loadSettings() },self.retryDelay); // retry after delay
});
}
this.saveSettings = function(callback) {
console.log("Settings:saveSettings");
//var printerSettings = {};
$("#printersettings input").each( function(index,element) {
var element = $(element);
//populate settings are with values from html
if(element.attr("type") == "text") {
settings[element.attr('name')] = element.val();
} else if(element.attr("type") == "checkbox") {
settings[element.attr('name')] = element.prop('checked')
}
});
if (communicateWithWifibox) {
$.ajax({
url: this.wifiboxURL + "/config",
type: "POST",
data: settings,
dataType: 'json',
timeout: this.timeoutTime,
success: function(data){
console.log("Settings:saveSettings response: ",data);
if(data.status == "error") {
clearTimeout(self.retrySaveSettingsDelay);
self.retrySaveSettingsDelay = setTimeout(function() { self.saveSettings() },self.retryDelay); // retry after delay
} else {
var savedSettings = data.data;
$.each(savedSettings, function(index, val) {
if (val != "ok") {
console.log("ERROR: value '" + index + "' not successfully set. Message: " + val);
}
});
// TODO something like a callback or feedback that saving went well / or failed
if (callback != undefined) {
callback();
}
}
}
}).fail(function() {
console.log("Settings:saveSettings: failed");
clearTimeout(self.retrySaveSettingsDelay);
self.retrySaveSettingsDelay = setTimeout(function() { self.saveSettings() },self.retryDelay); // retry after delay
});
}
}
this.fillForm = function() {
//update html with loaded wifi settings
$("#ipaddress").attr('value', settings["network.ap.address"]);
$("#netmask").attr('value', settings["network.ap.netmask"]);
$("#ssid").attr('value', settings["network.ap.ssid"]);
//update html with loaded printer settings
$("#printersettings input").each( function(index,element) {
var element = $(element);
//console.log("printer setting input: ",index,element.attr("type"),element.attr('name')); //,element);
if(element.attr("type") == "text") {
element.val(settings[element.attr('name')]);
} else if(element.attr("type") == "checkbox") {
element.prop('checked', settings[element.attr('name')]);
}
});
}
}
/*************************
*
*
* FROM DOODLE3D.INI
*
*/
//TODO: find all references to these variables, replace them and finally remove these.
var objectHeight = 20;
var layerHeight = .2;
//var wallThickness = .5;
var hop = 0;
//var speed = 70;
//var travelSpeed = 200;
var enableTraveling = true;
//var filamentThickness = 2.89;
var minScale = .3;
var maxScale = 1;
var shape = "%";
var twists = 0;
var useSubLayers = true;
//var debug = false; // debug moved to main.js
var loglevel = 2;
var zOffset = 0;
var serverport = 8888;
var autoLoadImage = "hand.txt";
var loadOffset = [0, 0]; // x en y ?
var showWarmUp = true;
var loopAlways = false;
var firstLayerSlow = true;
var useSubpathColors = false;
var autoWarmUp = true;
var maxObjectHeight = 150;
var maxScaleDifference = .1;
var frameRate = 60;
var quitOnEscape = true;
var screenToMillimeterScale = .3; // 0.3
var targetTemperature = 230;
var simplifyiterations = 10;
var simplifyminNumPoints = 15;
var simplifyminDistance = 3;
var retractionspeed = 50;
var retractionminDistance = 5;
var retractionamount = 3;
var sideis3D = true;
var sidevisible = true;
var sidebounds = [900, 210, 131, 390];
var sideborder = [880, 169, 2, 471];
var windowbounds = [0, 0, 800, 500];
var windowcenter = true;
var windowfullscreen = false;
var autoWarmUpCommand = "M104 S230";
//var checkTemperatureInterval = 3;
var autoWarmUpDelay = 3;

View File

@ -204,7 +204,7 @@ function initButtonBehavior() {
btnSettings.bind('touchstart mousedown',function () {
//e.preventDefault();
//console.log("btnSettings clicked");
showSettings();
settingsWindow.showSettings();
});
// btnSettings.on('touchend', function(e) {
// e.preventDefault();

View File

@ -2,9 +2,10 @@ 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)
var wifiboxIsRemote = false; // when you want to run the client on a computer and have it remotely connect to the wifibox
var autoUpdate = true; // auto retrieve updates about temperature and progress from printer
var printer = new Printer();
var settingsWindow = new SettingsWindow();
$(function() {
console.log("ready");
@ -12,7 +13,7 @@ $(function() {
if (getURLParameter("p") != "null") sendPrintCommands = (getURLParameter("p") == "1");
if (getURLParameter("c") != "null") communicateWithWifibox = (getURLParameter("c") == "1");
if (getURLParameter("r") != "null") wifiboxIsRemote = (getURLParameter("r") == "1");
if (getURLParameter("u") != "null") autoUpdate = (getURLParameter("u") == "1");
if (wifiboxIsRemote) {
wifiboxURL = "http://192.168.5.1/cgi-bin/d3dapi";
@ -30,34 +31,27 @@ $(function() {
console.log("wifibox URL: " + wifiboxURL);
initLayouting();
initDoodleDrawing();
initPreviewRendering();
initButtonBehavior();
initSettingsPopup(wifiboxURL);
printer.init();
$(document).on(Printer.UPDATE,update);
$("#settings .settings").load("settings.html", function() {
if (communicateWithWifibox) {
console.log("finished loading settings.html, now loading settings...");
loadSettings();
} else {
console.log("finished loading settings.html >> communicateWithWifibox is false: not loading settings");
}
});
settingsWindow.init(wifiboxURL);
$(document).on(SettingsWindow.SETTINGS_LOADED,settingsLoaded);
if(debugMode) {
if(debugMode) {
console.log("debug mode is true");
$("body").css("overflow", "auto");
$("#debug_textArea").css("display", "block");
$("#preview_tmp").css("display", "block");
}
printer.init();
if (communicateWithWifibox) printer.preheat();
$(document).on(Printer.UPDATE,update);
})
function settingsLoaded() {
console.log("settingsLoaded");
console.log("autoWarmUp: ",settings["printer.autoWarmUp"]);
if(settings["printer.autoWarmUp"]) {
printer.preheat();
}
}

View File

@ -1,192 +0,0 @@
var wifiboxURL;//"http://192.168.5.1/cgi-bin/d3dapi";
//these settings are defined in the firmware (conf_defaults.lua) and will be initialized in loadSettings()
var settings = {
"network.ap.ssid": "d3d-ap-%%MAC_ADDR_TAIL%%",
"network.ap.address": "192.168.10.1",
"network.ap.netmask": "255.255.255.0",
"printer.temperature": 220,
"printer.objectHeight": '???',
"printer.layerHeight": 0.2,
"printer.wallThickness": 0.7,
"printer.speed": 50,
"printer.travelSpeed": 200,
"printer.filamentThickness": 2.85,
"printer.useSubLayers": true,
"printer.firstLayerSlow": true,
"printer.autoWarmUp": true,
"printer.simplify.iterations": 10,
"printer.simplify.minNumPoints": 15,
"printer.simplify.minDistance": 3,
"printer.retraction.enabled": true,
"printer.retraction.speed": 250,
"printer.retraction.minDistance": 1,
"printer.retraction.amount": 2,
"printer.autoWarmUpCommand": "M104 S220 (hardcoded temperature)"
}
var settingsForm = $("#settingsForm");
settingsForm.submit(function(e) {
e.preventDefault();
saveSettings();
return false;
})
function initSettingsPopup(apiURL) {
console.log("f:initSettingsPopup()");
wifiboxURL = apiURL;
if (communicateWithWifibox) loadSettings();
$("#contentOverlay").hide();
$("div.content .btnOK").click(function(e) {
e.preventDefault();
e.stopPropagation();
// TODO something like a callback or feedback that saving went well / or failed
if (communicateWithWifibox) saveSettings();
$("#contentOverlay").fadeOut(375, function() {
document.body.addEventListener('touchmove',prevent,false);
});
console.log("button OK in settings popup pressed");
});
}
function showSettings() {
console.log("f:showSettings()");
if (!communicateWithWifibox) console.log(" communicateWithWifibox is false: settings aren't being loaded from wifibox...")
$("#contentOverlay").fadeIn(375, function() {
console.log("#contentOverlay faded in...");
if (communicateWithWifibox) loadSettings();
document.body.removeEventListener('touchmove',prevent,false);
});
}
function loadSettings() {
console.log("f:loadSettings() >> getting new data...");
$.get(wifiboxURL + "/config/all", {}, function(data) {
settings = JSON.parse(data).data;
// // var printer_layerHeight = settings["printer.layerHeight"];
// // var printer_autoWarmup = settings["printer.autoWarmUp"];
// console.log("print_layerHeight = " + settings["printer.layerHeight"]);
// console.log("printer_autoWarmup = " + settings["printer.autoWarmUp"] + ", type: " + (typeof settings["printer.autoWarmUp"]));
// console.log("printer_useSubLayers = " + settings["printer.useSubLayers"] + " type: " + (typeof settings["printer.useSubLayers"]));
// $("#formpje input[name='printer.layerHeight']").attr('value', settings["printer.layerHeight"]);
//update html with loaded wifi settings
$("#ipaddress").attr('value', settings["network.ap.address"]);
$("#netmask").attr('value', settings["network.ap.netmask"]);
$("#ssid").attr('value', settings["network.ap.ssid"]);
//update html with loaded printer settings
$("#printersettings input").each( function(index,element) {
var element = $(element);
//console.log("printer setting input: ",index,element.attr("type"),element.attr('name')); //,element);
if(element.attr("type") == "text") {
element.val(settings[element.attr('name')]);
} else if(element.attr("type") == "checkbox") {
element.prop('checked', settings[element.attr('name')]);
}
//console.log(" val: ",$(element).val(),element);
});
});
}
function saveSettings(callback) {
console.log("settings form submitted");
// console.log(" printer.layerHeight:" + $("#formpje input[name='printer.layerHeight']").attr('value'));
// console.log(" first layer slow (checkbox):" + $('#firstLayerSlow').prop('checked'));
// console.log(" use sublayers (checkbox):" + $('#useSubLayers').prop('checked'));
//var printerSettings = {};
$("#printersettings input").each( function(index,element) {
var element = $(element);
//populate settings are with values from html
if(element.attr("type") == "text") {
settings[element.attr('name')] = element.val();
} else if(element.attr("type") == "checkbox") {
settings[element.attr('name')] = element.prop('checked')
}
});
$.post(
wifiboxURL + "/config",
settings,
function(data) {
var res = JSON.parse(data).data;
$.each(res, function(index, val) {
if (val != "ok") {
console.log("ERROR: value '" + index + "' not successfully set. Message: " + val);
}
});
if (callback != undefined) {
callback();
}
}
);
}
/*************************
*
*
* FROM DOODLE3D.INI
*
*/
//TODO: find all references to these variables, replace them and finally remove these.
var objectHeight = 20;
var layerHeight = .2;
//var wallThickness = .5;
var hop = 0;
//var speed = 70;
//var travelSpeed = 200;
var enableTraveling = true;
//var filamentThickness = 2.89;
var minScale = .3;
var maxScale = 1;
var shape = "%";
var twists = 0;
var useSubLayers = true;
//var debug = false; // debug moved to main.js
var loglevel = 2;
var zOffset = 0;
var serverport = 8888;
var autoLoadImage = "hand.txt";
var loadOffset = [0, 0]; // x en y ?
var showWarmUp = true;
var loopAlways = false;
var firstLayerSlow = true;
var useSubpathColors = false;
var autoWarmUp = true;
var maxObjectHeight = 150;
var maxScaleDifference = .1;
var frameRate = 60;
var quitOnEscape = true;
var screenToMillimeterScale = .3; // 0.3
var targetTemperature = 230;
var simplifyiterations = 10;
var simplifyminNumPoints = 15;
var simplifyminDistance = 3;
var retractionspeed = 50;
var retractionminDistance = 5;
var retractionamount = 3;
var sideis3D = true;
var sidevisible = true;
var sidebounds = [900, 210, 131, 390];
var sideborder = [880, 169, 2, 471];
var windowbounds = [0, 0, 800, 500];
var windowcenter = true;
var windowfullscreen = false;
var autoWarmUpCommand = "M104 S230";
//var checkTemperatureInterval = 3;
var autoWarmUpDelay = 3;

View File

@ -9,15 +9,6 @@
<link href="css/settings.css" rel="stylesheet" media="screen">
</head>
<body>
<!--<div>-->
<!--<button id="loadBtn">load</button> - load data-->
<!--</div>-->
<!--<div>-->
<!--<form action="http://192.168.5.1/cgi-bin/d3dapi/config" method="POST" id="formpje">-->
<!--printer.layerHeight: <input type="text" name="printer.layerHeight" value="0.1"><br>-->
<!--<input type="submit" value="Submit">-->
<!--</form>-->
<!--</div>-->
<div>
<h3 style="font-weight:bold">
Not all fields are saveable at the moment
@ -171,54 +162,6 @@ targetTemperature=230
<!--<input type="submit" value="Save settings">-->
</form>
</div>
<!--<script src="js/jquery-1.8.3.min.js"></script>-->
<!--<script src="js/bootstrap.min.js"></script>-->
<script src="js/settings.js"></script>
<script type="text/javascript">
// var btnLoad = $("#loadBtn");
// var myForm = $("#formpje");
// myForm.submit(function(e) {
// e.preventDefault();
// console.log("form submitted");
// console.log(" printer.layerHeight:" + $("#formpje input[name='printer.layerHeight']").attr('value'));
// $.post(
// wifiboxURL + "/config",
// {
// "printer.layerHeight": $("#formpje input[name='printer.layerHeight']").attr('value')
// },
// function(data) {
// console.log(JSON.stringify(data));
// });
// return false;
// })
var sendIndex;
var sendLength;
$(function() {
console.log("ready");
// if ($("#useRetraction").prop('checked') == true) $(".retractionSettings").show(500);
// $("#useRetraction").click(function(e) {
// if ($(this).prop('checked')) {
// $(".retractionSettings").show(350);
// } else {
// $(".retractionSettings").hide(350);
// }
// });
// btnLoad.click(function(e) {
// e.preventDefault();
// console.log("load");
// });
// if (communicateWithWifibox) loadSettings();
})
</script>
</body>
</html>