webmarlin.js 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872
  1. var wmLogBuffer = new Array();
  2. var wmSdListCounter = {
  3. FILES:0,
  4. FOLDERS:0,
  5. Reset: function() {
  6. wmSdListCounter.FILES = 0;
  7. wmSdListCounter.FOLDERS = 0;
  8. $('#list-sd-content').empty();
  9. $('#div-sdlist-file-count').text(wmSdListCounter.FILES);
  10. $('#div-sdlist-folder-count').text(wmSdListCounter.FOLDERS);
  11. }
  12. };
  13. var WmButtonGroups = {
  14. FileManagement: ["#btn-get-sdcontent","#btn-set-sdinit","#btn-set-sdrelease","#file-upload","#btn-file-upload"],
  15. FileActions: ["#btn-set-sdprint","#btn-set-sddelete"],
  16. FileProcess: ["#btn-file-proc","#btn-file-proc-cancel"],
  17. TempStatus: ["#set-auto-temp","#auto-temp-interval","#chart-show-extruder","#chart-show-bed"],
  18. FanSpeed: ["#fan-speed-range"],
  19. MoveHome: ["#btn-move-home-all","#btn-move-home-x","#btn-move-home-y","#btn-move-home-z"],
  20. Move: ["#btn-move-xl","#btn-move-xr","#btn-move-yf","#btn-move-yb","#btn-move-zu","#btn-move-zd"],
  21. StepperAll: ["#set-stepper-all","#set-stepper-x","#set-stepper-y","#set-stepper-z","#set-stepper-e"],
  22. Stepper: ["#set-stepper-x","#set-stepper-y","#set-stepper-z","#set-stepper-e"],
  23. All: function() {
  24. let all = [];
  25. all = all.concat(
  26. WmButtonGroups.FileManagement,
  27. WmButtonGroups.FileActions,
  28. WmButtonGroups.FileProcess,
  29. WmButtonGroups.TempStatus,
  30. WmButtonGroups.FanSpeed,
  31. WmButtonGroups.MoveHome,
  32. WmButtonGroups.Move,
  33. WmButtonGroups.StepperAll
  34. );
  35. return all;
  36. }
  37. };
  38. var wmWebSoket = {
  39. WSObject: null,
  40. Connect: function() {
  41. WsUrl=`ws://${location.host}/ws`;
  42. try {
  43. if(wmWebSoket.WSObject === null) {
  44. jsLog.Debug("WebSocket: Trying connecting to " + WsUrl);
  45. wmWebSoket.WSObject = new WebSocket(WsUrl);
  46. wmWebSoket.SetWsStatusBar(wmWebSoket.WSObject.readyState);
  47. wmWebSoket.WSObject.onopen = function () {
  48. jsLog.Info("WebSocket: Successfully connected to " + WsUrl);
  49. wmWebSoket.SetWsStatusBar(wmWebSoket.WSObject.readyState);
  50. WmControls.Enable(WmButtonGroups.All());
  51. wmWebSoket.Send(wmGCommands.SdPrintStatus);
  52. };
  53. wmWebSoket.WSObject.onclose = function () {
  54. jsLog.Info("WebSocket: Disconnected from "+WsUrl);
  55. wmWebSoket.SetWsStatusBar(null);
  56. wmWebSoket.WSObject = null;
  57. WmControls.Disable(WmButtonGroups.All());
  58. };
  59. wmWebSoket.WSObject.onerror = function () {
  60. jsLog.Error("WebSocket: Connection error");
  61. WmConsole.Trace(new wmLogItem("WebSoket connection error", wmEnums.WSMsgDirection.RECEIVED, wmEnums.ConsoleLevels.ERROR));
  62. };
  63. wmWebSoket.WSObject.onmessage = function (event) {
  64. jsLog.Info("WebSocket: Message received: "+event.data);
  65. wmWebSoket.OnMessage(event.data.trim());
  66. };
  67. }
  68. }
  69. catch (exception) {
  70. jsLog.Error("WebSocket: Exception: "+exception);
  71. wmWebSoket.SetWsStatusBar(wmWebSoket.WSObject.readyState);
  72. WmConsole.Trace(new wmLogItem("WebSocket: Connection exception", wmEnums.WSMsgDirection.RECEIVED, wmEnums.ConsoleLevels.ERROR));
  73. }
  74. },
  75. Disconnect: function() {
  76. try {
  77. if(wmWebSoket.WSObject !== null && wmWebSoket.WSObject.readyState === wmEnums.WSSatuses.OPEN) {
  78. jsLog.Debug("WebSocket: Disconnecting from "+WsUrl);
  79. WmConsole.Trace(new wmLogItem("WebSoket disconnecting...", wmEnums.WSMsgDirection.SENT, wmEnums.ConsoleLevels.INFO));
  80. wmWebSoket.WSObject.close();
  81. wmWebSoket.WSObject = null;
  82. }
  83. }
  84. catch (exception) {
  85. jsLog.Error("WebSocket: Exception: "+exception);
  86. wmWebSoket.SetWsStatusBar(wmWebSoket.WSObject.readyState);
  87. WmConsole.Trace(new wmLogItem("WebSoket connection exception", wmEnums.WSMsgDirection.RECEIVED, wmEnums.ConsoleLevels.ERROR));
  88. }
  89. },
  90. Send: function(gCmd) {
  91. if(wmWebSoket.WSObject !== null && wmWebSoket.WSObject.readyState === wmEnums.WSSatuses.OPEN) {
  92. let strcmd = gCmd.GCode;
  93. if (gCmd.GParams === null) { jsLog.Verbose('WebSocket: Send: Command with no params detected'); }
  94. else {
  95. jsLog.Verbose('WebSocket: Send: Arguments detected:'+gCmd.GParams);
  96. gCmd.GParams = wmTools.StringFormat(gCmd.GParams, gCmd.Value);
  97. strcmd = strcmd +" "+gCmd.GParams;
  98. }
  99. jsLog.Debug('WebSocket: Send commandstring: '+strcmd);
  100. WmConsole.Trace(new wmLogItem("GCmd: <span class=\"badge badge-light\">" + strcmd + "</span> " + gCmd.Description, wmEnums.WSMsgDirection.SENT, wmEnums.ConsoleLevels.SUCCESS));
  101. try { wmWebSoket.WSObject.send(strcmd + '\n'); }
  102. catch (exception) {
  103. jsLog.Error('WebSocket: Exception:' + exception);
  104. WmConsole.Trace(new wmLogItem("WebSoket: Command exception: "+exception, wmEnums.WSMsgDirection.RECEIVED, wmEnums.ConsoleLevels.ERROR));
  105. }
  106. } else { $('#modal-connect').modal('show'); }
  107. },
  108. OnMessage: function(mdt) {
  109. if(mdt === "") { jsLog.Debug("WSMessage match: Empty message (skipped)"); }
  110. else {
  111. let litem = wmLogItem.ParseWsMessage(mdt);
  112. WmConsole.Trace(litem);
  113. if(litem.SdFile !== null) { WmConsole.TraceSdFile(litem); }
  114. }
  115. },
  116. SetWsStatusBar: function(rs) {
  117. let cli = new wmLogItem();
  118. let ctrls = { div:$('#div-conn-statusmsg'), ico:$('#div-conn-statusico'), btn:$('#btn-connect-status'), bar:$('#div-conn-statusbar') };
  119. switch (rs) {
  120. case wmEnums.WSSatuses.CONNECTING:
  121. cli.SetValues("Connecting to "+WsUrl, wmEnums.WSMsgDirection.SENT, wmEnums.ConsoleLevels.INFO);
  122. ctrls.ico.html("<span class=\"blink\">"+wmIcons.Exchange.AddClass('')+"</span>");
  123. ctrls.div.html("Connecting...");
  124. ctrls.btn.html("<span class=\"spinner-border spinner-border-sm\"></span>");
  125. ctrls.bar.removeClass('bg-success bg-warning bg-danger text-light text-dark').addClass("bg-warning text-dark");
  126. break;
  127. case wmEnums.WSSatuses.OPEN:
  128. cli.SetValues("Connected to "+WsUrl, wmEnums.WSMsgDirection.RECEIVED, wmEnums.ConsoleLevels.SUCCESS);
  129. ctrls.ico.html(wmIcons.Wifi.AddClass(''));
  130. ctrls.div.html("Connected");
  131. ctrls.btn.html(wmIcons.Ban.ToHtml());
  132. ctrls.bar.removeClass('bg-success bg-warning bg-danger text-light text-dark').addClass("bg-success text-light");
  133. break;
  134. case wmEnums.WSSatuses.CLOSED:
  135. cli.SetValues("Disconnected from "+WsUrl, wmEnums.WSMsgDirection.RECEIVED, wmEnums.ConsoleLevels.ERROR);
  136. ctrls.ico.html(wmIcons.Plug.AddClass(''));
  137. ctrls.div.html("Disconnected");
  138. ctrls.btn.html(wmIcons.Bolt.ToHtml());
  139. ctrls.bar.removeClass('bg-success bg-warning bg-danger text-light text-dark').addClass("bg-danger text-light");
  140. break;
  141. case wmEnums.WSSatuses.CLOSING:
  142. cli.SetValues("Disconnecting from "+WsUrl, wmEnums.WSMsgDirection.SENT, wmEnums.ConsoleLevels.WARNING);
  143. ctrls.ico.html("<span class=\"blink\">"+wmIcons.Wifi.AddClass('')+"</span>");
  144. ctrls.div.html("Disconnecting...");
  145. ctrls.btn.html("<span class=\"spinner-border spinner-border-sm\"></span>");
  146. ctrls.bar.removeClass('bg-success bg-warning bg-danger text-light text-dark').addClass("bg-warning text-dark");
  147. break;
  148. default:
  149. cli.SetValues("Disconnected from "+WsUrl, wmEnums.WSMsgDirection.RECEIVED, wmEnums.ConsoleLevels.ERROR);
  150. ctrls.ico.html(wmIcons.Plug.AddClass(''));
  151. ctrls.div.html("Disconnected");
  152. ctrls.btn.html(wmIcons.Bolt.ToHtml());
  153. ctrls.bar.removeClass('bg-success bg-warning bg-danger text-light text-dark').addClass("bg-danger text-light");
  154. break;
  155. }
  156. WmConsole.Trace(cli);
  157. }
  158. };
  159. var WmUpload = {
  160. Reader: null,
  161. FileName: null,
  162. FileSize: null,
  163. FileContent: null,
  164. ReadyToWrite: false,
  165. Cancelled: false,
  166. Load: function() {
  167. let [fn,fe] = $("#file-upload-label").text().toUpperCase().split(".");
  168. WmUpload.FileName = fn.substring(0,7)+".GCO";
  169. let input = $('#file-upload').get(0);
  170. if (input.files.length) {
  171. let tfile = input.files[0];
  172. WmUpload.Reader = new FileReader();
  173. WmUpload.Reader.onloadstart = function() {
  174. jsLog.Debug("File uploading starting");
  175. $('#div-upload-fname').html(WmUpload.FileName);
  176. if(!$('#upload-process-collapse').hasClass("show")){ $('#upload-process-collapse').collapse('show'); }
  177. };
  178. WmUpload.Reader.onload = function(e) {
  179. jsLog.Debug("File uploading completed");
  180. WmUpload.FileSize = e.loaded;
  181. WmUpload.FileContent = e.target.result.split("\n");
  182. WmUpload.Cancelled = false;
  183. $('#div-upload-fsize').html(wmTools.FileSizeFormat(WmUpload.FileSize));
  184. $('#div-upload-fproc').html(wmTools.FormatNumber(WmUpload.FileContent.length,0));
  185. WmControls.Enable(WmButtonGroups.FileProcess);
  186. WmUpload.FileProgress(0,"Ready to process...");
  187. };
  188. WmUpload.Reader.onloadend = function(e) {
  189. jsLog.Debug("File uploading finished");
  190. jsLog.Debug("___________________onloadend");
  191. };
  192. WmUpload.Reader.readAsText(tfile);
  193. return true;
  194. } else {
  195. WmControls.ShowModalAlert('Please select the upload file before continuing');
  196. WmControls.Enable(WmButtonGroups.FileManagement,WmButtonGroups.FileActions);
  197. return false;
  198. }
  199. },
  200. Cancel: function() {
  201. jsLog.Debug("File uploading aborted");
  202. WmUpload.Reader = null;
  203. WmUpload.FileName = null;
  204. WmUpload.FileSize = null;
  205. WmUpload.Cancelled = true;
  206. WmControls.Disable(WmButtonGroups.FileProcess);
  207. WmControls.Enable(WmButtonGroups.FileManagement,WmButtonGroups.FileActions);
  208. $('#div-upload-fsize').html("-");
  209. $('#div-upload-fproc').html("-");
  210. $('#div-upload-fname').html("-");
  211. WmUpload.FileProgress(0,"&nbsp;");
  212. if($('#upload-process-collapse').hasClass("show")){ $('#upload-process-collapse').collapse('hide'); }
  213. },
  214. FileProcess: function() {
  215. WmControls.Disable([$("#btn-file-proc")]);
  216. let fl = WmUpload.FileContent.length;
  217. jsLog.Debug("Start process GCode lines ("+WmUpload.FileSize+" total)");
  218. WmUpload.FileProgress(0,"Start analyzing uploaded GCode...");
  219. wmGCommands.SdFileStart.GParams = WmUpload.FileName;
  220. wmWebSoket.Send(wmGCommands.SdFileStart);
  221. var i = 0;
  222. var n = 1;
  223. (function pgline() {
  224. if(WmUpload.Cancelled){
  225. wmWebSoket.Send(wmGCommands.SdFileStop);
  226. return;
  227. }
  228. else if(!WmUpload.ReadyToWrite){
  229. jsLog.Debug("WmUpload.FileProcess: Waiting ready to write...");
  230. WmUpload.FileProgress(0,"Waiting ready to write...");
  231. setTimeout(pgline, 500);
  232. }
  233. else {
  234. let p = wmTools.GetPercentage(i+1,fl);
  235. WmUpload.FileProgress(p,"Analyzing line "+(i+1)+" of "+fl);
  236. let gitem = { line:WmUpload.FileContent[i], process:false, cksum:0 };
  237. if(gitem.line.trim()==="" || gitem.line.match(/^ *$/)) { jsLog.Verbose("GLine: "+i+": "+gitem.line+" => Empty line (skip)"); }
  238. else if(gitem.line.substring(0,1)===";") { jsLog.Verbose("GLine: "+i+": "+gitem.line+" => Comment line (skip)"); }
  239. else if(gitem.line.indexOf(";") > -1) { gitem.line = gitem.line.substring(0,gitem.line.indexOf(";")); gitem.process=true; }
  240. else { gitem.process = true; }
  241. if(gitem.process) {
  242. gitem.line = "N"+n+" "+gitem.line.trim();
  243. gitem.line = gitem.line+"*"+wmGCommandItem.CalcChecksum(gitem.line);
  244. jsLog.Verbose("GLINE TO SEND: "+gitem.line);
  245. wmGCommands.CustomCmd.GCode = gitem.line;
  246. wmWebSoket.Send(wmGCommands.CustomCmd);
  247. n++;
  248. }
  249. i++;
  250. if (i < fl) { setTimeout(pgline, 10); }
  251. else {
  252. WmUpload.FileProgress(100,"GCode Analysis completed!");
  253. WmUpload.ReadyToWrite = false;
  254. wmWebSoket.Send(wmGCommands.SdFileStop);
  255. WmUpload.FileCompleted();
  256. }
  257. }
  258. })();
  259. },
  260. FileProgress: function(p,m) {
  261. p = wmTools.FormatNumber(p,0);
  262. $('#upload-progressbar').text(p+"%");
  263. $('#upload-progressbar').css('width',p+'%').attr('aria-valuenow', p);
  264. $('#upload-progress-text').html(m);
  265. if(p===100) { $('#upload-progressbar').removeClass("progress-bar-animated"); }
  266. },
  267. FileCompleted: function() {
  268. WmControls.Disable(WmButtonGroups.FileProcess);
  269. WmButtons.GetSdContentList();
  270. },
  271. };
  272. var WmButtons = {
  273. ConsoleListClear: function() { WmConsole.Clear(); },
  274. ConsoleListExport: function() { WmConsole.Export(); },
  275. DeleteSdConfirm: function() {
  276. $('#div-sdfile-delete-badge').html($('#txt-sdfile-selected').val());
  277. },
  278. DeleteSdSelected: function() {
  279. jsLog.Debug("DeleteSdSelected: Delete file:"+$("#txt-sdfile-selected").val());
  280. WmControls.Disable(WmButtonGroups.FileActions);
  281. $('#div-sdfile-delete-rs').collapse('show');
  282. wmGCommands.SdFileDel.GParams = $("#txt-sdfile-selected").val();
  283. wmWebSoket.Send(wmGCommands.SdFileDel);
  284. setTimeout(function(){
  285. $('#modal-sdfile-delete').modal('hide');
  286. $('#div-sdfile-delete-rs').collapse('hide');
  287. WmButtons.GetSdContentList();
  288. }, 2000);
  289. },
  290. GCommandSetPreset: function(gc) {
  291. jsLog.Debug("Set preset GCommand ("+gc+")");
  292. $('#text-gcommand').val(gc);
  293. $('#modal-presets').modal('hide');
  294. WmAutostart.SetGCommandChecksum();
  295. },
  296. GetSdContentList: function() {
  297. wmSdListCounter.Reset();
  298. $('#txt-sdfile-selected').val('');
  299. WmControls.Disable(WmButtonGroups.FileManagement);
  300. wmWebSoket.Send(wmGCommands.SdGetList);
  301. },
  302. PrintSdConfirm: function() {
  303. $('#div-sdfile-print-badge').html($('#txt-sdfile-selected').val());
  304. },
  305. PrintSdSelected: function() {
  306. jsLog.Debug("PrintSdSelected: Print file:"+$("#txt-sdfile-selected").val());
  307. WmControls.Disable(WmButtonGroups.FileActions);
  308. $('#div-sdfile-print-rs').collapse('show');
  309. wmGCommands.SdFilePrint.GParams = $("#txt-sdfile-selected").val();
  310. wmWebSoket.Send(wmGCommands.SdFilePrint);
  311. setTimeout(function(){
  312. $('#modal-sdfile-print').modal('hide');
  313. $('#div-sdfile-print-rs').collapse('hide');
  314. WmAutostart.SetShownPanel(wmEnums.Panels.STATUS);
  315. }, 2000);
  316. },
  317. SaveSettings: function() {
  318. jsLog.Verbose("Button 'btn-save-settings' clicked");
  319. WmControls.Disable(['#btn-save-settings','#btn-close-settings']);
  320. wmSettings.AutoConnect = document.getElementById('set-auto-connect').checked;
  321. wmSettings.DefaultPanel = parseInt($('#set-default-panel').val());
  322. wmSettings.LogLevel = parseInt($('#set-log-level').val());
  323. wmSettings.SymbolMode = $('#set-log-symbol').val();
  324. wmSettings.AutoTempInterval = $('#set-default-autotemp').val();
  325. if($('#set-default-tempunit').val()===0) { wmSettings.TempUnit = wmEnums.TempUnits.CELSIUS; }
  326. else if($('#set-default-tempunit').val()===1) { wmSettings.TempUnit = wmEnums.TempUnits.FAHRENHEIT; }
  327. else if( $('#set-default-tempunit').val()===2) { wmSettings.TempUnit = wmEnums.TempUnits.KELVIN; }
  328. if(wmSettings.SymbolMode==='letter') {
  329. wmSettings.SymbolSend = wmEnums.WsMsgSymbols.SENT.LETTER;
  330. wmSettings.SymbolReceive = wmEnums.WsMsgSymbols.RECEIVED.LETTER;
  331. } else {
  332. wmSettings.SymbolSend = $('#div-log-symbol-icon-sample-s').html();
  333. wmSettings.SymbolReceive = $('#div-log-symbol-icon-sample-r').html();
  334. }
  335. if(document.getElementById('set-trace-mode-append').checked) {
  336. wmSettings.ConsoleDirection = wmEnums.ConsoleDirection.APPEND;
  337. } else {
  338. wmSettings.ConsoleDirection = wmEnums.ConsoleDirection.PREPEND;
  339. }
  340. wmCookie.Write(wmTools.StringFormatJson(wmSettings));
  341. $('#div-save-setting-rs').collapse('show');
  342. setTimeout(function(){
  343. $('#modal-settings').modal('hide');
  344. $('#div-save-setting-rs').collapse('hide');
  345. WmControls.Enable(['#btn-save-settings','#btn-close-settings']);
  346. }, 2000);
  347. },
  348. SdInit: function() {
  349. wmWebSoket.Send(wmGCommands.SdInit);
  350. },
  351. SdRelease: function() {
  352. wmWebSoket.Send(wmGCommands.SdRelease);
  353. },
  354. SendGcommand: function() {
  355. if(wmWebSoket.WSObject !== null && wmWebSoket.WSObject.readyState === wmEnums.WSSatuses.OPEN) {
  356. WmControls.Disable(["#btn-gcommand"]);
  357. let gcmd = $('#text-gcommand');
  358. if (gcmd.val() === "") {
  359. gcmd.removeClass('border-dark').addClass('border-danger');
  360. jsLog.Warning("Empty custom command string detected");
  361. gcmd.focus();
  362. } else {
  363. gcmd.removeClass('border-danger').addClass('border-dark');
  364. let gc = wmGCommandItem.GetCommandItemByCode(gcmd.val().trim().toUpperCase());
  365. if(gc === null) {
  366. wmGCommands.CustomCmd.GCode = gcmd.val().trim().toUpperCase();
  367. jsLog.Debug("Sending custom command: " + wmGCommands.CustomCmd.GCode);
  368. wmWebSoket.Send(wmGCommands.CustomCmd);
  369. } else {
  370. if(gc.Supported) {
  371. wmGCommands.CustomCmd.GCode = gcmd.val().trim().toUpperCase();
  372. jsLog.Debug("Sending custom command: " + wmGCommands.CustomCmd.GCode);
  373. wmWebSoket.Send(wmGCommands.CustomCmd);
  374. } else {
  375. jsLog.Warning("Unsupported command: " + wmGCommands.CustomCmd.GCode);
  376. WmConsole.Trace(new wmLogItem("GCmd: <span class=\"badge badge-light\">" + gcmd.val() + "</span> Unsupported command", wmEnums.WSMsgDirection.RECEIVED, wmEnums.ConsoleLevels.ERROR));
  377. }
  378. }
  379. gcmd.val('');
  380. $('#checksum-gcommand-value').html('&nbsp;');
  381. WmControls.Enable(["#btn-gcommand"]);
  382. }
  383. } else { $('#modal-connect').modal('show'); }
  384. },
  385. SetPositionHome: function(b) {
  386. if(b.id==="btn-move-home-all"){ wmWebSoket.Send(wmGCommands.MoveHome); }
  387. else if (b.id==="btn-move-home-x"){ wmWebSoket.Send(wmGCommands.MoveHomeX); }
  388. else if (b.id==="btn-move-home-y"){ wmWebSoket.Send(wmGCommands.MoveHomeY);}
  389. else if (b.id==="btn-move-home-z"){ wmWebSoket.Send(wmGCommands.MoveHomeZ);}
  390. },
  391. SetSdSelected: function(sdi) {
  392. jsLog.Debug("SetSdSelected: Selected file:"+$(sdi).attr("data-sdfile"));
  393. $('#txt-sdfile-selected').val($(sdi).attr("data-sdfile"));
  394. let lip = document.getElementById("list-sd-content").getElementsByTagName("a");
  395. for (let i=0; i<lip.length; i++) { $(lip[i]).removeClass('list-group-item-success').addClass("list-group-item-light"); }
  396. $(sdi).removeClass('list-group-item-light').addClass("list-group-item-success");
  397. WmControls.Enable(WmButtonGroups.FileActions);
  398. if(!$('#div-sd-selected-file').hasClass("show")) { $('#div-sd-selected-file').collapse("show"); }
  399. wmGCommands.SdFileSel.GParams = $(sdi).attr("data-sdfile");
  400. wmWebSoket.Send(wmGCommands.SdFileSel);
  401. },
  402. ToggleChecksumDiv: function() {
  403. let csdiv = $('#checksum-gcommand-div');
  404. if($('#btn-gcommand-checksum').hasClass('active')===true) { csdiv.collapse('hide'); } else { csdiv.collapse('show'); }
  405. },
  406. UploadSdFile: function() {
  407. WmControls.Disable(WmButtonGroups.FileManagement);
  408. WmControls.Disable(WmButtonGroups.FileActions);
  409. if (!window.FileReader) {
  410. jsLog.Error('Your browser do not support JS file uploading');
  411. alert('Your browser do not support JS file uploading');
  412. WmControls.Enable(WmButtonGroups.FileManagement,WmButtonGroups.FileActions);
  413. } else {
  414. jsLog.Debug("Starting upload file process");
  415. if(WmUpload.Load()) { jsLog.Debug("Upload completed"); }
  416. else {
  417. jsLog.Error("Upload failed");
  418. WmControls.Enable(WmButtonGroups.FileManagement,WmButtonGroups.FileActions);
  419. }
  420. }
  421. },
  422. WsConnect: function() {
  423. if(wmWebSoket.WSObject === null) { wmWebSoket.Connect(); }
  424. else { if(wmWebSoket.WSObject.readyState === wmEnums.WSSatuses.OPEN) { wmWebSoket.Disconnect(); } }
  425. },
  426. };
  427. var WmControls = {
  428. Enable: function() {
  429. if(arguments.length > 0) {
  430. for(let i=0; i<arguments.length; i++) {
  431. let fld = arguments[i];
  432. for(let c=0; c<fld.length; c++) { WmControls.SetInputStatus(fld[c],'enabled'); }
  433. }
  434. } else { jsLog.Warning("WmControls.Enable: Missing input arguments"); }
  435. },
  436. Disable: function() {
  437. if(arguments.length > 0) {
  438. for(let i=0; i<arguments.length; i++) {
  439. let fld = arguments[i];
  440. for(let c=0; c<fld.length; c++) { WmControls.SetInputStatus(fld[c],'disabled'); }
  441. }
  442. } else { jsLog.Warning("WmControls.Disable: Missing input arguments"); }
  443. },
  444. SetInputStatus(inid,st) {
  445. if($(inid).attr("data-input-type")==="togglebtn"){
  446. if(st==="enabled") { $(inid).bootstrapToggle('enable'); } else { $(inid).bootstrapToggle('disable'); }
  447. } else {
  448. if(st==="enabled") { $(inid).prop("disabled", false); } else { $(inid).prop("disabled", true); }
  449. }
  450. },
  451. SetCheckStatus: function(ao,b) {
  452. let cs="off";
  453. if(b) { cs="on"; }
  454. for(let i=0; i<ao.length; i++) { $(ao[i]).bootstrapToggle(cs); }
  455. },
  456. SetUpload: function() {
  457. let f = $("#file-upload").val();
  458. jsLog.Debug("SetUploadFilename: Ready to upload file:"+f);
  459. $("#file-upload-label").html(f.split("\\").pop());
  460. WmControls.Enable(WmButtonGroups.FileManagement);
  461. WmControls.Disable(WmButtonGroups.FileProcess);
  462. },
  463. ShowModalAlert: function(m) {
  464. $('#div-alert-message').html(m);
  465. $('#modal-alert').modal('show');
  466. },
  467. SetAutoTemp: function() {
  468. if($('#set-auto-temp').prop('checked')) {
  469. wmGCommands.SetTempOn.GParams = "S"+$('#auto-temp-interval').val();
  470. wmWebSoket.Send(wmGCommands.SetTempOn);
  471. } else { wmWebSoket.Send(wmGCommands.SetTempOff); }
  472. },
  473. SetFanSpeed: function(rv) {
  474. rv = parseInt(rv);
  475. jsLog.Debug("Set fan speed to: "+rv+"%");
  476. let fsv = wmTools.FormatNumber(wmTools.GetNumPercent(rv,255),0);
  477. $('#div-fan-speed-current').html(rv+"%<span class='badge badge-success ml-1'>"+fsv+"</span>");
  478. $('#div-fan-speed-set').html(rv+"%<span class='badge badge-success ml-1'>"+fsv+"</span>");
  479. if(rv===0) { wmWebSoket.Send(wmGCommands.FanOff); }
  480. else {
  481. wmGCommands.FanOn.GParams = "S"+fsv;
  482. wmWebSoket.Send(wmGCommands.FanOn);
  483. }
  484. WmChartsData.FanSpeed.DataUpdate(rv);
  485. },
  486. ResetSdFileCounters() {
  487. $('#list-sd-content').empty();
  488. $('#div-sdlist-file-count').text(0);
  489. $('#div-sdlist-folder-count').text(0);
  490. },
  491. UpdateTemperatures: function(dt){
  492. $('#div-temp-extruder-detect').text(dt.ExtruderTemp);
  493. $('#div-temp-extruder-set').text(dt.ExtruderSet);
  494. $('#div-temp-extruder-unit').text(wmSettings.TempUnit.LABEL);
  495. if(dt.BedTemp !== null) {
  496. $('#div-temp-bed-detect').text(dt.BedTemp);
  497. $('#div-temp-bed-set').text(dt.BedSet);
  498. $('#div-temp-bed-unit').text(wmSettings.TempUnit.LABEL);
  499. }
  500. },
  501. SetPrinterStatusInfo: function(s, m) {
  502. if(!s) {
  503. $('#div-pstatus-sdprint').removeClass("badge-danger").addClass("badge-info");
  504. $('#div-pstatus-sdprint').html("Ready to print");
  505. $('#div-pstatus-timer').collapse('hide');
  506. $('#div-pstatus-progress').collapse('hide');
  507. } else {
  508. $('#div-pstatus-sdprint').removeClass("badge-danger badge-info").addClass("badge-success");
  509. $('#div-pstatus-sdprint').html("Printing in progress");
  510. $('#div-pstatus-timer').collapse('show');
  511. $('#div-pstatus-progress').collapse('show');
  512. }
  513. },
  514. SetSteppers: function(o) {
  515. if(o.id==="set-stepper-all") {
  516. WmControls.SetCheckStatus(WmButtonGroups.Stepper,o.checked);
  517. if(o.checked) { wmWebSoket.Send(wmGCommands.StepEnableAll); } else { wmWebSoket.Send(wmGCommands.StepDisableAll); }
  518. } else {
  519. if(o.id==="set-stepper-x") { wmGCommands.StepEnable.GParams = "X"; }
  520. else if(o.id==="set-stepper-y") { wmGCommands.StepEnable.GParams = "Y"; }
  521. else if(o.id==="set-stepper-z") { wmGCommands.StepEnable.GParams = "Z"; }
  522. else if(o.id==="set-stepper-e") { wmGCommands.StepEnable.GParams = "E"; }
  523. if(o.checked) { wmWebSoket.Send(wmGCommands.StepEnable); } else { wmWebSoket.Send(wmGCommands.StepDisable); }
  524. }
  525. },
  526. };
  527. var WmChartsData = {
  528. Temperatures: {
  529. TimeFormat: 'HH:mm:ss',
  530. Speed: 1000,
  531. Scale: 1,
  532. Extruder: {
  533. Label: "Extruder",
  534. BorderColor: wmColors.RedCoral,
  535. BgColor: wmColors.RedCoral,
  536. Data:[]
  537. },
  538. Bed: {
  539. Label: "Bed",
  540. BorderColor: wmColors.Blue,
  541. BgColor: wmColors.Blue,
  542. Data:[]
  543. },
  544. AddEmpty: function(arr, n) {
  545. for(var i = 0; i < n; i++) {
  546. let xd = moment().subtract((n - i) * WmChartsData.Temperatures.Speed, 'milliseconds').toDate();
  547. arr.push({ x: xd, y: null });
  548. }
  549. },
  550. DataUpdate(di) {
  551. let dt = new Date();
  552. WmChartsData.Temperatures.Extruder.Data.push({ x: dt, y: di.ExtruderTemp });
  553. WmChartsData.Temperatures.Extruder.Data.shift();
  554. if(di.BedTemp !== null) {
  555. WmChartsData.Temperatures.Bed.Data.push({ x: dt, y: di.BedTemp });
  556. WmChartsData.Temperatures.Bed.Data.shift();
  557. }
  558. requestAnimationFrame(WmCharts.Advance);
  559. }
  560. },
  561. FanSpeed: {
  562. Values: {
  563. Label: ["Fan speed",""],
  564. BgColor: [wmColors.GreenSuc, wmColors.Grey],
  565. Data: [0,100]
  566. },
  567. DataUpdate(di) {
  568. WmChartsData.FanSpeed.Values.Data[0] = di;
  569. WmChartsData.FanSpeed.Values.Data[1] = 100 - di;
  570. if(di < 30) { WmChartsData.FanSpeed.Values.BgColor[0] = wmColors.GreenSuc; }
  571. else if(di < 60) { WmChartsData.FanSpeed.Values.BgColor[0] = wmColors.Yellow; }
  572. else if(di < 80) { WmChartsData.FanSpeed.Values.BgColor[0] = wmColors.Orange; }
  573. else { WmChartsData.FanSpeed.Values.BgColor[0] = wmColors.Red; }
  574. requestAnimationFrame(function() { WmCharts.FanSpeed.CanvasItem.update()});
  575. }
  576. }
  577. };
  578. var WmCharts = {
  579. Temperatures: {
  580. CanvasItem: null,
  581. Config: {
  582. type: 'line',
  583. data: {
  584. datasets: [{
  585. label: WmChartsData.Temperatures.Extruder.Label,
  586. data: WmChartsData.Temperatures.Extruder.Data,
  587. backgroundColor: WmChartsData.Temperatures.Extruder.BgColor,
  588. borderColor: WmChartsData.Temperatures.Extruder.BorderColor,
  589. borderWidth: 2,
  590. fill: false,
  591. pointRadius: 1.5
  592. },{
  593. label: WmChartsData.Temperatures.Bed.Label,
  594. data: WmChartsData.Temperatures.Bed.Data,
  595. backgroundColor: WmChartsData.Temperatures.Bed.BgColor,
  596. borderColor: WmChartsData.Temperatures.Bed.BorderColor,
  597. borderWidth: 2,
  598. fill: false,
  599. pointRadius: 1.5
  600. }]
  601. },
  602. options: {
  603. responsive: true,
  604. animation: { duration: WmChartsData.Temperatures.Speed * 1.5, easing:'linear' },
  605. scales: {
  606. xAxes: [{ type:'time', time:{ displayFormats: { second: 'HH:mm:ss'} }, scaleLabel: { display: false } }],
  607. yAxes: [{ ticks: { min: 0} }]
  608. }
  609. }
  610. },
  611. DisplayAxis: function(ck) {
  612. if(ck.id==="chart-show-extruder") {
  613. WmCharts.Temperatures.CanvasItem.getDatasetMeta(0).hidden = ck.checked===true ? false : true;
  614. $('#chart-show-extruder-label').text(ck.checked===true ? "Show" : "Hide");
  615. }
  616. else if(ck.id==="chart-show-bed") {
  617. WmCharts.Temperatures.CanvasItem.getDatasetMeta(1).hidden = ck.checked===true ? false : true;
  618. $('#chart-show-bed-label').text(ck.checked===true ? "Show" : "Hide");
  619. }
  620. if(!$('#set-auto-temp').prop('checked')){ WmCharts.Temperatures.CanvasItem.update(); }
  621. }
  622. },
  623. FanSpeed: {
  624. CanvasItem: null,
  625. Config: {
  626. type: 'doughnut',
  627. data: {
  628. datasets: [{
  629. data: WmChartsData.FanSpeed.Values.Data,
  630. backgroundColor: WmChartsData.FanSpeed.Values.BgColor,
  631. }],
  632. labels: WmChartsData.FanSpeed.Values.Label
  633. },
  634. options: {
  635. responsive: true,
  636. circumference: Math.PI,
  637. rotation: -Math.PI,
  638. legend: { display: false },
  639. tooltips: { enabled: false },
  640. title: { display: false },
  641. animation: {
  642. animateScale: true,
  643. animateRotate: true,
  644. onComplete: function () {
  645. var ctx = this.chart.ctx;
  646. ctx.font = "14pt Verdana";
  647. ctx.textAlign = 'center';
  648. ctx.textBaseline = 'bottom';
  649. ctx.fillStyle = wmColors.Black;
  650. let ds = this.data.datasets;
  651. let model = ds[0]._meta[Object.keys(ds[0]._meta)[0]].data[0]._model;
  652. let xp = wmTools.FormatNumber(model.x,0), yp = wmTools.FormatNumber(model.y,0);
  653. jsLog.Debug("Drawing speed gauge percentage label position (x,y): "+xp+","+yp);
  654. ctx.fillText(WmChartsData.FanSpeed.Values.Data[0]+'%', xp, yp);
  655. }
  656. }
  657. }
  658. }
  659. },
  660. Init: function() {
  661. WmChartsData.Temperatures.AddEmpty(WmChartsData.Temperatures.Extruder.Data, 20);
  662. WmChartsData.Temperatures.AddEmpty(WmChartsData.Temperatures.Bed.Data, 20);
  663. WmCharts.Temperatures.CanvasItem = new Chart(document.getElementById('chart-temps'), WmCharts.Temperatures.Config);
  664. WmCharts.FanSpeed.CanvasItem = new Chart(document.getElementById('chart-fanspeed'), WmCharts.FanSpeed.Config);
  665. },
  666. Advance: function() {
  667. if (WmChartsData.Temperatures.Extruder.Data[0] !== null && WmChartsData.Temperatures.Extruder.Scale < 4) { WmCharts.Temperatures.CanvasItem.update(); }
  668. WmCharts.Temperatures.CanvasItem.update();
  669. },
  670. SetTempReport: function(tr) {
  671. let temps = {
  672. ExtruderTemp: tr[0].replace(/T:/,""),
  673. ExtruderSet: tr[1],
  674. BedTemp: tr[2]==="undefined" ? null : tr[2].replace(/B:/,""),
  675. BedSet: tr[3]==="undefined" ? null : tr[3]
  676. };
  677. WmChartsData.Temperatures.DataUpdate(temps);
  678. WmControls.UpdateTemperatures(temps);
  679. }
  680. };
  681. var WmConsole = {
  682. Clear: function() {
  683. jsLog.Debug("Clearing console message list...");
  684. $('#gcommand-console-list').empty();
  685. wmLogBuffer.length = 0;
  686. WmConsole.Trace(new wmLogItem("Console list cleared by user", wmEnums.WSMsgDirection.RECEIVED, wmEnums.ConsoleLevels.SUCCESS));
  687. },
  688. Export: function() {
  689. jsLog.Debug("Exporting console message list...");
  690. var fdt = new Array();
  691. // DA FINIRE LA PRIMA RIGA NOMI CAMPI
  692. for(i=0; i<wmLogBuffer.length; i++) { fdt.push(wmLogBuffer[i].ToCsv()+"\n"); }
  693. wmTools.FileDownload("e4dbox_log.csv", "text/csv;charset=utf-8", fdt);
  694. },
  695. SetMessageSymbol: function() {
  696. if($('#set-log-symbol').val()==="icon") {
  697. jsLog.Verbose("Set message symbol icon collapse panel to 'show'",this);
  698. WmConsole.SetSymbolIcon();
  699. $('#div-log-symbol-icon').collapse('show');
  700. } else {
  701. jsLog.Verbose("Set message symbol icon collapse panel to 'hide'",this);
  702. $('#div-log-symbol-icon').collapse('hide');
  703. }
  704. },
  705. SetSymbolIcon: function() {
  706. let ctrl = parseInt($('#set-log-symbol-icon').val());
  707. let hc = {s:null, r:null};
  708. jsLog.Verbose("Set settings symbol sample fields ("+ctrl+")");
  709. if(ctrl===0) { hc.s = wmIcons.ChevronUp.ToHtml(); hc.r = wmIcons.ChevronDown.ToHtml(); }
  710. else if(ctrl===1) { hc.s = wmIcons.LongArrowUp.ToHtml(); hc.r = wmIcons.LongArrowDown.ToHtml(); }
  711. else if(ctrl===2) { hc.s = wmIcons.ChevronLeft.ToHtml(); hc.r = wmIcons.ChevronRight.ToHtml(); }
  712. else if(ctrl===3) { hc.s = wmIcons.LongArrowLeft.ToHtml(); hc.r = wmIcons.LongArrowRight.ToHtml(); }
  713. $('#div-log-symbol-icon-sample-s').html(hc.s);
  714. $('#div-log-symbol-icon-sample-r').html(hc.r);
  715. },
  716. Trace: function(litem) {
  717. wmLogBuffer.push(litem);
  718. let clist = $('#gcommand-console-list');
  719. if (wmSettings.ConsoleDirection === wmEnums.ConsoleDirection.APPEND) { clist.append(litem.ToLoglist()); } else { clist.prepend(litem.ToLoglist()); }
  720. $('#log-counter-badge').text(wmLogBuffer.length);
  721. },
  722. TraceSdFile: function(litem) {
  723. if(litem.SdFile === "Begin file list") { wmSdListCounter.Reset(); }
  724. if(litem.SdFile !== "Begin file list" && litem.SdFile !== "End file list") {
  725. wmSdListCounter.FILES++;
  726. if(litem.SdFile.indexOf("/")>-1) { wmSdListCounter.FOLDERS++; }
  727. }
  728. $('#list-sd-content').append(litem.ToSdFileList());
  729. $('#div-sdlist-file-count').text(wmSdListCounter.FILES);
  730. $('#div-sdlist-folder-count').text(wmSdListCounter.FOLDERS);
  731. if(litem.SdFile === "End file list") { WmControls.Enable(WmButtonGroups.FileManagement); }
  732. }
  733. };
  734. var WmAutostart = {
  735. SetDefaultPanel: function() {
  736. jsLog.Verbose("Set default shown panel ("+wmSettings.DefaultPanel+")");
  737. if (wmSettings.DefaultPanel == wmEnums.Panels.STATUS) { $('#accordion-panel-status-body').addClass("show"); }
  738. else if (wmSettings.DefaultPanel === wmEnums.Panels.CONTROLS) { $('#accordion-panel-controls-body').addClass("show"); }
  739. else if (wmSettings.DefaultPanel === wmEnums.Panels.TEMP) { $('#accordion-panel-temp-body').addClass("show"); }
  740. else if (wmSettings.DefaultPanel === wmEnums.Panels.FILES) { $('#accordion-panel-file-body').addClass("show"); }
  741. else if (wmSettings.DefaultPanel === wmEnums.Panels.CONSOLE) { $('#accordion-panel-console-body').addClass("show"); }
  742. },
  743. SetShownPanel: function(p) {
  744. jsLog.Verbose("Set shown panel ("+p+")");
  745. if (p === wmEnums.Panels.STATUS) { $('#accordion-panel-status-body').removeClass("hide").addClass("show"); } else { $('#accordion-panel-status-body').removeClass("show").addClass("hide"); }
  746. if (p === wmEnums.Panels.CONTROLS) { $('#accordion-panel-controls-body').removeClass("hide").addClass("show"); } else { $('#accordion-panel-controls-body').removeClass("show").addClass("hide"); }
  747. if (p === wmEnums.Panels.TEMP) { $('#accordion-panel-temp-body').removeClass("hide").addClass("show"); } else { $('#accordion-panel-temp-body').removeClass("show").addClass("hide"); }
  748. if (p === wmEnums.Panels.FILES) { $('#accordion-panel-file-body').removeClass("hide").addClass("show"); } else { $('#accordion-panel-file-body').removeClass("show").addClass("hide"); }
  749. if (p === wmEnums.Panels.CONSOLE) { $('#accordion-panel-console-body').removeClass("hide").addClass("show"); } else { $('#accordion-panel-console-body').removeClass("show").addClass("hide"); }
  750. },
  751. SetGCommandChecksum: function() {
  752. cs = wmGCommandItem.CalcChecksum($('#text-gcommand').val());
  753. $('#checksum-gcommand-value').text(cs);
  754. jsLog.Debug("Set GCommand checksum ("+cs+")");
  755. },
  756. SetGCommandPresetList: function() {
  757. jsLog.Verbose("Fill GCommand preset list");
  758. let lip = document.getElementById("list-presets").getElementsByTagName("li");
  759. let i=0;
  760. if(lip.length === 1) {
  761. Object.keys(wmGCommands).forEach(key => {
  762. if(wmGCommands[key].GCode != "" && wmGCommands[key].Supported) {
  763. let gp = wmGCommands[key].GParams !== null ? wmTools.StringFormat(wmGCommands[key].GParams,wmGCommands[key].Values) : '';
  764. var lib = "<button type=\"button\" class=\"list-group-item list-group-item-action p-1\" onclick=\"WmButtons.GCommandSetPreset('"+wmGCommands[key].GCode+" "+gp+"')\">";
  765. lib += "<span class=\"h5\"><span class=\"badge badge-success mr-1\" style=\"width:100px;\">"+wmGCommands[key].GCode+" "+gp+"</span></span>";
  766. lib += wmGCommands[key].Description+"</button>";
  767. $('#list-presets').append(lib);
  768. i++;
  769. }
  770. });
  771. }
  772. jsLog.Verbose("Fill GCommand preset list completed ("+i+" items)");
  773. },
  774. SetWmSettingsControls: function() {
  775. jsLog.Verbose("Set settings controls fields");
  776. $('#set-default-panel').val(wmSettings.DefaultPanel);
  777. $('#set-auto-connect').bootstrapToggle(wmSettings.AutoConnect==true ? "on" : "off");
  778. $('#set-default-autotemp').val(wmSettings.AutoTempInterval);
  779. $('#set-default-tempunit').val(wmSettings.TempUnit.VALUE);
  780. $('#set-log-level').val(wmSettings.LogLevel);
  781. if(wmSettings.ConsoleDirection===wmEnums.ConsoleDirection.APPEND) {
  782. $('#set-trace-mode-prepend').prop('checked',false);
  783. $('#set-trace-mode-append').prop('checked',true);
  784. } else {
  785. $('#set-trace-mode-append').prop('checked',false);
  786. $('#set-trace-mode-prepend').prop('checked',true);
  787. }
  788. $('#set-log-symbol').val(wmSettings.SymbolMode);
  789. if(wmSettings.SymbolMode==='letter') { $('#div-log-symbol-icon').collapse('hide'); }
  790. else { $('#div-log-symbol-icon').collapse('show'); SetConsoleSymbolIcon(); }
  791. },
  792. SetAutotempDefault: function() {
  793. $('#auto-temp-interval').val(wmSettings.AutoTempInterval);
  794. }
  795. };
  796. $(document).ready(function () {
  797. $('.accordion-always-open').on('show.bs.collapse', function () { $(this).data('isShowing', true); });
  798. $('.accordion-always-open').on('hide.bs.collapse', function (event) {
  799. if (!$(this).data('isShowing')) { event.preventDefault(); }
  800. $(this).data('isShowing', false);
  801. });
  802. jsLog.Debug("Browser in use: "+wmTools.GetBrowser());
  803. jsLog.Debug("Browser sizes: "+wmTools.GetScreenSize());
  804. // AutoStar Actions
  805. WmAutostart.SetWmSettingsControls();
  806. WmAutostart.SetDefaultPanel();
  807. WmAutostart.SetGCommandPresetList();
  808. WmAutostart.SetAutotempDefault();
  809. // EVENTS: Buttons
  810. $('#btn-clear-console').click(function() { WmButtons.ConsoleListClear(); });
  811. $('#btn-export-console').click(function() { WmButtons.ConsoleListExport(); });
  812. $('#btn-file-proc').click(function(){ WmUpload.FileProcess(); });
  813. $('#btn-file-proc-cancel').click(function() { WmUpload.Cancel(); });
  814. $('#btn-file-upload').click(function(){ WmButtons.UploadSdFile(); });
  815. $('#btn-gcommand').click(function() { WmButtons.SendGcommand(); });
  816. $('#btn-get-sdcontent').click(function() { WmButtons.GetSdContentList(); });
  817. $('#btn-move-home-all').click(function() { WmButtons.SetPositionHome(this); });
  818. $('#btn-move-home-x').click(function() { WmButtons.SetPositionHome(this); });
  819. $('#btn-move-home-y').click(function() { WmButtons.SetPositionHome(this); });
  820. $('#btn-move-home-z').click(function() { WmButtons.SetPositionHome(this); });
  821. $('#btn-save-settings').click(function() { WmButtons.SaveSettings(); });
  822. $('#btn-sdfile-delete-modal').click(function() { WmButtons.DeleteSdSelected(); });
  823. $('#btn-sdfile-print-modal').click(function() { WmButtons.PrintSdSelected(); });
  824. $('#btn-set-sdinit').click(function() { WmButtons.SdInit(); });
  825. $('#btn-set-sdrelease').click(function() { WmButtons.SdRelease(); });
  826. $('#btn-wsconnect').click(function() { WmButtons.WsConnect(); });
  827. $('#btn-wsconnect-modal').click(function() { WmButtons.WsConnect(); });
  828. // EVENTS: Inputs fields
  829. $('#text-gcommand').keyup(function() { WmAutostart.SetGCommandChecksum(); });
  830. $('#text-gcommand').change(function() { WmAutostart.SetGCommandChecksum(); });
  831. $('#set-log-symbol').change(function() { WmConsole.SetMessageSymbol(); });
  832. $('#set-log-symbol-icon').change(function() { WmConsole.SetSymbolIcon(); });
  833. $('#file-upload').change( function() { WmControls.SetUpload(); });
  834. $('#set-auto-temp').change( function() { WmControls.SetAutoTemp(); });
  835. $('#auto-temp-interval').change( function() { WmControls.SetAutoTemp();} );
  836. $('#chart-show-extruder').change( function() { WmCharts.Temperatures.DisplayAxis(this); });
  837. $('#chart-show-bed').change( function() { WmCharts.Temperatures.DisplayAxis(this); });
  838. $('#fan-speed-range').on("change", function() { WmControls.SetFanSpeed(this.value); });
  839. $('#set-stepper-all').change( function() { WmControls.SetSteppers(this); });
  840. $('#set-stepper-e').change( function() { WmControls.SetSteppers(this); });
  841. $('#set-stepper-x').change( function() { WmControls.SetSteppers(this); });
  842. $('#set-stepper-y').change( function() { WmControls.SetSteppers(this); });
  843. $('#set-stepper-z').change( function() { WmControls.SetSteppers(this); });
  844. // Autorun onload
  845. WmConsole.Trace(new wmLogItem("Ready", wmEnums.WSMsgDirection.SENT, wmEnums.ConsoleLevels.SUCCESS));
  846. if(wmSettings.AutoConnect===true) { wmWebSoket.Connect(); }
  847. window.onload = function() {
  848. WmCharts.Init();
  849. WmCharts.Advance();
  850. };
  851. WmControls.Enable(WmButtonGroups.All());
  852. });