mirror of
https://github.com/Doodle3D/doodle3d-connect.git
synced 2024-12-26 10:33:48 +01:00
move substituteVariables function to ConfigAPI to be able to use it on Print page + Control page
This commit is contained in:
parent
b424daf038
commit
4b68bb5680
@ -14,6 +14,7 @@
|
|||||||
var _noRetainCheckbox;
|
var _noRetainCheckbox;
|
||||||
var _includeBetasCheckbox;
|
var _includeBetasCheckbox;
|
||||||
var _submitButton;
|
var _submitButton;
|
||||||
|
var _settings;
|
||||||
|
|
||||||
var _updateAPI = new UpdateAPI();
|
var _updateAPI = new UpdateAPI();
|
||||||
var _configAPI = new ConfigAPI();
|
var _configAPI = new ConfigAPI();
|
||||||
@ -83,16 +84,19 @@
|
|||||||
$("#btnStop").on("click", function(data) {
|
$("#btnStop").on("click", function(data) {
|
||||||
$(this).hide();
|
$(this).hide();
|
||||||
|
|
||||||
_configAPI.loadSetting("printer.endcode",function(successData) {
|
_configAPI.loadAll(function(successData) {
|
||||||
console.log('btnStop','endcode',successData);
|
_settings = successData;
|
||||||
_printerAPI.stop({gcode:successData}, function(successData) {
|
|
||||||
|
var endcode = _configAPI.subsituteVariables(_settings["printer.endcode"],_settings);
|
||||||
|
|
||||||
|
_printerAPI.stop({gcode:endcode}, function(successData) {
|
||||||
console.log("btnStop success",successData);
|
console.log("btnStop success",successData);
|
||||||
refreshStatus();
|
refreshStatus();
|
||||||
},function(failData) {
|
},function(failData) {
|
||||||
console.log("btnStop fail",failData);
|
console.log("btnStop fail",failData);
|
||||||
});
|
});
|
||||||
}, function(failData) {
|
}, function(failData) {
|
||||||
console.log('btnStop failed to load endcode',failData);
|
console.log('btnStop failed to load settings',failData);
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
@ -41,16 +41,6 @@
|
|||||||
$("#btnPrint").on("click", fetchPrint);
|
$("#btnPrint").on("click", fetchPrint);
|
||||||
});
|
});
|
||||||
|
|
||||||
function formatBytes(a,b) {
|
|
||||||
if (0===a) {
|
|
||||||
return "0 Bytes";
|
|
||||||
} else {
|
|
||||||
var c=1e3,d=b||2,e=["Bytes","KB","MB","GB","TB","PB","EB","ZB","YB"];
|
|
||||||
var f=Math.floor(Math.log(a)/Math.log(c));
|
|
||||||
return parseFloat((a/Math.pow(c,f)).toFixed(d))+" "+e[f];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$.mobile.document.on( "pagebeforeshow", PAGE_ID, function( event, data ) {
|
$.mobile.document.on( "pagebeforeshow", PAGE_ID, function( event, data ) {
|
||||||
_pageData = d3d.util.getPageParams(PAGE_ID);
|
_pageData = d3d.util.getPageParams(PAGE_ID);
|
||||||
|
|
||||||
@ -77,7 +67,7 @@
|
|||||||
|
|
||||||
_serverAPI.getInfo(d3d.pageParams.uuid, function(successData) {
|
_serverAPI.getInfo(d3d.pageParams.uuid, function(successData) {
|
||||||
console.log("getInfo success",successData);
|
console.log("getInfo success",successData);
|
||||||
$("#lstPrint li.gcodeItem p").text(formatBytes(successData["bytes"]));
|
$("#lstPrint li.gcodeItem p").text(d3d.util.formatBytes(successData["bytes"]));
|
||||||
console.log(successData);
|
console.log(successData);
|
||||||
|
|
||||||
|
|
||||||
@ -104,8 +94,6 @@
|
|||||||
_configAPI.loadAll(function(successData) {
|
_configAPI.loadAll(function(successData) {
|
||||||
_settings = successData;
|
_settings = successData;
|
||||||
console.log(_settings);
|
console.log(_settings);
|
||||||
var startcode = subsituteVariables(successData["printer.startcode"],successData);
|
|
||||||
var endcode = subsituteVariables(successData["printer.endcode"],successData);
|
|
||||||
|
|
||||||
var printerLink = $("#lstPrint li.printerItem a").attr("href");
|
var printerLink = $("#lstPrint li.printerItem a").attr("href");
|
||||||
printerLink = d3d.util.replaceURLParameters(printerLink,_pageData);
|
printerLink = d3d.util.replaceURLParameters(printerLink,_pageData);
|
||||||
@ -117,9 +105,6 @@
|
|||||||
$("#lstPrint li.materialItem p").html(materialInfo);
|
$("#lstPrint li.materialItem p").html(materialInfo);
|
||||||
$("#lstPrint li.materialItem a").attr("href",printerLink);
|
$("#lstPrint li.materialItem a").attr("href",printerLink);
|
||||||
|
|
||||||
$("#printStartgcode").val(startcode);
|
|
||||||
$("#printEndgcode").val(endcode);
|
|
||||||
|
|
||||||
_printerAPI.listAll(function(successData) {
|
_printerAPI.listAll(function(successData) {
|
||||||
console.log("printer listAll");
|
console.log("printer listAll");
|
||||||
var printerId = _settings["printer.type"];
|
var printerId = _settings["printer.type"];
|
||||||
@ -136,52 +121,33 @@
|
|||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
$.mobile.document.on( "pagebeforehide", PAGE_ID, function( event, data ) {
|
$.mobile.document.on("pagebeforehide", PAGE_ID, function( event, data ) {
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
function fetchPrint() {
|
function fetchPrint() {
|
||||||
console.log("fetchPrint",d3d.pageParams.uuid);
|
var startcode = _configAPI.subsituteVariables(_settings["printer.startcode"],_settings);
|
||||||
_printerAPI.fetch({
|
var endcode = _configAPI.subsituteVariables(_settings["printer.endcode"],_settings);
|
||||||
|
|
||||||
|
var data = {
|
||||||
"id": d3d.pageParams.uuid,
|
"id": d3d.pageParams.uuid,
|
||||||
"startcode": $("#printStartgcode").val(),
|
"start_code": startcode,
|
||||||
"endcode": $("#printEndgcode").val()
|
"end_code": endcode
|
||||||
},function(successData) {
|
};
|
||||||
|
|
||||||
|
console.log("fetchPrint",d3d.pageParams.uuid,data);
|
||||||
|
_printerAPI.fetch(data,function(successData) {
|
||||||
console.log("fetchPrint success",successData);
|
console.log("fetchPrint success",successData);
|
||||||
$.mobile.changePage("#printing");
|
|
||||||
|
var url = d3d.util.replaceURLParameters("#control",_pageData);
|
||||||
|
$.mobile.changePage(url);
|
||||||
|
|
||||||
},function(failData) {
|
},function(failData) {
|
||||||
console.log("fetchPrint fail",failData);
|
console.log("fetchPrint fail",failData);
|
||||||
|
window.alert("Problem: " + failData.msg);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function subsituteVariables(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;
|
|
||||||
}
|
|
||||||
|
|
||||||
})(window);
|
})(window);
|
||||||
|
|
||||||
|
@ -72,6 +72,15 @@ function ConfigAPI() {
|
|||||||
this.loadSetting("printer.type",completeHandler,failedHandler);
|
this.loadSetting("printer.type",completeHandler,failedHandler);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//this.loadStartOrEndGCode = function(startOrEndGCode, doSubstitute, completeHandler, failedHandler) {
|
||||||
|
// this.loadAll(function(successData) {
|
||||||
|
// var gcode = subsituteVariables(successData["printer."+startOrEndGCode],successData);
|
||||||
|
// if (completeHandler) completeHandler(gcode);
|
||||||
|
// },function(failedData) {
|
||||||
|
// if (failedHandler(failedData));
|
||||||
|
// });
|
||||||
|
//}
|
||||||
|
|
||||||
this.save = function(newSettings,completeHandler,failedHandler) {
|
this.save = function(newSettings,completeHandler,failedHandler) {
|
||||||
//console.log("ConfigAPI:save");
|
//console.log("ConfigAPI:save");
|
||||||
$.ajax({
|
$.ajax({
|
||||||
@ -117,4 +126,33 @@ function ConfigAPI() {
|
|||||||
if(failedHandler) failedHandler();
|
if(failedHandler) failedHandler();
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user