From 13c7b8392b7517264d46dfde465f4f1a8323aebc Mon Sep 17 00:00:00 2001 From: Rick Companje Date: Tue, 11 Jul 2017 12:32:18 +0200 Subject: [PATCH] substitute variables in custom gcode --- js/ControlPage.js | 51 +++++++++++++++++++++++++++++++++++++---------- 1 file changed, 40 insertions(+), 11 deletions(-) diff --git a/js/ControlPage.js b/js/ControlPage.js index 28dffe3..e6b5ac3 100644 --- a/js/ControlPage.js +++ b/js/ControlPage.js @@ -44,18 +44,42 @@ $("#grpStatusAndControl").hide(); $("#btnSend").on("click", function(data) { - console.log("test",$("#gcode").val()); - $(this).hide(); - _printerAPI.print({ - gcode: $("#gcode").val(), - start: true, - first: true - },function(successData) { - console.log("success"); - },function(failData) { - console.log("fail"); + // console.log("test",$("#gcode").val()); + + _configAPI.loadAll(function(successData) { + _settings = successData; + + var gcode = _configAPI.subsituteVariables($("#gcode").val(),_settings); + + console.log("btnPrint subsituteVariables: ",gcode); + + $(this).hide(); + _printerAPI.print({ + gcode: gcode, + start: true, + first: true + },function(successData) { + console.log("btnSend success"); + },function(failData) { + console.log("btnSend fail"); + }); }); + }); + + _pageData = d3d.util.getPageParams(PAGE_ID); + + // console.log(_pageData); + + if(_pageData === undefined) { + console.log("ERROR",PAGE_ID,"_pageData undefined"); + $.mobile.changePage("#boxes"); + return; + } + + var backUrl = d3d.util.replaceURLParameters("#box",_pageData); + $("#btnControlBack").attr("href",backUrl); + /* $("#btnCooldown").button().on("click", function(data) { _printerAPI.print({ @@ -82,6 +106,10 @@ }); */ $("#btnStop").on("click", function(data) { + if (!window.confirm("Are you sure you want to stop the current print?")) { + return; + } + $(this).hide(); _configAPI.loadAll(function(successData) { @@ -94,6 +122,7 @@ refreshStatus(); },function(failData) { console.log("btnStop fail",failData); + window.alert("Problem: " + failData.msg); }); }, function(failData) { console.log('btnStop failed to load settings',failData); @@ -145,7 +174,7 @@ d3d.util.hideLoader(); },function(failData) { - console.log("getStatus fail"); + console.log("getStatus fail",failData); $("#grpStatusAndControl").hide(); d3d.util.hideLoader(); });