2014-04-28 16:54:57 +02:00
|
|
|
/*
|
|
|
|
* This file is part of the Doodle3D project (http://doodle3d.com).
|
|
|
|
*
|
|
|
|
* Copyright (c) 2013, Doodle3D
|
|
|
|
* This software is licensed under the terms of the GNU GPL v2 or later.
|
|
|
|
* See file LICENSE.txt or visit http://www.gnu.org/licenses/gpl.html for full license details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
function ConfigAPI() {
|
|
|
|
|
|
|
|
var _apiPath = "/d3dapi";
|
|
|
|
var _apiCGIPath = "/cgi-bin"+_apiPath;
|
|
|
|
var _wifiboxURL;
|
|
|
|
var _wifiboxCGIBinURL;
|
|
|
|
|
|
|
|
var _timeoutTime = 3000;
|
|
|
|
var _saveSettingsTimeoutTime = 8000;
|
|
|
|
|
|
|
|
var _self = this;
|
|
|
|
|
|
|
|
this.init = function(wifiboxURL) {
|
|
|
|
//console.log("ConfigAPI:init");
|
|
|
|
|
|
|
|
_wifiboxURL = wifiboxURL+_apiPath;
|
|
|
|
_wifiboxCGIBinURL = wifiboxURL+_apiCGIPath;
|
|
|
|
}
|
|
|
|
this.loadAll = function(completeHandler,failedHandler) {
|
|
|
|
//console.log("ConfigAPI:loadAll");
|
|
|
|
$.ajax({
|
|
|
|
url: _wifiboxURL + "/config/all",
|
|
|
|
type: "GET",
|
|
|
|
dataType: 'json',
|
|
|
|
timeout: _timeoutTime,
|
|
|
|
success: function(response){
|
|
|
|
if(response.status == "error" || response.status == "fail") {
|
|
|
|
if(failedHandler) failedHandler(response);
|
|
|
|
} else {
|
|
|
|
completeHandler(response.data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}).fail(function() {
|
|
|
|
if(failedHandler) failedHandler();
|
|
|
|
});
|
|
|
|
};
|
|
|
|
this.load = function(targetSettings,completeHandler,failedHandler) {
|
|
|
|
//console.log("ConfigAPI:load");
|
|
|
|
$.ajax({
|
|
|
|
url: _wifiboxURL + "/config/",
|
|
|
|
type: "GET",
|
|
|
|
dataType: 'json',
|
|
|
|
data: targetSettings,
|
|
|
|
timeout: _timeoutTime,
|
|
|
|
success: function(response){
|
|
|
|
if(response.status == "error" || response.status == "fail") {
|
|
|
|
if(failedHandler) failedHandler(response);
|
|
|
|
} else {
|
|
|
|
completeHandler(response.data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}).fail(function() {
|
|
|
|
if(failedHandler) failedHandler();
|
|
|
|
});
|
|
|
|
};
|
2017-05-16 09:55:32 +02:00
|
|
|
|
|
|
|
this.loadSetting = function(settingName,completeHandler,failedHandler) {
|
|
|
|
this.load(settingName+"=",function(successData) {
|
|
|
|
completeHandler(successData[settingName]);
|
|
|
|
},failedHandler);
|
|
|
|
}
|
|
|
|
|
|
|
|
this.loadPrinterType = function(completeHandler,failedHandler) {
|
|
|
|
this.loadSetting("printer.type",completeHandler,failedHandler);
|
|
|
|
}
|
|
|
|
|
2014-04-28 16:54:57 +02:00
|
|
|
this.save = function(newSettings,completeHandler,failedHandler) {
|
|
|
|
//console.log("ConfigAPI:save");
|
|
|
|
$.ajax({
|
|
|
|
url: _wifiboxCGIBinURL + "/config",
|
|
|
|
type: "POST",
|
|
|
|
data: newSettings,
|
|
|
|
dataType: 'json',
|
|
|
|
timeout: _saveSettingsTimeoutTime,
|
|
|
|
success: function(response){
|
|
|
|
//console.log("ConfigAPI:save response: ",response);
|
|
|
|
if(response.status == "error" || response.status == "fail") {
|
2017-05-16 11:02:29 +02:00
|
|
|
if (failedHandler) failedHandler(response);
|
2014-04-28 16:54:57 +02:00
|
|
|
} else {
|
2017-05-16 11:02:29 +02:00
|
|
|
console.log("ConfigAPI.save",newSettings,response.data);
|
|
|
|
if (completeHandler) completeHandler(response.data);
|
2014-04-28 16:54:57 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}).fail(function() {
|
|
|
|
if(failedHandler) failedHandler();
|
|
|
|
});
|
|
|
|
};
|
2017-05-16 11:02:29 +02:00
|
|
|
|
|
|
|
this.savePrinterType = function(printerType,completeHandler,failedHandler) {
|
|
|
|
var settings = {"printer.type": printerType};
|
2017-07-12 11:37:31 +02:00
|
|
|
this.save(settings,function(successData) {
|
|
|
|
if (successData.validation["printer.type"]==="ok") {
|
|
|
|
if (completeHandler) completeHandler(successData);
|
|
|
|
} else {
|
|
|
|
if (failedHandler) failedHandler(successData); //passing successData because it contains valiation error
|
|
|
|
}
|
|
|
|
},function(failData) {
|
|
|
|
if (failedHandler) failedHandler(failData);
|
|
|
|
});
|
2017-05-16 11:02:29 +02:00
|
|
|
};
|
|
|
|
|
2014-04-28 16:54:57 +02:00
|
|
|
this.resetAll = function(completeHandler,failedHandler) {
|
|
|
|
//console.log("ConfigAPI:resetAll");
|
|
|
|
$.ajax({
|
|
|
|
url: _wifiboxCGIBinURL + "/config/resetall",
|
|
|
|
type: "POST",
|
|
|
|
dataType: 'json',
|
|
|
|
timeout: _timeoutTime,
|
|
|
|
success: function(response){
|
|
|
|
if(response.status == "error" || response.status == "fail") {
|
|
|
|
if(failedHandler) failedHandler(response);
|
|
|
|
} else {
|
|
|
|
completeHandler(response.data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}).fail(function() {
|
|
|
|
if(failedHandler) failedHandler();
|
|
|
|
});
|
|
|
|
};
|
2017-07-12 11:37:31 +02:00
|
|
|
|
|
|
|
this.subsituteVariables = function(gcode,settings) {
|
|
|
|
//,temperature,bedTemperature,preheatTemperature,preheatBedTemperature
|
|
|
|
var temperature = settings["printer.temperature"];
|
|
|
|
var bedTemperature = settings["printer.bed.temperature"];
|
|
|
|
var preheatTemperature = settings["printer.heatup.temperature"];
|
|
|
|
var preheatBedTemperature = settings["printer.heatup.bed.temperature"];
|
|
|
|
var printerType = settings["printer.type"];
|
|
|
|
var heatedbed = settings["printer.heatedbed"];
|
|
|
|
|
|
|
|
switch (printerType) {
|
|
|
|
case "makerbot_replicator2": printerType = "r2"; break;
|
|
|
|
case "makerbot_replicator2x": printerType = "r2x"; break;
|
|
|
|
case "makerbot_thingomatic": printerType = "t6"; break;
|
|
|
|
case "makerbot_generic": printerType = "r2"; break;
|
|
|
|
case "wanhao_duplicator4": printerType = "r2x"; break;
|
|
|
|
case "_3Dison_plus": printerType = "r2"; break;
|
|
|
|
}
|
|
|
|
var heatedBedReplacement = (heatedbed)? "" : ";";
|
|
|
|
|
|
|
|
gcode = gcode.replace(/{printingTemp}/gi ,temperature);
|
|
|
|
gcode = gcode.replace(/{printingBedTemp}/gi ,bedTemperature);
|
|
|
|
gcode = gcode.replace(/{preheatTemp}/gi ,preheatTemperature);
|
|
|
|
gcode = gcode.replace(/{preheatBedTemp}/gi ,preheatBedTemperature);
|
|
|
|
gcode = gcode.replace(/{printerType}/gi ,printerType);
|
|
|
|
gcode = gcode.replace(/{if heatedBed}/gi ,heatedBedReplacement);
|
|
|
|
|
|
|
|
return gcode;
|
|
|
|
}
|
2014-04-28 16:54:57 +02:00
|
|
|
}
|