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