forked from chilipeppr/widget-axes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
auto-generated-widget.html
2876 lines (2610 loc) · 138 KB
/
auto-generated-widget.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>Widget / XYZ Axes v2</title>
<!-- ChiliPeppr is based on bootstrap CSS. -->
<link rel="stylesheet" type="text/css" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css">
<!--<link rel="stylesheet" type="text/css" href="//maxcdn.bootstrapcdn.com/bootswatch/3.3.6/cyborg/bootstrap.min.css"> -->
<!-- Customized version of require.js for ChiliPeppr. Please see require.js docs for how
ChiliPeppr's dependency system works as it's based on require.js. -->
<script type='text/javascript' src="//i2dcui.appspot.com/js/require.js"></script>
<style type='text/css'>
#com-chilipeppr-widget-axes2-body {
padding:2px;
}
#com-chilipeppr-widget-axes2-body .col {
padding:0;
}
#com-chilipeppr-widget-axes2-ftr .hilite {
background-color: #dff0d8;
}
#com-chilipeppr-widget-axes2-ftr .hiliteblue {
background-color: #d9edf7;
}
.col {
float:left;
}
.rotate90 {
display:block;
-webkit-transform: rotate(-90deg);
-webkit-font-smoothing: none;
-moz-transform: rotate(-90deg);
-ms-transform: rotate(-90deg);
-o-transform: rotate(-90deg);
transform: rotate(-90deg);
}
.btnincrements .btn {
font-size:9px;
padding:1px 3px;
}
.com-chilipeppr-xyz-pos {
padding:0 0 0 0px;
margin:0;
}
.com-chilipeppr-xyz-label {
padding:0;
margin:0;
}
.com-chilipeppr-xyz-label-well h2 {
text-align: center;
}
#com-chilipeppr-widget-axes2-body .com-chilipeppr-xyz-label-well {
background-color: white;
border-top-right-radius: 0;
border-bottom-right-radius: 0;
margin-bottom: 0px;
margin-right: 2px;
}
#com-chilipeppr-widget-axes2-body .com-chilipeppr-xyz-well {
overflow: hidden;
/* position: relative; */
margin-bottom: 0px;
padding: 3px 16px;
}
#com-chilipeppr-widget-axes2-body .com-chilipeppr-xyz-pos-well {
border-top-left-radius: 0;
border-bottom-left-radius: 0;
}
#com-chilipeppr-widget-axes2-body .com-chilipeppr-xyz-menu {
/* z-index: 2; */
position: absolute;
left: 3px;
top: 3px;
}
.com-chilipeppr-xyz-menu > .btn {
border:0;
}
.com-chilipeppr-xyz-dim {
position: absolute;
top:0px;
right:14px;
font-size:13px;
}
#com-chilipeppr-widget-axes2-ftr {
overflow-x: visible;
overflow-y: visible;
}
#com-chilipeppr-widget-axes2-ftr:focus {
background-color: #428bca;
}
#com-chilipeppr-widget-axes2-ftr.panel-primary {
background-color: #428bca;
}
.xyz-dimmed {
color:black; /*changed to black to offset cyborg theme*/
}
.xyz-limitswitch {
color:#804040;
font-size:11px;
}
.xyz-active {
color: black;
}
.flatbottom {
border-bottom-left-radius: 0;
border-bottom-right-radius: 0;
border-bottom: 0px solid red;
}
.flattop {
border-top-left-radius: 0;
border-top-right-radius: 0;
}
.flatleft {
border-top-left-radius: 0;
border-bottom-left-radius: 0;
}
.flatright {
border-bottom-right-radius: 0;
border-top-right-radius: 0;
}
.btn-nobg {
background:none;
border:none;
}
.btn-nobg:hover {
background:none;
border:none;
}
#com-chilipeppr-widget-axes2 .btnIconWarning {
color: #f0ad4e;
}
#com-chilipeppr-widget-axes2 .dbltall {
height:68px;
}
#com-chilipeppr-widget-axes2 .moveby {
position:absolute;
top:0;
left:0;
border:0px red solid;
}
#com-chilipeppr-widget-axes2 .jogincrements-small {
display:none;
}
/* View Small Mode */
#com-chilipeppr-widget-axes2.size-small .com-chilipeppr-xyz-label, #com-chilipeppr-widget-axes2.size-small .com-chilipeppr-xyz-pos {
font-size:16px;
}
#com-chilipeppr-widget-axes2.size-small #com-chilipeppr-widget-axes2-ftr, #com-chilipeppr-widget-axes2.size-small #com-chilipeppr-widget-axes2-ftr .btn {
font-size:9px;
}
#com-chilipeppr-widget-axes2.size-small .dbltall {
height:51px;
}
#com-chilipeppr-widget-axes2.size-small .jogincrements-normal {
display:none;
}
#com-chilipeppr-widget-axes2.size-small .jogincrements-small {
display:initial;
}
#com-chilipeppr-widget-axes2.size-small .moveby {
left:8px;
}
#com-chilipeppr-widget-axes2 .touchpad-overlay {
padding:0;
margin:0;
/* position:absolute; */
top: 1px;
left: 1px;
bottom: 1px;
height: 200px;
right: 1px;
background-color: #f5f5f5;
border: 2px solid transparent;
border-radius: 4px;
-webkit-box-shadow: 0 1px 1px rgba(0, 0, 0, .05);
box-shadow: 0 1px 1px rgba(0, 0, 0, .05);
/* z-index:2; */
display: flex;
align-items: center;
justify-content: center;
}
#com-chilipeppr-widget-axes2 .btnShowTouchJog {
font-size:10px;
height:67px;
}
#com-chilipeppr-widget-axes2.size-small .btnShowTouchJog {
font-size:10px;
height:50px;
}
#com-chilipeppr-widget-axes2-machinecoords {
padding:2px;
}
#com-chilipeppr-widget-axes2-machinecoords .col {
padding:0;
}
#com-chilipeppr-widget-axes2-machinecoords .com-chilipeppr-xyz-label-well {
background-color: white;
border-top-right-radius: 0;
border-bottom-right-radius: 0;
margin-bottom: 0px;
margin-right: 2px;
}
#com-chilipeppr-widget-axes2-machinecoords .com-chilipeppr-xyz-well {
overflow: hidden;
/* position: relative; */
margin-bottom: 0px;
padding: 3px 16px;
}
#com-chilipeppr-widget-axes2-machinecoords .com-chilipeppr-xyz-pos-well {
border-top-left-radius: 0;
border-bottom-left-radius: 0;
}
#com-chilipeppr-widget-axes2-machinecoords .com-chilipeppr-xyz-menu {
/* z-index: 2; */
position: absolute;
left: 3px;
top: 3px;
}
.jogincrements-horiz button {
height: 26px;
}
#com-chilipeppr-widget-axes2 .xyz-pencil {
position:absolute;
top:1px;
left:1px;
}
#com-chilipeppr-widget-axes2 .xyz-number {
position:absolute;
top:-4px;
left:28px;
width:70%;
z-index:10;
}
</style>
<script type='text/javascript'>
//<![CDATA[
/* global cprequire_test macro chilipeppr THREE $ requirejs cprequire cpdefine chilipeppr */
// Test this element. This code is auto-removed by the chilipeppr.load()
cprequire_test(["inline:com-chilipeppr-widget-axes2"], function (xyz) {
console.log("test running of " + xyz.id);
//sp.init("192.168.1.7");
//xyz.initAs3dPrinting();
xyz.init();
xyz.showBody("com-chilipeppr-widget-axes2");
xyz.currentUnits = 'mm'
// load the WCS widget to left
//$('body').css('margin-left', '80px');
var wrapDiv = $('<div class="testdiv" style="margin-left:80px;position:relative;">');
$('#com-chilipeppr-widget-axes2').wrap(wrapDiv);
// test out planner resume/pause
var testPauseResume = function () {
setTimeout(function () {
chilipeppr.publish('/com-chilipeppr-interface-cnccontroller/plannerpause', "");
}, 5000);
setTimeout(function () {
chilipeppr.publish('/com-chilipeppr-interface-cnccontroller/plannerresume', "");
}, 10000);
setTimeout(function () {
chilipeppr.publish('/com-chilipeppr-interface-cnccontroller/plannerpause', "");
}, 15000);
setTimeout(function () {
chilipeppr.publish('/com-chilipeppr-interface-cnccontroller/plannerresume', "");
}, 20000);
};
var testAxesValUpdates = function () {
setTimeout(function () {
chilipeppr.publish("/com-chilipeppr-interface-cnccontroller/axes", {
x: 0.005,
y: 10.46,
z: 0.304,
a: 0,
type: "work",
mpo: {
x: 0.005,
y: 10.46,
z: 0.304,
a: 0,
type: "machine"
}
});
}, 1000);
setTimeout(function () {
chilipeppr.publish("/com-chilipeppr-interface-cnccontroller/axes", {
x: 192,
y: 0.028,
z: 0.01,
a: 0,
type: "work"
});
}, 2000);
setTimeout(function () {
chilipeppr.publish("/com-chilipeppr-interface-cnccontroller/axes", {
x: -3288.73,
y: -0,
z: 1.12,
a: null,
type: "work"
});
}, 3000);
setTimeout(function () {
chilipeppr.publish("/com-chilipeppr-interface-cnccontroller/axes", {
x: 940.5744,
y: null,
z: 1.12,
a: null,
type: "work"
});
}, 4000);
setTimeout(function () {
chilipeppr.publish("/com-chilipeppr-interface-cnccontroller/axes", {
x: 0.574,
y: 32.424,
z: -3.424,
a: null,
type: "work"
});
}, 5000);
setTimeout(function () {
chilipeppr.publish("/com-chilipeppr-interface-cnccontroller/axes", {
x: null,
y: 132.424,
z: -3.424,
a: null,
type: "work"
});
}, 5000);
};
// test units change
var testUnitsChange = function () {
setTimeout(function () {
chilipeppr.publish("/com-chilipeppr-interface-cnccontroller/units", "inch");
}, 1000);
setTimeout(function () {
chilipeppr.publish("/com-chilipeppr-interface-cnccontroller/units", "mm");
}, 5000);
};
// test units change
var testCoordsChange = function () {
setTimeout(function () {
var c = {
coord: "G54",
coordNum: 54
};
chilipeppr.publish("/com-chilipeppr-interface-cnccontroller/coords", c);
}, 1000);
setTimeout(function () {
var c = {
coord: "G55",
coordNum: 55
};
chilipeppr.publish("/com-chilipeppr-interface-cnccontroller/coords", c);
}, 5000);
};
//testPauseResume();
testAxesValUpdates();
//testUnitsChange();
testCoordsChange();
/*
setTimeout(function() {
console.log("setting up alternate keystrokes");
$('#com-chilipeppr-widget-axes2-ftr').keydown(function(evt) {
var e = $.Event('keydown');
if (evt.which == 50) {
// the #2 key
// mimic down arrow being pressed
e.which= 40;
} else if (evt.which == 56) {
// the #8 key
// mimic up arrow being pressed
e.which= 38; // enter
}
console.log("artificial event:", e);
if (e.which > 0) {
evt.preventDefault();
// fire off fake event as if key was pressed down
$('#com-chilipeppr-widget-axes2-ftr').trigger(e);
return false;
}
});
}, 5000);
*/
$('body').css("padding", "20px");
} /*end_test*/ );
cpdefine("inline:com-chilipeppr-widget-axes2", ["chilipeppr_ready", "jquerycookie"], function () {
return {
id: "com-chilipeppr-widget-axes2",
url: "http://raw.githubusercontent.com/reecem7/widget-axes2/master/auto-generated-widget.html", // The final URL of the working widget as a single HTML file with CSS and Javascript inlined. You can let runme.js auto fill this if you are using Cloud9.
fiddleurl: "http://ide.c9.io/reecem7/widget-axes2", // The edit URL. This can be auto-filled by runme.js in Cloud9 if you'd like, or just define it on your own to help people know where they can edit/fork your widget
githuburl: "http://github.com/reecem7/widget-axes2", // The backing github repo
testurl: "http://widget-axes2-reecem7.c9users.io/widget.html", // The standalone working widget so can view it working by itself
name: "Widget / XYZ Axes v2",
desc: "The Axes widget shows the XYZA values of the axes of your CNC controller. It also enables you to jog, home, change units, and change Work Coordinate Systems.",
publish: {},
subscribe: {},
foreignPublish: {
'/com-chilipeppr-widget-serialport/send': "We publish to the serial port Gcode jog commands"
},
foreignSubscribe: {
"/com-chilipeppr-interface-cnccontroller/axes": "We want X,Y,Z,A,MX,MY,MZ,MA axis updates.",
"/com-chilipeppr-interface-cnccontroller/coords": "Track which is active: G54, G55, etc.",
"/com-chilipeppr-interface-cnccontroller/plannerpause": "We need to know when to pause sending jog cmds.",
"/com-chilipeppr-interface-cnccontroller/plannerresume": "We need to know when to resume jog cmds.",
"/com-chilipeppr-interface-cnccontroller/units": "Deprecated. Not listening to this anymore. See next.",
'/com-chilipeppr-widget-3dviewer/unitsChanged': "Listenting to see if the 3D Viewer is telling us that the user Gcode is in a specific coordinate and then just assuming we will only be sent axes coordinate updates in that unit. Not using /com-chilipeppr-interface-cnccontroller/units anymore."
},
init: function () {
// Do UI setup
this.initBody();
this.btnSetup();
this.menuSetup();
this.jogSetup();
this.pencilSetup();
this.forkSetup();
this.toolbarSetup();
// Subscribe to the signal published from the specific controller implementing the generic interface
// for CNC controllers that normalizes the XYZ Axis updates so we don't have to worry about
// the specific implementation
chilipeppr.subscribe("/com-chilipeppr-interface-cnccontroller/axes", this, this.updateAxesFromStatus);
// Update units if we get a notification published to us
chilipeppr.subscribe("/com-chilipeppr-interface-cnccontroller/units", this, this.updateUnitsFromStatus);
chilipeppr.subscribe('/com-chilipeppr-widget-3dviewer/unitsChanged', this, this.updateUnitsFromStatus);
// in case we didn't get loaded fast enough, thus we never got the /unitsChanged event from the 3d viewer, we better double check here and fire off a request just to cover all our bases
chilipeppr.subscribe('/com-chilipeppr-widget-3dviewer/recvUnits', this, this.updateUnitsFromStatus);
chilipeppr.publish('/com-chilipeppr-widget-3dviewer/requestUnits', "");
// Subscribe to the generic interface signals of plannerresume/plannerpause so we know when to slow
// down on our sending of gcode commands when jogging.
// If a different controller is implemented, they can send on these signals
// and abstract away the specific hardware details from us so this widget is reusable
chilipeppr.subscribe("/com-chilipeppr-interface-cnccontroller/plannerpause", this, this.onPlannerPause);
chilipeppr.subscribe("/com-chilipeppr-interface-cnccontroller/plannerresume", this, this.onPlannerResume);
// subscribe to the CNC controller broadcasting what
// layer system we're in
chilipeppr.subscribe('/com-chilipeppr-interface-cnccontroller/coords', this.onCoordsUpdate.bind(this));
// setup onconnect pubsub event
/*
chilipeppr.subscribe("/com-chilipeppr-widget-serialport/ws/onconnect", this, function (msg) {
console.log("got onconnect so will query for status");
});
*/
// setup recv pubsub event
// this is when we receive data in a per line format from the serial port
/*
chilipeppr.subscribe("/com-chilipeppr-widget-serialport/recvline", this, function (msg) {
this.onRecvCmd(msg);
});
*/
// setup DOM elements for the Axes in the UI
this.setupAxes();
// setup controller specific init items
//this.initControllerSpecific();
// setup cookie based UI settings
this.setupUiFromCookie();
this.setupTouchArea();
this.setupShowHideTouchBtn();
this.setupShowHideWcsBtn();
var that = this;
console.log(this.name + " done loading.");
},
pencilSetup: function() {
// add mouseover events to DRO numbers
//$('#com-chilipeppr-widget-axes2-x').mouseover(this.pencilOnMouseover.bind(this));
//$('#com-chilipeppr-widget-axes2-x').mouseout(this.pencilOnMouseout.bind(this));
$('#com-chilipeppr-widget-axes2-x').hover(this.pencilOnMouseover.bind(this), this.pencilOnMouseout.bind(this));
$('#com-chilipeppr-widget-axes2-y').hover(this.pencilOnMouseover.bind(this), this.pencilOnMouseout.bind(this));
$('#com-chilipeppr-widget-axes2-z').hover(this.pencilOnMouseover.bind(this), this.pencilOnMouseout.bind(this));
$('#com-chilipeppr-widget-axes2-a').hover(this.pencilOnMouseover.bind(this), this.pencilOnMouseout.bind(this));
},
pencilOnMouseover: function(evt) {
console.log("got pencilOnMouseover. evt:", evt);
var tgtEl = $(evt.currentTarget);
var btn = $('<button class="btn btn-xs btn-default xyz-pencil"><span class="glyphicon glyphicon-pencil"></span></button>');
btn.click(this.pencilClick.bind(this));
tgtEl.find('.com-chilipeppr-xyz-pos-well').prepend(btn);
// attach descriptive popoover
btn.popover({
animation: true,
delay: 500,
placement: "auto",
container: "body",
trigger: "hover",
title: "Enter a new coordinate",
content: "Move to a new coordinate in this axis by modifying the value and hitting the enter key."
});
},
pencilOnMouseout: function(evt) {
console.log("got pencilOnMouseout. evt:", evt);
var tgtEl = $(evt.currentTarget);
this.pencilHide(tgtEl);
},
pencilClick: function(evt) {
console.log("got pencilClick. evt:", evt);
var tgtEl = $(evt.currentTarget);
var txt = $('<input type="number" class="form-control xyz-number" placeholder="Enter New Coord">');
txt.keyup(this.pencilKeypress.bind(this));
var posEl = tgtEl.parents('.com-chilipeppr-xyz-pos-well');
console.log("lastCoords:", this.lastCoords, "lastVal:", this.lastVal);
var val = this.lastVal[posEl.data('axis')];
txt.val(val);
posEl.prepend(txt);
txt.focus();
// hide popover
posEl.find('button').popover('hide');
},
pencilCtr: 0,
pencilKeypress: function(evt) {
console.log("got pencilKeypress. evt:", evt);
var tgtEl = $(evt.currentTarget);
var posEl = tgtEl.parents('.com-chilipeppr-xyz-pos-well');
var axis = posEl.data('axis').toUpperCase();
console.log("axis:", axis);
// see if return key
if (evt.keyCode == 13) {
console.log("enter key hit");
// send gcode
var gcode = "G90 G0 " + axis + tgtEl.val();
console.log("about to send gcode:", gcode);
chilipeppr.publish('/com-chilipeppr-widget-serialport/jsonSend', {
D: gcode,
Id:"axes" + this.pencilCtr++
});
this.pencilHide(tgtEl.parents('.com-chilipeppr-xyz-pos-well'));
} else if (evt.keyCode == 27) {
console.log("ESC key hit");
this.pencilHide(tgtEl.parents('.com-chilipeppr-xyz-pos-well'));
}
},
pencilHide: function(tgtEl) {
console.log("pencilHide");
// hide popover
tgtEl.find('button').popover('hide');
//tgtEl.popover('hide');
tgtEl.find('.xyz-pencil').remove();
tgtEl.find('.xyz-number').remove();
},
initAs3dPrinting: function () {
// by default we'll show the A/B/C axes
$('#com-chilipeppr-widget-axes2-a').removeClass("hidden");
$('#com-chilipeppr-widget-axes2-b').removeClass("hidden");
// change labels
$('#com-chilipeppr-widget-axes2-a .com-chilipeppr-xyz-label').text("E0");
$('#com-chilipeppr-widget-axes2-b .com-chilipeppr-xyz-label').text("E1");
// change units
$('#com-chilipeppr-widget-axes2-a .com-chilipeppr-xyz-dim').text("mm");
$('#com-chilipeppr-widget-axes2-b .com-chilipeppr-xyz-dim').text("mm");
},
setupShowHideWcsBtn: function () {
var btnEl = $("#com-chilipeppr-widget-axes2 .btnToggleShowWcs");
btnEl.click(this.toggleWcs.bind(this));
btnEl.popover();
chilipeppr.load(
"#com-chilipeppr-widgetholder-wcs",
//"http://fiddle.jshell.net/Danal/4ete4691/show/light/",
"http://raw.githubusercontent.com/chilipeppr/widget-wcs/master/auto-generated-widget.html",
function () {
cprequire(["inline:com-chilipeppr-widget-wcs"], function (wcs) {
console.log("test running of " + wcs.id);
wcs.init();
});
});
},
toggleWcs: function (evt) {
$("#com-chilipeppr-widget-axes2 .btnToggleShowWcs").popover('hide');
var wcsEl = $('#com-chilipeppr-widgetholder-wcs');
if (wcsEl.hasClass("hidden")) {
wcsEl.removeClass("hidden");
$('#com-chilipeppr-widget-axes2 .btnToggleShowWcs').addClass("active");
} else {
wcsEl.addClass("hidden");
$('#com-chilipeppr-widget-axes2 .btnToggleShowWcs').removeClass("active");
}
},
setupShowHideTouchBtn: function () {
$("#com-chilipeppr-widget-axes2 .btnToggleShowTouchJog").popover();
//$( window ).resize(this.showHideTouchBtn.bind(this));
this.showHideTouchBtn();
$(window).resize(this.showHideTouchBtn.bind(this));
},
showHideTouchBtn: function () {
//console.log("should we show or hide the touch btn");
var btnEl = $("#com-chilipeppr-widget-axes2 .btnShowTouchJog");
var btnParentWidth = btnEl.parent().parent().width();
var widgetWidth = $("#com-chilipeppr-widget-axes2").width();
console.log("btnParentWidth:", btnParentWidth, "widgetWidth:", widgetWidth);
//console.log("btnEl:", btnEl, "parent:", btnEl.parent(), "btnEl.parent().width()", btnEl.parent().width(), "btnEl.parent().parent().width()", btnEl.parent().parent().width());
//console.log("btnEl.parent().parent().width()", btnEl.parent().parent().width(), "btnEl.parent().parent().width()", btnEl.parent().parent().parent().parent().width());
if (btnParentWidth > widgetWidth) {
console.log("it appears the btn is being clipped");
btnEl.css('visibility', 'hidden');
btnEl.addClass("hidden");
//apply class1
} else {
//apply class2
btnEl.css('visibility', 'visible');
btnEl.removeClass("hidden");
console.log("it appears the btn is NOT being clipped");
}
},
canvas: null,
el: null,
ctx: null,
setupTouchArea: function () {
this.canvas = $('#com-chilipeppr-widget-axes2 .touchpad-overlay canvas');
var tpad = $('#com-chilipeppr-widget-axes2 .touchpad-overlay');
console.log("tpad:", tpad);
/*
this.canvas.width(tpad.width());
this.canvas.height(tpad.height());
this.canvas.prop({
width: tpad.width(),
height: tpad.height()
});
*/
this.el = $('#com-chilipeppr-widget-axes2 .touchpad-overlay canvas')[0];
this.canvasResize();
//this.ctx = $('#com-chilipeppr-widget-axes2 .touchpad-overlay canvas')[0].getContext("2d");
var that = this;
tpad.bind("touchstart", function (e) {
//console.log("about to dish touchstart evt:", e);
that.handleStart(e);
});
tpad.bind("touchend", this.handleEnd.bind(this));
tpad.bind("touchcancel", this.handleCancel.bind(this));
tpad.bind("touchleave", this.handleEnd.bind(this));
tpad.bind("touchmove", this.handleMove.bind(this));
/*
tpad.bind('touchstart', function(e){
console.log("got touch/mouse evt:", e);
that.drawCircle(ctx, e);
});
tpad.bind('touchend', function(e){
console.log("got touch/mouse evt:", e);
that.drawCircle(ctx, e);
});
*/
// setup toggle buttons
$('#com-chilipeppr-widget-axes2 .btnToggleShowTouchJog').click(this.toggleTouchJog.bind(this));
$(window).resize(this.canvasResize.bind(this));
//this.toggleTouchJog();
// scrolling
tpad.bind('mousewheel DOMMouseScroll', this.onScroll.bind(this));
// mouse movements
tpad.bind("mousedown", this.onMouseDown.bind(this));
tpad.bind("mousemove", this.onMouseMove.bind(this));
tpad.bind("mouseup", this.onMouseUp.bind(this));
this.log("touch area setup");
},
toggleTouchJog: function () {
$('#com-chilipeppr-widget-axes2 .btnToggleShowTouchJog').popover('hide');
var tpad = $('#com-chilipeppr-widget-axes2 .touchpad-overlay');
if (tpad.hasClass("hidden")) {
tpad.removeClass("hidden");
this.canvasResize();
$('#com-chilipeppr-widget-axes2 .btnToggleShowTouchJog').addClass("active");
} else {
tpad.addClass("hidden");
$('#com-chilipeppr-widget-axes2 .btnToggleShowTouchJog').removeClass("active");
}
},
canvasResize: function () {
console.log("touchpad resizing");
var tpad = $('#com-chilipeppr-widget-axes2 .touchpad-overlay');
this.canvas.width(tpad.width());
this.canvas.height(tpad.height());
this.canvas.prop({
width: tpad.width(),
height: tpad.height()
});
//this.el = $('#com-chilipeppr-widget-axes2 .touchpad-overlay canvas')[0];
this.ctx = $('#com-chilipeppr-widget-axes2 .touchpad-overlay canvas')[0].getContext("2d");
this.drawText();
},
drawText: function () {
var x = this.el.width / 2;
var y = this.el.height / 2;
this.ctx.font = '14pt "Helvetica Neue",Helvetica,Arial,sans-serif';
this.ctx.textAlign = 'center';
this.ctx.fillStyle = 'silver';
this.ctx.fillText('Touch/Mouse/Scroll', x, y - 8);
this.ctx.fillText('Jog Area', x, y + 8);
},
isMouseDown: false,
mouseLastOffset: {
x: 0,
y: 0
},
onMouseDown: function (evt) {
console.log("onMouseDown:", evt);
this.isMouseDown = true;
//inside my mouse events handler:
var target = evt.target || evt.srcElement,
rect = target.getBoundingClientRect(),
offsetX = evt.clientX - rect.left,
offsetY = evt.clientY - rect.top;
anOffsetX = offsetX;
anOffsetY = offsetY;
console.log("mouse anOffsetX:", anOffsetX, "anOffsetY:", anOffsetY);
this.mouseLastOffset.x = anOffsetX; //evt.offsetX;
this.mouseLastOffset.y = anOffsetY; //evt.offsetY;
console.log("mouseLastOffset:", this.mouseLastOffset);
this.canvas.css('cursor', 'default');
var ctx = this.ctx;
ctx.beginPath();
ctx.arc(this.mouseLastOffset.x, this.mouseLastOffset.y, 10, 0, 2 * Math.PI, true); // a circle at the start
ctx.fillStyle = 'rgba(0,0,255,0.1)';
ctx.strokeStyle = 'rgba(0,0,0,0)';
ctx.lineWidth = 0;
ctx.fill();
ctx.stroke();
},
onMouseMove: function (evt) {
if (!this.isMouseDown) {
return;
}
console.log("onMouseMove:", evt);
var target = evt.target || evt.srcElement,
rect = target.getBoundingClientRect(),
offsetX = evt.clientX - rect.left,
offsetY = evt.clientY - rect.top;
anOffsetX = offsetX;
anOffsetY = offsetY;
console.log("mouse anOffsetX:", anOffsetX, "anOffsetY:", anOffsetY);
var deltax = anOffsetX - this.mouseLastOffset.x;
var deltay = (anOffsetY - this.mouseLastOffset.y) * -1;
console.log("deltax:", deltax, "deltay", deltay);
var newpos = {
x: anOffsetX,
y: anOffsetY
};
//this.sendMove(0, this.mouseLastOffset, {x:deltax, y:deltay});
this.sendMove(0, this.mouseLastOffset, newpos);
var ctx = this.ctx;
ctx.moveTo(this.mouseLastOffset.x, this.mouseLastOffset.y);
ctx.lineTo(newpos.x, newpos.y);
ctx.lineWidth = 8;
ctx.strokeStyle = 'rgba(0,0,255,0.1)';
ctx.stroke();
this.mouseLastOffset = newpos;
},
onMouseUp: function (evt) {
console.log("onMouseUp:", evt);
this.isMouseDown = false;
var target = evt.target || evt.srcElement,
rect = target.getBoundingClientRect(),
offsetX = evt.clientX - rect.left,
offsetY = evt.clientY - rect.top;
anOffsetX = offsetX;
anOffsetY = offsetY;
console.log("mouse anOffsetX:", anOffsetX, "anOffsetY:", anOffsetY);
var ctx = this.ctx;
ctx.lineWidth = 14;
ctx.fillStyle = 'rgba(0,0,255,0.2)';
ctx.beginPath();
ctx.moveTo(this.mouseLastOffset.x, this.mouseLastOffset.y);
ctx.lineTo(anOffsetX, anOffsetY);
ctx.fillRect(anOffsetX - 9, anOffsetY - 9, 18, 18); // and a square at the end
this.sendDone();
this.fadeCanvas();
},
scrollPrev: {
x: 0,
y: 0
},
scrollFadeTimer: null,
scrollLastPosDir: "up",
onScroll: function (evt) {
console.log("onScroll:", evt.originalEvent); //, evt.originalEvent.wheelDelta);
evt.preventDefault();
// fix for firefox. detect DOMMouseScroll
if ("type" in evt && evt.type.match(/^D/)) {
console.log("detected firefox.");
evt.originalEvent.wheelDelta = evt.originalEvent.detail * -10;
evt.originalEvent.wheelDeltaX = 0;
evt.originalEvent.wheelDeltaY = 0;
if (evt.originalEvent.axis == 2) {
// left/right scroll
evt.originalEvent.wheelDeltaY = evt.originalEvent.wheelDelta;
} else {
evt.originalEvent.wheelDeltaX = evt.originalEvent.wheelDelta;
}
}
// see if user changed positions. if so, cancel all moves.
//if (evt.originalEvent.wheelDelta /120 > 0) {
if (evt.originalEvent.wheelDelta > 0) {
console.log('scrolling up !');
if (this.scrollLastPosDir != "up") {
this.sendDone();
this.scrollLastPosDir = "up";
}
} else {
console.log('scrolling down !');
if (this.scrollLastPosDir != "dn") {
this.sendDone();
this.scrollLastPosDir = "dn";
}
}
var newpos = {
x: evt.originalEvent.wheelDeltaX,
y: evt.originalEvent.wheelDeltaY
};
// divide by 10 to slow down to sort of match touch/mouse
//newpos.x = newpos.x / 10;
//newpos.y = newpos.y / 10;
this.sendMove(0, {
x: 0,
y: 0
}, {
x: newpos.x / 10,
y: newpos.y / 10
});
var x = this.el.width / 2;
var y = this.el.height / 2;
var ctx = this.ctx;
ctx.beginPath();
var moveTo = {
x: this.scrollPrev.x + x,
y: this.scrollPrev.y + y
};
moveTo = {
x: x,
y: y
};
console.log("moveTo:", moveTo);
ctx.moveTo(moveTo.x, moveTo.y);
var lineTo = {
x: moveTo.x + newpos.x,
y: moveTo.y + newpos.y
};
// logarithmically adjust
//var xSign = -1 ? lineTo.x < 0 : 1;
//lineTo.x = Math.log(Math.abs(lineTo.x)) * xSign;
if (newpos.y !== 0) {
var ySign = newpos.y < 0 ? -1 : 1;
lineTo.y = (Math.log(Math.abs(newpos.y)) * ySign * 25) + y;
}
if (newpos.x !== 0) {
var xSign = newpos.x < 0 ? -1 : 1;
lineTo.x = (Math.log(Math.abs(newpos.x)) * xSign * 25) + x;
}
console.log("lineTo:", lineTo);
ctx.lineTo(lineTo.x, lineTo.y);
ctx.lineWidth = 32;
ctx.strokeStyle = 'rgba(0,0,0,0.025)';
ctx.stroke();
this.scrollPrev.x += newpos.x;
this.scrollPrev.y += newpos.y;
var that = this;
if (this.scrollFadeTimer) {
clearTimeout(this.scrollFadeTimer);
that.scrollPrev.x = 0;
that.scrollPrev.y = 0;
}
this.scrollFadeTimer = setTimeout(function () {
that.scrollPrev.x = 0;
that.scrollPrev.y = 0;
that.ctx.clearRect(0, 0, that.el.width, that.el.height);
that.drawText();
}, 100);
//this.fadeCanvas();
},
ongoingTouches: [], // new Array;
start: {
x: 0,
y: 0
},
inZMode: false,
handleStart: function (evt) {
console.log("touchstart. evt:", evt);
var el = this.el; //= document.getElementsByTagName("canvas")[0];
var ctx = this.ctx; // el.getContext("2d");
var touches = evt.originalEvent.changedTouches;
var offset = this.findPos(el);
for (var i = 0; i < touches.length; i++) {
if (touches[i].clientX - offset.x > 0 && touches[i].clientX - offset.x < parseFloat(el.width) && touches[i].clientY - offset.y > 0 && touches[i].clientY - offset.y < parseFloat(el.height)) {
evt.preventDefault();
this.log("touchstart:" + i + "...");
this.ongoingTouches.push(this.copyTouch(touches[i]));
var color = this.colorForTouch(touches[i]);
ctx.beginPath();
ctx.arc(touches[i].clientX - offset.x, touches[i].clientY - offset.y, 14, 0, 2 * Math.PI, false); // a circle at the start
ctx.fillStyle = color;
ctx.fill();
this.log("touchstart:" + i + ".");
}
}
},
//divider: 10,
sendCtr: 0,
sendMove: function (touchid, prevpos, newpos) {
var deltax = newpos.x - prevpos.x;
var deltay = newpos.y - prevpos.y;
if (deltax === 0 && deltay === 0) {
console.log("no move happened. returning.");
return;
}
var gcode = "G91 G0 ";
if (deltax !== 0) {
gcode += "X" + (deltax * this.accelBaseval).toFixed(3) + " ";
}
if (deltay !== 0) {
gcode += "Y" + (deltay * this.accelBaseval * -1).toFixed(3) + " ";
}
gcode += "\nG90\n";
//chilipeppr.publish("/com-chilipeppr-widget-serialport/send", gcode);
var jsonSend = {
D: gcode,
Id: "jog" + this.sendCtr
};
chilipeppr.publish("/com-chilipeppr-widget-serialport/jsonSend", jsonSend);
this.sendCtr++;
if (this.sendCtr > 999999) this.sendCtr = 0;
},
sendDone: function () {
chilipeppr.publish("/com-chilipeppr-widget-serialport/send", "!\n%\n");
setTimeout(function () {
chilipeppr.publish("/com-chilipeppr-widget-serialport/send", "%\n");
}, 200);
},
sendMoveZ: function (touchid, prevpos, newpos) {