-
Notifications
You must be signed in to change notification settings - Fork 22
/
grbl_player_main.pas
3074 lines (2773 loc) · 100 KB
/
grbl_player_main.pas
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
unit grbl_player_main;
// CNC-Steuerung für GRBL-JOG-Platine mit GRBL 0.8c/jog.2 Firmware
// oder GRBL 0.9j mit DEFINE GRBL115
interface
uses
Dialogs, Math, StdCtrls, ComCtrls, ToolWin, Buttons, ExtCtrls, ImgList,
StdActns, Classes, ActnList, Menus, GraphUtil, StrUtils, Windows,
Graphics, Messages, Spin, FileCtrl, Grids, Registry, ShellApi, MMsystem,
VFrames, ExtDlgs, XPMan, CheckLst, drawing_window, glscene_view, GLColor,
ValEdit, System.ImageList, System.Actions, FTDItypes, deviceselect, grbl_com,
Vcl.ColorGrd, Vcl.Samples.Gauges, System.UItypes, app_defaults, DateUtils,
TouchButton, Forms, GLScene, GLFullScreenViewer, System.IniFiles, SysUtils,
Vcl.Touch.Keyboard, GLCrossPlatform, GLBaseClasses, Controls;
const
c_ProgNameStr: String = 'GRBLize ';
c_VerStr: String = '1.5d';
c_unloadATCstr: String = 'M8';
c_loadATCstr: String = 'M9';
c_Grbl_VerStr: String = 'for GRBL 0.9 and 1.1 ';
// Jogging Controll:
// c_JogDealy
// MouseDown --> v(50ms) 6 --> JogStep
// v(50ms) 5
// ...
// v(50ms) 1
// 0 --> JogStep or JogContinue
// (50ms> -1 --> Idle (wait for MouseDown)
// ^(50ms> -2 --> MouseDown blocked
// MouseUp --> ^(50ms> -3 --> MouseDown blocked
c_JogDelay: integer = 6; // delay start jogging in [50ms]
c_CntrDelay: integer = 6; // delay of second buttom level in [50ms]
type
TPOVControl = record // Joystick control
up,down,left,right:boolean;
raw: Integer;
active: Boolean;
end;
T3dFloat = record
X: Double;
Y: Double;
Z: Double;
C: Double;
end;
TForm1 = class(TForm)
MainMenu1: TMainMenu;
File1: TMenuItem;
FileNewItem: TMenuItem;
FileOpenItem: TMenuItem;
FileSaveItem: TMenuItem;
FileSaveAsItem: TMenuItem;
FileExitItem: TMenuItem;
Edit0: TMenuItem;
CutItem: TMenuItem;
CopyItem: TMenuItem;
PasteItem: TMenuItem;
Help1: TMenuItem;
HelpAboutItem: TMenuItem;
ActionList1: TActionList;
FileNew1: TAction;
FileOpen1: TAction;
FileSave1: TAction;
FileSaveAs1: TAction;
FileExit1: TAction;
EditCut1: TEditCut;
EditCopy1: TEditCopy;
EditPaste1: TEditPaste;
HelpAbout1: TAction;
ImageList1: TImageList;
BtnRescan: TButton;
TimerDraw: TTimer;
BtnClose: TButton;
XPManifest1: TXPManifest;
N7: TMenuItem;
OpenFileDialog: TOpenDialog;
OpenJobDialog: TOpenDialog;
GerberImportDialog: TOpenDialog;
SaveJobDialog: TSaveDialog;
ColorDialog1: TColorDialog;
PageControl1: TPageControl;
TabSheetPens: TTabSheet;
Label7: TLabel;
SgPens: TStringGrid;
TabSheetGroups: TTabSheet;
TabSheetDefaults: TTabSheet;
TabSheetRun: TTabSheet;
SgGrblSettings: TStringGrid;
Bevel3: TBevel;
Label11: TLabel;
BtnRunJob: TSpeedButton;
CheckEndPark: TCheckBox;
MposX: TLabel;
MposY: TLabel;
MposZ: TLabel;
ComboBox1: TComboBox;
TabSheet1: TTabSheet;
SgFiles: TStringGrid;
Label1: TLabel;
Label5: TLabel;
SgBlocks: TStringGrid;
Label12: TLabel;
Bevel1: TBevel;
Label2: TLabel;
WindowMenu1: TMenuItem;
ShowDrawing1: TMenuItem;
Show3DPreview1: TMenuItem;
SgJobDefaults: TStringGrid;
MemoComment: TMemo;
Label3: TLabel;
TimerStatus: TTimer;
BtnEmergStop: TBitBtn;
PanelBusy: TPanel;
PanelRun: TPanel;
PanelReady: TPanel;
PanelAlarm: TPanel;
PanelHold: TPanel;
BtnLoadGrblSetup: TSpeedButton;
BtnSaveGrblSetup: TSpeedButton;
TimerBlink: TTimer;
Label23: TLabel;
ProgressBar1: TProgressBar;
SgAppDefaults: TStringGrid;
Label25: TLabel;
Label26: TLabel;
Label28: TLabel;
Bevel8: TBevel;
LabelWorkX: TLabel;
LabelWorkY: TLabel;
LabelWorkZ: TLabel;
Label4: TLabel;
ComboBoxGtip: TComboBox;
ComboBoxGdia: TComboBox;
Bevel7: TBevel;
BtnRunGcode: TSpeedButton;
CheckTLCprobe: TCheckBox;
LabelTableX: TLabel;
LabelTableY: TLabel;
LabelTableZ: TLabel;
Label31: TLabel;
Bevel6: TBevel;
Bevel9: TBevel;
PanelZdone: TPanel;
LabelHintZ: TLabel;
ToolBar1: TToolBar;
ToolButton9: TToolButton;
ToolButton1: TToolButton;
ToolButton2: TToolButton;
CheckBoxSim: TCheckBox;
BtnCancel: TSpeedButton;
BtnConnect: TBitBtn;
PanelYdone: TPanel;
PanelXdone: TPanel;
BtnZeroAll: TSpeedButton;
Label48: TLabel;
GerberImport1: TMenuItem;
LabelHintZ2: TLabel;
Memo1: TMemo;
Label13: TLabel;
Bevel4: TBevel;
PanelAlive: TPanel;
EditFirstToolDia: TEdit;
CheckToolChange: TCheckBox;
CheckUseATC2: TCheckBox;
sgATC: TStringGrid;
LabelATCmsg: TLabel;
Label24: TLabel;
PopupMenuATC: TPopupMenu;
pu_MovetoATCslot: TMenuItem;
pu_LoadFromATCslot: TMenuItem;
N1: TMenuItem;
pu_ProbeToolLengthRef: TMenuItem;
pu_ProbetoolLengthComp: TMenuItem;
BtnRunTool: TSpeedButton;
Label14: TLabel;
Label21: TLabel;
Label22: TLabel;
Action1: TAction;
PopupMenuShape: TPopupMenu;
ms_contour: TMenuItem;
ms_inside: TMenuItem;
ms_outside: TMenuItem;
ms_pocket: TMenuItem;
ms_drill: TMenuItem;
PopupMenuTooltip: TPopupMenu;
mt_flat: TMenuItem;
mt_cone30: TMenuItem;
mt_cone45: TMenuItem;
mt_cone60: TMenuItem;
mt_cone90: TMenuItem;
mt_ballnose: TMenuItem;
mt_drill: TMenuItem;
TabUtils: TTabSheet;
MemoUtils1: TMemo;
BtnUtilsSquare: TSpeedButton;
ScrollUtilsFeed: TScrollBar;
LabelUtilsFeed: TLabel;
EditUtilsZend: TEdit;
EditUtilsZinc: TEdit;
Label30: TLabel;
BtnUtilsReset: TBitBtn;
EditCornerX: TEdit;
EditCornerY: TEdit;
Label34: TLabel;
Label35: TLabel;
BtnSetCorner: TButton;
Label29: TLabel;
BtnUtilsCircle: TSpeedButton;
BtnSetRadius: TButton;
Label37: TLabel;
EditRadius: TEdit;
BtnCirclePocket: TSpeedButton;
BtnCircleOutline: TSpeedButton;
Label38: TLabel;
BtnSquareOutline: TSpeedButton;
BtnSquarePocket: TSpeedButton;
Label32: TLabel;
EditToolDia: TEdit;
Label33: TLabel;
UpDown1: TUpDown;
UpDown2: TUpDown;
UpDown3: TUpDown;
Label36: TLabel;
Label19: TLabel;
LabelInfo1: TLabel;
LabelInfo2: TLabel;
BtnReloadAll: TButton;
PanelPinState: TPanel;
LabelInfo3: TLabel;
LabelInfo4: TLabel;
MposC: TLabel;
BtnZeroC: TSpeedButton;
TabSheetPos: TTabSheet;
VideoBox: TPaintBox;
RadioGroupCam: TRadioGroup;
TrackBar1: TTrackBar;
StaticText1: TStaticText;
StaticText6: TStaticText;
OverlayColor: TPanel;
Label43: TLabel;
BitBtn14: TBitBtn;
BitBtn13: TBitBtn;
BitBtn12: TBitBtn;
BitBtn11: TBitBtn;
Bevel10: TBevel;
BtnHomeOverride: TSpeedButton;
BtnHomeCycle: TSpeedButton;
LabelJogDistance: TLabel;
BtnMovePark: TSpeedButton;
Bevel2: TBevel;
LabelMoveTo: TLabel;
BtnZcontact: TSpeedButton;
BtnMoveXYzero: TSpeedButton;
BtnMoveJobCenter: TSpeedButton;
BtnMoveZzero: TSpeedButton;
BtnMoveHilite: TSpeedButton;
BtnMoveFix2: TSpeedButton;
BtnMoveFix1: TSpeedButton;
Label9: TLabel;
Label6: TLabel;
PosC: TLabel;
PosZ: TLabel;
PosY: TLabel;
PosX: TLabel;
Bevel12: TBevel;
Label10: TLabel;
Bevel13: TBevel;
Bevel14: TBevel;
Label15: TLabel;
BtnEmergStopRun: TBitBtn;
BtnCancelRun: TSpeedButton;
BtnCancelMill: TSpeedButton;
BtnEmergStopMill: TBitBtn;
Label16: TLabel;
BtnMoveToolChange: TSpeedButton;
TouchButton1: TTouchButton;
TouchButton2: TTouchButton;
TouchButton3: TTouchButton;
TouchButton4: TTouchButton;
TouchButton5: TTouchButton;
TouchButton6: TTouchButton;
TouchButton7: TTouchButton;
TouchButton8: TTouchButton;
TouchButton9: TTouchButton;
TouchButton10: TTouchButton;
PopupMenuBlockShape: TPopupMenu;
MenuItem1: TMenuItem;
MenuItem2: TMenuItem;
MenuItem3: TMenuItem;
MenuItem4: TMenuItem;
MenuItem5: TMenuItem;
SpeedButton1: TSpeedButton;
LabelWorkX_2: TLabel;
LabelWorkY_2: TLabel;
LabelWorkZ_2: TLabel;
Label8: TLabel;
Label17: TLabel;
Label18: TLabel;
PopupMenuMaterial: TPopupMenu;
Bevel5: TBevel;
Label20: TLabel;
PosX_2: TLabel;
PosY_2: TLabel;
PosZ_2: TLabel;
ToolButton3: TToolButton;
ToolButton4: TToolButton;
ToolButton5: TToolButton;
ToolButton7: TToolButton;
ToolButton8: TToolButton;
ToolButton10: TToolButton;
ToolButton11: TToolButton;
TouchKeyboard: TTouchKeyboard;
TouchButton11: TTouchButton;
LabelJoySend: TLabel;
LabelJoyInfo: TLabel;
LabelResponse: TLabel;
LabelStatusFaults: TLabel;
DeviceView: TPanel;
procedure BtnEmergencyStopClick(Sender: TObject);
procedure TimerStatusElapsed(Sender: TObject);
procedure PageControl1Change(Sender: TObject);
procedure SgBlocksClick(Sender: TObject);
procedure SgBlocksMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure Show3DPreview1Click(Sender: TObject);
procedure ShowDrawing1Click(Sender: TObject);
procedure SgJobDefaultsExit(Sender: TObject);
procedure SgJobDefaultsKeyPress(Sender: TObject; var Key: Char);
procedure SgPensKeyPress(Sender: TObject; var Key: Char);
procedure SgFilesKeyPress(Sender: TObject; var Key: Char);
procedure ComboBox1Exit(Sender: TObject);
procedure SgBlocksDrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
procedure SgEditorOn(Sg: TStringGrid; ACol,ARow:integer; NumMode,SideWise:boolean);
procedure SgEditorOff(Sg: TStringGrid);
procedure BtnMoveToolChangeClick(Sender: TObject);
procedure BtnMoveXYzeroClick(Sender: TObject);
procedure SgGrblSettingsDrawCell(Sender: TObject; ACol,
ARow: Integer; Rect: TRect; State: TGridDrawState);
procedure SgGrblSettingsExit(Sender: TObject);
procedure SgGrblSettingsKeyPress(Sender: TObject; var Key: Char);
procedure SgGrblSettingsSelectCell(Sender: TObject; ACol, ARow: Integer;
var CanSelect: Boolean);
procedure SgJobDefaultsDrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
procedure BtnHomeCycleClick(Sender: TObject);
procedure BtnZeroZClick(Sender: TObject);
procedure BtnZeroYClick(Sender: TObject);
procedure BtnZeroXClick(Sender: TObject);
procedure HelpAbout1Execute(Sender: TObject);
procedure SgFilesDrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
procedure BtnCancelClick(Sender: TObject);
procedure FileNew1Execute(Sender: TObject);
procedure SgPensDrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
procedure JobSaveExecute(Sender: TObject);
procedure JobSaveAsExecute(Sender: TObject);
procedure BtnConnectClick(Sender: TObject);
procedure BtnCloseClick(Sender: TObject);
procedure FileExitItemClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure JobOpenExecute(Sender: TObject);
procedure TimerDrawElapsed(Sender: TObject);
procedure ComboBoxGtipChange(Sender: TObject);
procedure ComboBoxGdiaChange(Sender: TObject);
procedure RunGcode(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
procedure CheckBoxSimClick(Sender: TObject);
procedure BitBtnJogMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure BitBtnJogMouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure BtnLoadGrblSetupClick(Sender: TObject);
procedure BtnSaveGrblSetupClick(Sender: TObject);
procedure TimerBlinkTimer(Sender: TObject);
procedure PanelAlarmClick(Sender: TObject);
procedure SgAppDefaultsKeyPress(Sender: TObject; var Key: Char);
procedure SgAppDefaultsDrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
procedure SgAppDefaultsExit(Sender: TObject);
procedure BtnZcontactClick(Sender: TObject);
procedure CheckTLCprobeClick(Sender: TObject);
procedure BtnRescanClick(Sender: TObject);
procedure BtnZeroAllClick(Sender: TObject);
procedure GerberImport1Click(Sender: TObject);
procedure sgATCDrawCell(Sender: TObject; ACol, ARow: Integer; Rect: TRect;
State: TGridDrawState);
procedure sgATCSelectCell(Sender: TObject; ACol, ARow: Integer;
var CanSelect: Boolean);
procedure BtnCancelMouseEnter(Sender: TObject);
procedure BtnCancelMouseLeave(Sender: TObject);
procedure BtnHomeOverrideClick(Sender: TObject);
procedure PanelAliveClick(Sender: TObject);
procedure PanelReadyClick(Sender: TObject);
procedure CheckToolChangeClick(Sender: TObject);
procedure PanelHoldClick(Sender: TObject);
procedure BtnRunJobClick(Sender: TObject);
procedure CheckUseATC2Click(Sender: TObject);
procedure pu_MovetoATCslotClick(Sender: TObject);
procedure pu_LoadFromATCslotClick(Sender: TObject);
procedure pu_ProbeToolLengthRefClick(Sender: TObject);
procedure sgATCMouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure pu_ProbetoolLengthCompClick(Sender: TObject);
procedure BtnRunToolClick(Sender: TObject);
procedure BtnMoveZzeroClick(Sender: TObject);
procedure mt_Click(Sender: TObject);
procedure ms_Click(Sender: TObject);
procedure mbs_click(Sender: TObject);
procedure BtnUtilsSquareClick(Sender: TObject);
procedure ScrollUtilsFeedChange(Sender: TObject);
procedure BtnUtilsResetClick(Sender: TObject);
procedure BtnSetCornerClick(Sender: TObject);
procedure EditCornerKeyPress(Sender: TObject; var Key: Char);
procedure BtnSetRadiusClick(Sender: TObject);
procedure BtnUtilsCircleClick(Sender: TObject);
procedure BtnCircleOutlineClick(Sender: TObject);
procedure BtnCirclePocketClick(Sender: TObject);
procedure BtnSquareOutlineClick(Sender: TObject);
procedure BtnSquarePocketClick(Sender: TObject);
procedure EditRadiusKeyPress(Sender: TObject; var Key: Char);
procedure PageControl1DrawTab(Control: TCustomTabControl; TabIndex: Integer;
const Rect: TRect; Active: Boolean);
procedure PageControl1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure UpDown1ChangingEx(Sender: TObject; var AllowChange: Boolean;
NewValue: Integer; Direction: TUpDownDirection);
procedure UpDown2ChangingEx(Sender: TObject; var AllowChange: Boolean;
NewValue: Integer; Direction: TUpDownDirection);
procedure UpDown3ChangingEx(Sender: TObject; var AllowChange: Boolean;
NewValue: Integer; Direction: TUpDownDirection);
procedure SgFilesExit(Sender: TObject);
procedure BtnReloadAllClick(Sender: TObject);
procedure BtnZeroCClick(Sender: TObject);
procedure RadioGroupCamClick(Sender: TObject);
procedure SwitchCam(SwitchOn: boolean);
procedure OverlayColorClick(Sender: TObject);
procedure BtnCntrMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure BtnCntrLongEvent;
procedure BtnCntrMouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure BtnMoveCamZeroClick(Sender: TObject);
procedure BtnCamAtZeroClick(Sender: TObject);
procedure BtnCamAtPointClick(Sender: TObject);
procedure BtnMoveCamPointClick(Sender: TObject);
procedure BtnMoveToolPointClick(Sender: TObject);
procedure SetDefaultToPos(s: String; var x,y,z: Double; idx: integer; CAM: boolean);
procedure MoveToPos(S: String; x, y, z: Double; Set0, CAM: boolean);
procedure SetZero(axes: integer);
procedure CheckEndParkClick(Sender: TObject);
procedure hide;
procedure ContinueJogging;
procedure StepJogging;
procedure ResetJogging;
procedure SetToolInSpindle(Tool: integer);
procedure BtnProbeZAssistentClick(Sender: TObject);
procedure PopupMenuMaterialClick(Sender: TObject);
procedure MemoCommentClick(Sender: TObject);
procedure MemoCommentExit(Sender: TObject);
procedure SgPensExit(Sender: TObject);
procedure SgJobDefaultsSelectCell(Sender: TObject; ACol, ARow: Integer;
var CanSelect: Boolean);
procedure SgAppDefaultsSelectCell(Sender: TObject; ACol, ARow: Integer;
var CanSelect: Boolean);
procedure SgFilesSelectCell(Sender: TObject; ACol, ARow: Integer;
var CanSelect: Boolean);
procedure SgPensSelectCell(Sender: TObject; ACol, ARow: Integer;
var CanSelect: Boolean);
procedure SgPensDblClick(Sender: TObject);
procedure SgPensContextPopup(Sender: TObject; MousePos: TPoint;
var Handled: Boolean);
procedure SystemTouchKeyboardOn(Sender: TObject);
procedure SystemTouchKeyboardOff(Sender: TObject);
private
{ Private declarations }
JogDistance : integer;
JogDirection : T3dFloat;
JogDelay : integer;
CntrDelay : integer;
ActiveCntrButtom : TSpeedButton;
procedure TouchKeyboardOn(Edit: TCustomEdit; NumMode:boolean);
procedure TouchKeyboardOff;
public
{ Public declarations }
GLScene1: TGLScene;
FrameCounter: integer;
BtnDownTime: int64;
BtnDownTag: integer;
fVideoImage: TVideoImage;
fVideoBitmap: TBitmap;
procedure OnNewVideoFrame(Sender : TObject; Width, Height: integer; DataPtr: pointer);
function TouchSupport:boolean;
end;
TLed = class
private
IsOn: Boolean;
procedure SetLED(led_on: Boolean);
public
property Checked: Boolean read IsOn write SetLED;
end;
{ TGamepad - A wrapper class for the Windows-Joystick-API}
TGamepad = class
private
FRange:integer;
FDeadZone:integer;
function GetButton(index:integer):boolean;
function GetX:integer;
function GetY:integer;
function GetZ:integer;
function GetR:integer;
function GetU:integer;
function GetV:integer;
function GetAnalogActive:Boolean;
function GetPOV:TPOVControl;
procedure UpdateDeviceNr(nr:cardinal);
protected
Device:TJoyInfoEx;
DeviceInfo:TJoyCaps;
FDeviceNr:Cardinal;
CenterX,CenterY,CenterZ:Integer;
CenterR,CenterU,CenterV:Integer;
public
property DeviceNr:Cardinal read FDeviceNr write UpdateDeviceNr;
procedure Update;
procedure Calibrate;
constructor Create;
property X:integer read GetX;
property Y:integer read GetY;
property Z:integer read GetZ;
property R:integer read GetR;
property U:integer read GetU;
property V:integer read GetV;
property IsAnalogActive:Boolean read GetAnalogActive;
property Range:integer read FRange write FRange;
property DeadZone:integer read FDeadZone write FDeadZone;
property POV:TPOVControl read GetPov;
property Buttons[index:integer]:boolean read GetButton;
end;
procedure DisplayMachinePosition;
procedure DisplayWorkPosition;
procedure WaitForIdle;
// dekodiert Antwort von GRBL und zeigt ggf. Meldungszeile:
function ResponseMsg(my_str:String): boolean;
// bei abgeschaltetem Status senden und empfangen:
function SendReceive(my_cmd: String; my_timeout: Integer): String;
function SendReceiveAndDwell(my_cmd: String): String;
procedure SendSingleCommandStr(my_command: String);
procedure SendSingleCommandAndDwell(my_command: String);
procedure SendListToGrbl;
function ListBlocks: boolean;
procedure EnableStatus; // automatische Upates freischalten
procedure DisableStatus; // automatische Upates freischalten
function isCancelled: Boolean;
function isJobRunning: Boolean;
function isEmergency: Boolean;
function isWaitExit: Boolean;
function isSimActive: Boolean;
function isGrblActive: Boolean;
function ManualToolchange(atc_idx_old, atc_idx_new: Integer; do_tlc: boolean): Boolean;
procedure ChangeATCtool(atc_idx_old, atc_idx_new: Integer; do_tlc: boolean);
procedure UnloadATCtool(atc_idx: Integer);
procedure LoadATCtool(atc_idx: Integer; do_tlc: boolean);
procedure OpenFilesInGrid;
procedure ForceToolPositions(x, y, z: Double);
procedure AutoAssignATCtoolsToJob;
procedure UpdateATC;
procedure ClearATCarray;
procedure InvalidateTLCs;
procedure ClearAlarmLock;
type
t_mstates = (none, idle, run, hold, alarm, zero);
t_rstates = (s_reset, s_request, s_receive, s_sim);
t_pstates = (s_notprobed, s_probed_manual, s_probed_contact);
var
SendActive: Boolean = false; // true bis GRBL-Sendeschleife beendet
Form1: TForm1;
LEDbusy: TLed;
DeviceList: TStringList;
TimeOutValue,LEDtimer: Integer; // Timer-Tick-Zähler
TimeOut: Boolean;
ComPortAvailableList: Array[0..31] of Integer;
ComPortUsed: Integer;
JobSettingsPath: String;
grbl_mpos, grbl_wpos, old_grbl_wpos, grbl_wco: T3dFloat;
PosProbeZ : T3dFloat; // last prosition of ProbeZ
Jog,WorkZero:T3dFloat; // Absolutwerte Werkstück-Null
grbl_feed_ov, grbl_seek_ov, grbl_speed_ov: Integer;
grbl_feed, grbl_speed: Integer;
MouseJogAction: Boolean;
open_request, ftdi_was_open, com_was_open: boolean;
HomingPerformed: Boolean;
MposOnFixedProbe, MposOnPartGauge: Double;
MposOnFixedProbeReference: Double;
WorkZeroXdone, WorkZeroYdone, WorkZeroZdone, WorkZeroCdone, WorkZeroAllDone: Boolean;
// ProbedState: t_pstates;
LastToolUsed: Integer = 1; // Zuletzt Benutztes Tool im Job, 0 = unused
ToolInSpindle: Integer = 1; // ATC-Tool in der Maschine, 0 = unused
StatusFaultCounter: Integer = 0;
SpindleRunning: Boolean;
TimerBlinkToggle: Boolean;
// StatusTimerState: t_rstates; // (none, status, response);
MachineState: t_mstates; // (idle, run, hold, alarm)GRBL ist in Ruhe wenn state_idle
LastResponseStr:String;
// für Simulation
gcsim_x_old, gcsim_y_old, gcsim_z_old: Double;
gcsim_seek: Boolean;
gcsim_dia: Double;
gcsim_feed: Integer;
gcsim_active: Boolean;
gcsim_tooltip: Integer;
gcsim_color: TColor;
StopWatch: TStopwatch;
// StartupDone: Boolean = false;
SquareCorner_wpos, SquareCorner_mpos: T3dFloat;
InstantZ_end, InstantZ_inc: Double;
SquarePocket: Boolean;
SquareCornerManualEnter, SquareCornerSetToMpos: Boolean;
CirclePocket: Boolean;
CircleRadiusManualEnter, CircleRadiusSetToMpos: Boolean;
CircleRadius: Double;
CircleRadius_wpos, CircleRadius_mpos: T3dFloat;
JoyPad: TGamepad;
JoyPadWasActive: Boolean = false;
SavedPortnameForSim: String;
fCamActivated, // Cam is switched on in current session
fCamPresent, // Cam is present in current session
CamIsOn : boolean; // global state of Cam
overlay_color: Tcolor;
const
// für Simulation
c_zero_x = 50;
c_zero_y = 50;
c_zero_z = -25;
c_numATCslots = 9;
SettingCodes_11_3: Array[0..35] of String[31] = (
'Step pulse time',
'Step idle delay',
'Step pulse invert mask',
'Step direction invert mask',
'Invert step enable pin',
'Invert limit pins',
'Invert probe pin',
'Status report options',
'Junction deviation',
'Arc tolerance',
'Report in inches',
'Soft limits enable',
'Hard limits enable',
'Homing cycle enable',
'Homing direction invert mask',
'Homing locate feed rate',
'Homing search seek rate',
'Homing switch debounce delay',
'Homing switch pull-off distance',
'Maximum spindle speed',
'Minimum spindle speed',
'Laser-mode enable',
'X-axis travel resolution',
'Y-axis travel resolution',
'Z-axis travel resolution',
'X-axis maximum rate',
'Y-axis maximum rate',
'Z-axis maximum rate',
'X-axis acceleration',
'Y-axis acceleration',
'Z-axis acceleration',
'X-axis maximum travel',
'Y-axis maximum travel',
'Z-axis maximum travel',
'(none)',
'(none)'
);
SettingCodes_11_4: Array[0..39] of String[31] = (
'Step pulse time',
'Step idle delay',
'Step pulse invert mask',
'Step direction invert mask',
'Invert step enable pin',
'Invert limit pins',
'Invert probe pin',
'Status report options',
'Junction deviation',
'Arc tolerance',
'Report in inches',
'Soft limits enable',
'Hard limits enable',
'Homing cycle enable',
'Homing direction invert mask',
'Homing locate feed rate',
'Homing search seek rate',
'Homing switch debounce delay',
'Homing switch pull-off distance',
'Maximum spindle speed',
'Minimum spindle speed',
'Laser-mode enable',
'X-axis travel resolution',
'Y-axis travel resolution',
'Z-axis travel resolution',
'C-axis travel resolution',
'X-axis maximum rate',
'Y-axis maximum rate',
'Z-axis maximum rate',
'C-axis maximum rate',
'X-axis acceleration',
'Y-axis acceleration',
'Z-axis acceleration',
'C-axis acceleration',
'X-axis maximum travel',
'Y-axis maximum travel',
'Z-axis maximum travel',
'C-axis maximum travel',
'(none)',
'(none)'
);
implementation
uses import_files, Clipper, About, bsearchtree, gerber_import, ParamAssist, Winapi.TlHelp32;
{$R *.dfm}
// #############################################################################
// #############################################################################
{$I joypad.inc}
function isCancelled: Boolean;
begin
result:= Form1.BtnCancel.Tag > 0;
end;
function isJobRunning: Boolean;
begin
result:= (Form1.BtnRunJob.Tag > 0);
end;
function isEmergency: Boolean;
begin
result:= Form1.BtnEmergStop.tag > 0;
end;
function isWaitExit: Boolean;
begin
result:= Form1.PanelAlive.tag > 0;
end;
function isSimActive: Boolean;
begin
result:= (not grbl_is_connected) or Form1.CheckBoxSim.checked;
end;
function isGrblActive: Boolean;
begin
result:= (not Form1.CheckBoxSim.checked) and grbl_is_connected;
end;
procedure TLed.SetLED(led_on: boolean);
// liefert vorherigen Zustand zurück
begin
if led_on and (not IsOn) then begin
Form1.PanelBusy.Color:= clred;
Form1.PanelBusy.Font.Color:= clWhite;
Screen.Cursor:= crHourGlass;
end;
if (not led_on) and IsOn then begin
Form1.PanelBusy.Color:= $00000040;
Form1.PanelBusy.Font.Color:= clgray;
Screen.Cursor:= crDefault;
end;
IsOn:= led_on;
end;
procedure DisplayMachinePosition;
begin
with Form1 do begin
if HomingPerformed then begin
// if RadioGroupCam.ItemIndex = 0
if fCamActivated
then MPosX.Caption:= FormatFloat('000.00', grbl_mpos.x + job.cam_x)
else MPosX.Caption:= FormatFloat('000.00', grbl_mpos.x);
// if RadioGroupCam.ItemIndex = 0
if fCamActivated
then MPosY.Caption:= FormatFloat('000.00', grbl_mpos.y + job.cam_y)
else MPosY.Caption:= FormatFloat('000.00', grbl_mpos.y);
MPosZ.Caption:= FormatFloat('000.00', grbl_mpos.z);
MPosC.Caption:= FormatFloat('000.0', grbl_mpos.c);
end else begin
MPosX.Caption:= '---.--';
MPosY.Caption:= '---.--';
MPosZ.Caption:= '---.--';
MPosC.Caption:= '---.-';
end;
end;
end;
procedure DisplayWorkPosition;
begin
with Form1 do begin
if WorkZeroXdone
then begin
// if RadioGroupCam.ItemIndex = 0
if fCamActivated
then PosX.Caption:= FormatFloat('000.00', grbl_wpos.x + job.cam_x)
else PosX.Caption:= FormatFloat('000.00', grbl_wpos.x);
end
else PosX.Caption:= '---.--';
PosX_2.Caption:= PosX.Caption;
if WorkZeroYdone
then begin
// if RadioGroupCam.ItemIndex = 0
if fCamActivated
then PosY.Caption:= FormatFloat('000.00', grbl_wpos.y + job.cam_y)
else PosY.Caption:= FormatFloat('000.00', grbl_wpos.y);
end
else PosY.Caption:= '---.--';
PosY_2.Caption:= PosY.Caption;
if WorkZeroZdone
then PosZ.Caption:= FormatFloat('000.00', grbl_wpos.z)
else PosZ.Caption:= '---.--';
PosZ_2.Caption:= PosZ.Caption;
if WorkZeroCdone
then PosC.Caption:= FormatFloat('000.0', grbl_wpos.c)
else PosC.Caption:= '---.--';
end;
end;
procedure button_enable(my_state: Boolean);
begin
if (MachineState >= run) then
my_state:= false;
with Form1 do begin
BtnMovePark.Enabled:= my_state;
BtnMoveFix1.Enabled:= my_state;
BtnMoveFix2.Enabled:= my_state;
BtnMoveHilite.Enabled:= my_state and (HilitePoint >= 0);
BtnMoveJobCenter.Enabled:= my_state and WorkZeroXdone and WorkZeroYdone;
BtnZcontact.Enabled:= my_state and job.use_part_probe;
BtnMoveXYzero.Enabled:= my_state;
BtnMoveZzero.Enabled:= my_state;
BtnZeroC.Enabled:= my_state;
BtnMoveToolChange.Enabled:= my_state;
// BtnMoveZzero.Enabled:= my_state;
// BtnZeroX.Enabled:= my_state;
// BtnZeroY.Enabled:= my_state;
// BtnZeroZ.Enabled:= my_state;
BtnZeroAll.Enabled:= my_state;
// Form1.BtnProbeTLC.Enabled:= my_state and Form1.CheckFixedProbeZ.checked;
BtnEmergStop.Enabled:= isGrblActive;
if WorkZeroXdone then
PanelXdone.Color:= cllime
else
if TimerBlinkToggle then
PanelXdone.Color:= $00000020
else
PanelXdone.Color:= clred;
if WorkZeroYdone then
PanelYdone.Color:= cllime
else
if TimerBlinkToggle then
PanelYdone.Color:= $00000020
else
PanelYdone.Color:= clred;
if WorkZeroZdone then
PanelZdone.Color:= cllime
else
if TimerBlinkToggle then
PanelZdone.Color:= $00000020
else
PanelZdone.Color:= clred;
end;
end;
procedure button_run_enable(my_state: Boolean);
begin
with Form1 do begin
BtnRunGcode.Enabled:= my_state;
BtnRunJob.Enabled:= my_state and (length(final_array) > 0);
BtnRunTool.Enabled:= my_state and (length(final_array) > 0);
// Form3.BtnMoveToolZero.Enabled:= my_state;
// Form3.BtnMoveCamZero.Enabled:= my_state;
end;
end;
// #############################################################################
procedure uncheck_ms;
var i: Integer;
begin
for i:= 0 to Form1.PopupMenuShape.Items.Count - 1 do
Form1.PopupMenuShape.Items[i].Checked:= false;
end;
procedure uncheck_mbs;
var i: Integer;
begin
for i:= 0 to Form1.PopupMenuBlockShape.Items.Count - 1 do
Form1.PopupMenuBlockShape.Items[i].Checked:= false;
end;
procedure uncheck_mtt;
var i: Integer;
begin
for i:= 0 to Form1.PopupMenuTooltip.Items.Count - 1 do
Form1.PopupMenuTooltip.Items[i].Checked:= false;
end;
procedure SetAllbuttons;
var is_idle, is_running: boolean;
begin
WorkZeroAllDone:= WorkZeroXdone and WorkZeroYdone and WorkZeroZdone;
is_running:= isJobRunning;
if grbl_is_connected then begin
Form1.CheckBoxSim.Enabled:= not is_running;
end else begin
Form1.CheckBoxSim.Checked:= true;
Form1.CheckBoxSim.Enabled:= false;
end;
is_idle:= MachineState = idle;
Form1.BtnCancel.Enabled:= is_running;
// Button have to be active all the time to set the values
// Form1.BtnMoveHilite.Enabled:= WorkZeroXdone and WorkZeroYdone;
// Form1.BtnMoveXYZero.Enabled:= WorkZeroXdone and WorkZeroYdone;
// Form1.BtnMoveZzero.Enabled := WorkZeroAllDone;
// Form1.BtnMoveZzero.Enabled := true;
if isCancelled then begin
button_enable(false);
button_run_enable(false);
with Form1 do begin
if TimerBlinkToggle then
BtnCancel.Font.Color:= clred
else
BtnCancel.Font.Color:= clblack;
end;
end else begin
button_enable(HomingPerformed);
with Form1 do begin
BtnCancel.Font.Color:= clred;
if isSimActive then begin
button_run_enable((not is_running) and WorkZeroAllDone);
end else begin
button_run_enable(is_idle and HomingPerformed and WorkZeroAllDone);
end;
end;
end;
with Form1 do begin
if (not HomingPerformed) and TimerBlinkToggle then
BtnHomeCycle.Font.Color:= cllime
else
BtnHomeCycle.Font.Color:= clgreen;
// if grbl_is_connected then begin
// BtnSendGrblSettings.Enabled:= true;
// BtnRefreshGrblSettings.Enabled:= true;