-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathController.pas
819 lines (768 loc) · 23.5 KB
/
Controller.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
(*
* The contents of this file are subject to the Mozilla Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
* License for the specific language governing rights and limitations
* under the License.
*
* The Initial Developer of this code is Mark Overmars.
* Portions created by John Hansen are Copyright (C) 2009-2013 John Hansen.
* All Rights Reserved.
*
*)
unit Controller;
{$IFDEF FPC}
{$MODE Delphi}
{$ENDIF}
interface
uses
{$IFNDEF FPC}
Windows,
{$ELSE}
LResources,
{$ENDIF}
SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ComCtrls, StdCtrls, ExtCtrls, Buttons, rcx_constants;
type
TDirectForm = class(TForm)
grpMotors: TGroupBox;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
grpTasks: TGroupBox;
TL0: TLabel;
TL1: TLabel;
TL2: TLabel;
TL3: TLabel;
TL4: TLabel;
TL5: TLabel;
TL6: TLabel;
TL7: TLabel;
TL8: TLabel;
TL9: TLabel;
StartAllBtn: TButton;
StopAllBtn: TButton;
SensorGroup: TGroupBox;
Label14: TLabel;
Label15: TLabel;
lblSensor2: TLabel;
SensorType0: TComboBox;
SensorMode0: TComboBox;
SensorType1: TComboBox;
SensorMode1: TComboBox;
SensorType2: TComboBox;
SensorMode2: TComboBox;
grpVariables: TGroupBox;
VariableBox: TComboBox;
OperatorBox: TComboBox;
ValueEdit: TEdit;
SetBtn: TButton;
ValueUpDown: TUpDown;
FwdABtn: TSpeedButton;
RevABtn: TSpeedButton;
OffABtn: TSpeedButton;
FloatABtn: TSpeedButton;
SpeedA: TTrackBar;
FwdBBtn: TSpeedButton;
RevBBtn: TSpeedButton;
OffBBtn: TSpeedButton;
FloatBBtn: TSpeedButton;
SpeedB: TTrackBar;
FwdCBtn: TSpeedButton;
RevCBtn: TSpeedButton;
OffCBtn: TSpeedButton;
FloatCBtn: TSpeedButton;
SpeedC: TTrackBar;
cboSource: TComboBox;
Label4: TLabel;
Label5: TLabel;
btnHelp: TButton;
RunTask0: TBitBtn;
StopTask0: TBitBtn;
StopTask1: TBitBtn;
RunTask1: TBitBtn;
StopTask2: TBitBtn;
RunTask2: TBitBtn;
StopTask3: TBitBtn;
RunTask3: TBitBtn;
StopTask4: TBitBtn;
RunTask4: TBitBtn;
StopTask5: TBitBtn;
RunTask5: TBitBtn;
StopTask6: TBitBtn;
RunTask6: TBitBtn;
StopTask7: TBitBtn;
RunTask7: TBitBtn;
StopTask8: TBitBtn;
RunTask8: TBitBtn;
StopTask9: TBitBtn;
RunTask9: TBitBtn;
lblSensor3: TLabel;
SensorType3: TComboBox;
SensorMode3: TComboBox;
lblMotorD: TLabel;
FwdDBtn: TSpeedButton;
RevDBtn: TSpeedButton;
OffDBtn: TSpeedButton;
FloatDBtn: TSpeedButton;
SpeedD: TTrackBar;
procedure SpeedChange(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure RunTask0Click(Sender: TObject);
procedure StopTask0Click(Sender: TObject);
procedure StartAllBtnClick(Sender: TObject);
procedure StopAllBtnClick(Sender: TObject);
procedure FormKeyPress(Sender: TObject; var Key: Char);
procedure SensorTypeChange(Sender: TObject);
procedure SensorModeChange(Sender: TObject);
procedure SetBtnClick(Sender: TObject);
procedure FwdABtnClick(Sender: TObject);
procedure RevABtnClick(Sender: TObject);
procedure OffABtnClick(Sender: TObject);
procedure FloatABtnClick(Sender: TObject);
procedure ValueEditKeyPress(Sender: TObject; var Key: Char);
procedure ValueEditExit(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure btnHelpClick(Sender: TObject);
private
{ Private declarations }
procedure InitForm;
function GetMotorPower(tag: integer): Byte;
function GetMotorDirection(tag: integer): TMotorDirection;
function GetMotorState(tag: integer): TMotorState;
procedure UpdateModes(aTypeID: integer; aStrings: TStrings);
public
{ Public declarations }
end;
var
DirectForm: TDirectForm;
implementation
{$IFNDEF FPC}
{$R *.DFM}
{$ENDIF}
uses
brick_common, uSources, uLocalizedStrings, uGlobals, uEV3TypeData;
var
V_HEIGHT, V_MOTORS_TOP, V_VARS_TOP, V_TASKS_TOP, V_FUDGE,
V_SENS_H, V_SENS_DELTA : Integer;
const
{$IFDEF FPC}
{$IFDEF Darwin}
K_FUDGE = -40;
K_HEIGHT = 560+80; //498;
K_MOTORS_TOP = 146+40; //118;
K_VARS_TOP = 292+40; //234;
K_TASKS_TOP = 368+40; //310;
K_SENS_DELTA = 32;
K_SENS_H = 140+40;
{$ENDIF}
{$IFNDEF Darwin}
K_FUDGE = 4;
K_HEIGHT = 560; //498;
K_MOTORS_TOP = 146; //118;
K_VARS_TOP = 292; //234;
K_TASKS_TOP = 368; //310;
K_SENS_DELTA = 32;
K_SENS_H = 140;
{$ENDIF}
{$ELSE}
K_FUDGE = 4;
K_HEIGHT = 560; //498;
K_MOTORS_TOP = 146; //118;
K_VARS_TOP = 292; //234;
K_TASKS_TOP = 368; //310;
K_SENS_DELTA = 32;
K_SENS_H = 140;
{$ENDIF}
procedure TDirectForm.UpdateModes(aTypeID : integer; aStrings : TStrings);
begin
if IsEV3 then
begin
// load the associated combo box with the correct mode names
LoadTypeModes(aTypeID, aStrings);
end;
end;
{Dealing with the Sensors}
procedure TDirectForm.SensorTypeChange(Sender: TObject);
var
cbo : TComboBox;
typeID : integer;
begin
if Sender = nil then Exit;
if TComboBox(Sender).ItemIndex >= 0 then
begin
typeID := TComboBox(Sender).ItemIndex;
cbo := TComboBox(FindComponent('SensorMode' + IntToStr(TComboBox(Sender).Tag)));
if Assigned(cbo) then
begin
UpdateModes(typeID, cbo.Items);
cbo.ItemIndex := 0;
end;
BrickComm.SetSensorType(TComboBox(Sender).Tag, typeID);
SensorModeChange(cbo);
end;
end;
procedure TDirectForm.SensorModeChange(Sender: TObject);
begin
if Sender = nil then Exit;
if TComboBox(Sender).ItemIndex >= 0 then
begin
BrickComm.SetSensorMode(TComboBox(Sender).Tag, TComboBox(Sender).ItemIndex, 0);
end;
end;
{Dealing with the Motors}
function GetMotorNum(tag : integer) : Byte;
begin
case tag of
0 : result := 1;
1 : result := 2;
2 : result := 4;
else
result := 8; // D
end;
end;
function TDirectForm.GetMotorPower(tag : integer) : Byte;
begin
case tag of
0 : result := SpeedA.Position;
1 : result := SpeedB.Position;
2 : result := SpeedC.Position;
3 : result := SpeedD.Position;
else
result := 0;
end;
end;
function TDirectForm.GetMotorDirection(tag : integer) : TMotorDirection;
begin
Result := mdForward;
case tag of
0 : if RevABtn.Down then Result := mdReverse;
1 : if RevBBtn.Down then Result := mdReverse;
2 : if RevCBtn.Down then Result := mdReverse;
3 : if RevDBtn.Down then Result := mdReverse;
end;
end;
function TDirectForm.GetMotorState(tag : integer) : TMotorState;
begin
Result := msFloat;
case tag of
0 :
if FwdABtn.Down or RevABtn.Down then
Result := msOn
else if OffABtn.Down then
Result := msOff;
1 :
if FwdBBtn.Down or RevBBtn.Down then
Result := msOn
else if OffBBtn.Down then
Result := msOff;
2 :
if FwdCBtn.Down or RevCBtn.Down then
Result := msOn
else if OffCBtn.Down then
Result := msOff;
3 :
if FwdDBtn.Down or RevDBtn.Down then
Result := msOn
else if OffDBtn.Down then
Result := msOff;
end;
end;
procedure TDirectForm.FwdABtnClick(Sender: TObject);
var
n, tag : integer;
pwr : byte;
begin
if Sender = nil then Exit;
tag := TComponent(Sender).Tag;
n := GetMotorNum(tag);
pwr := GetMotorPower(tag);
BrickComm.ControlMotors(n, pwr, mdForward, msOn);
// BrickComm.SetFwd(n);
// BrickComm.MotorsOn(n);
end;
procedure TDirectForm.RevABtnClick(Sender: TObject);
var
n, tag : integer;
pwr : byte;
begin
if Sender = nil then Exit;
tag := TComponent(Sender).Tag;
n := GetMotorNum(tag);
pwr := GetMotorPower(tag);
BrickComm.ControlMotors(n, pwr, mdReverse, msOn);
// BrickComm.SetRwd(n);
// BrickComm.MotorsOn(n);
end;
procedure TDirectForm.OffABtnClick(Sender: TObject);
var
n, tag : integer;
begin
if Sender = nil then Exit;
tag := TComponent(Sender).Tag;
n := GetMotorNum(tag);
BrickComm.ControlMotors(n, 0, mdForward, msOff);
// BrickComm.MotorsOff(n);
end;
procedure TDirectForm.FloatABtnClick(Sender: TObject);
var
n, tag : integer;
begin
if Sender = nil then Exit;
tag := TComponent(Sender).Tag;
n := GetMotorNum(tag);
BrickComm.ControlMotors(n, 0, mdForward, msFloat);
// BrickComm.MotorsFloat(n);
end;
procedure TDirectForm.SpeedChange(Sender: TObject);
var
n, tag : integer;
pwr : byte;
dir : TMotorDirection;
state : TMotorState;
begin
if Sender = nil then Exit;
tag := TComponent(Sender).Tag;
n := GetMotorNum(tag);
pwr := GetMotorPower(tag);
dir := GetMotorDirection(tag);
state := GetMotorState(tag);
BrickComm.ControlMotors(n, pwr, dir, state);
// BrickComm.SetMotorPower(n, kRCX_ConstantType, pwr);
end;
{Dealing with the Variables}
procedure TDirectForm.SetBtnClick(Sender: TObject);
var
vnumb,
val : integer;
stype : byte;
begin
stype := cboSource.ItemIndex;
if IsScout and not ((stype = 0) or (stype = 2)) then
begin
stype := 2;
cboSource.ItemIndex := stype;
MessageDlg(sScoutSourceError, mtError, [mbOK], 0);
Exit;
end;
// get the source type from the selected item.
vnumb := VariableBox.ItemIndex;
val := ValueUpDown.Position;
case OperatorBox.ItemIndex of
0: BrickComm.SetVar(vnumb,stype,val);
1: BrickComm.SumVar(vnumb,stype,val);
2: BrickComm.SubVar(vnumb,stype,val);
3: BrickComm.MulVar(vnumb,stype,val);
4: BrickComm.DivVar(vnumb,stype,val);
5: BrickComm.AndVar(vnumb,stype,val);
6: BrickComm.OrVar(vnumb,stype,val);
7: BrickComm.AbsVar(vnumb,stype,val);
8: BrickComm.SgnVar(vnumb,stype,val);
end;
end;
{Dealing with the Tasks}
procedure TDirectForm.RunTask0Click(Sender: TObject);
begin
BrickComm.StartTask(TSpeedButton(Sender).Tag);
end;
procedure TDirectForm.StopTask0Click(Sender: TObject);
begin
BrickComm.StopTask(TSpeedButton(Sender).Tag);
end;
procedure TDirectForm.StartAllBtnClick(Sender: TObject);
var
i:integer;
c : TCursor;
begin
if Screen.Cursor = crHourGlass then Exit;
c := Screen.Cursor;
try
Screen.Cursor := crHourGlass;
if IsRCX then
begin
for i := 0 to 9 do BrickComm.StartTask(i);
end else if IsScout then
begin
for i := 0 to 5 do BrickComm.StartTask(i);
end else if IsSpybotic then
begin
for i := 8 to 15 do BrickComm.StartTask(i);
end else begin // cybermaster
for i := 0 to 3 do BrickComm.StartTask(i);
end;
finally
Screen.Cursor := c;
end;
end;
procedure TDirectForm.StopAllBtnClick(Sender: TObject);
begin
BrickComm.StopAllTasks();
end;
procedure TDirectForm.FormKeyPress(Sender: TObject; var Key: Char);
begin
// if IsRCX then
// begin
// if (Key >='0') and (Key <='9') then
// BrickComm.StartTask(Ord(Key)-Ord('0'));
// end else begin
// if (Key >='0') and (Key <='3') then
// BrickComm.StartTask(Ord(Key)-Ord('0'));
// end;
end;
{Handling the Window}
procedure TDirectForm.FormShow(Sender: TObject);
var
c : TCursor;
begin
c := Screen.Cursor;
try
Screen.Cursor := crHourGlass;
InitForm;
finally
Screen.Cursor := c;
end;
end;
procedure TDirectForm.ValueEditKeyPress(Sender: TObject; var Key: Char);
begin
if not (Key in [#8, #16, '-', '0'..'9']) then
Key := #0;
end;
procedure TDirectForm.ValueEditExit(Sender: TObject);
var
val : integer;
begin
// ensure value is within range
val := StrToInt(ValueEdit.Text);
if val < ValueUpDown.Min then
ValueEdit.Text := IntToStr(ValueUpDown.Min)
else if val > ValueUpDown.Max then
ValueEdit.Text := IntToStr(ValueUpDown.Max);
end;
procedure TDirectForm.InitForm;
var
ttt, h, i, delta : integer;
bVisible : boolean;
tmpSL : TStrings;
C : TComponent;
WS : WatchSources;
const
SPY_MODES : array[0..4] of Integer = (0, 1, -1, -1, 2);
begin
tmpSL := TStringList.Create;
try
// load the source combobox
WS := BrickWatchSources[LocalBrickType];
for i := low(WS) to high(WS) do
begin
if WS[i].Has then
cboSource.Items.AddObject(WS[i].Name, TObject(i));
end;
{Adapt to RCX type}
for i:= 0 to 9 do
begin
bVisible := IsRCX or
(IsScout and (i in [0..5])) or
(IsSpybotic and (i in [0..7]));
C := FindComponent('RunTask'+IntToStr(i));
TSpeedButton(C).Visible := bVisible;
if IsSpybotic then
C.Tag := i + 8
else
C.Tag := i;
C := FindComponent('StopTask'+IntToStr(i));
if IsSpybotic then
C.Tag := i + 8
else
C.Tag := i;
TSpeedButton(C).Visible := bVisible;
C := FindComponent('TL'+IntToStr(i));
TLabel(C).Visible := bVisible;
if IsSpybotic then
TLabel(C).Caption := IntToStr(i+8)
else
TLabel(C).Caption := IntToStr(i);
end;
Height := V_HEIGHT;
SensorGroup.Visible := True;
grpVariables.Visible := True;
grpTasks.Visible := True;
grpMotors.Top := V_MOTORS_TOP;
grpVariables.Top := V_VARS_TOP;
grpTasks.Top := V_TASKS_TOP;
SensorType2.Visible := not IsSpybotic;
SensorMode2.Visible := not IsSpybotic;
lblSensor2.Visible := not IsSpybotic;
SensorType3.Visible := IsNXT or IsEV3;
SensorMode3.Visible := IsNXT or IsEV3;
lblSensor3.Visible := IsNXT or IsEV3;
lblMotorD.Visible := IsEV3;
FwdDBtn.Visible := IsEV3;
RevDBtn.Visible := IsEV3;
OffDBtn.Visible := IsEV3;
FloatDBtn.Visible := IsEV3;
SpeedD.Visible := IsEV3;
if IsRCX then
begin
SensorGroup.Height := V_SENS_H - V_SENS_DELTA;
grpMotors.Top := V_MOTORS_TOP - V_SENS_DELTA - V_FUDGE;
grpVariables.Top := V_VARS_TOP - V_SENS_DELTA - V_FUDGE;
grpTasks.Top := V_TASKS_TOP - V_SENS_DELTA - V_FUDGE;
Height := V_HEIGHT - V_SENS_DELTA - V_FUDGE;
SensorType0.Enabled := true;
SensorType1.Enabled := true;
SensorType2.Enabled := true;
tmpSL.Clear;
tmpSL.Append(sRaw);
tmpSL.Append(sBoolean);
tmpSL.Append(sTransCount);
tmpSL.Append(sPeriodCount);
tmpSL.Append(sPercent);
tmpSL.Append(sCelsius);
tmpSL.Append(sFahrenheit);
tmpSL.Append(sAngle);
SensorMode0.Items.Assign(tmpSL);
SensorMode1.Items.Assign(tmpSL);
SensorMode2.Items.Assign(tmpSL);
tmpSL.Clear;
tmpSL.Append(sNone);
tmpSL.Append(sSwitch);
tmpSL.Append(sTemperature);
tmpSL.Append(sLight);
tmpSL.Append(sAngle);
SensorType0.Items.Assign(tmpSL);
SensorType1.Items.Assign(tmpSL);
SensorType2.Items.Assign(tmpSL);
end
else if IsScout then begin
// scout
SensorGroup.Visible := False;
grpMotors.Top := V_MOTORS_TOP - SensorGroup.Height - V_FUDGE;
grpVariables.Top := V_VARS_TOP - SensorGroup.Height - V_FUDGE;
grpTasks.Top := V_TASKS_TOP - SensorGroup.Height - V_FUDGE;
Height := V_HEIGHT - SensorGroup.Height - V_FUDGE;
end
else if IsNXT then begin
Height := V_HEIGHT - grpVariables.Height - grpTasks.Height - V_FUDGE;
SensorGroup.Height := V_SENS_H;
grpVariables.Visible := False;
grpTasks.Visible := False;
SensorGroup.Visible := True;
SensorType0.Enabled := true;
SensorType1.Enabled := true;
SensorType2.Enabled := true;
SensorType3.Enabled := true;
tmpSL.Clear;
tmpSL.Append(sRaw);
tmpSL.Append(sBoolean);
tmpSL.Append(sTransCount);
tmpSL.Append(sPeriodCount);
tmpSL.Append(sPercent);
tmpSL.Append(sCelsius);
tmpSL.Append(sFahrenheit);
tmpSL.Append(sAngle);
SensorMode0.Items.Assign(tmpSL);
SensorMode1.Items.Assign(tmpSL);
SensorMode2.Items.Assign(tmpSL);
SensorMode3.Items.Assign(tmpSL);
tmpSL.Clear;
tmpSL.Append(sNone);
tmpSL.Append(sSwitch);
tmpSL.Append(sTemperature);
tmpSL.Append(sLight);
tmpSL.Append(sAngle);
tmpSL.Append(sLightActiv);
tmpSL.Append(sLightInact);
tmpSL.Append(sSoundDB);
tmpSL.Append(sSoundDBA);
tmpSL.Append(sCustom);
tmpSL.Append(sLowspeed);
tmpSL.Append(sLowspeed9v);
tmpSL.Append(sHighspeed);
tmpSL.Append(sColorFull);
tmpSL.Append(sColorRed);
tmpSL.Append(sColorGreen);
tmpSL.Append(sColorBlue);
tmpSL.Append(sColorNone);
SensorType0.Items.Assign(tmpSL);
SensorType1.Items.Assign(tmpSL);
SensorType2.Items.Assign(tmpSL);
SensorType3.Items.Assign(tmpSL);
end
else if IsEV3 then begin
Height := V_HEIGHT - grpVariables.Height - grpTasks.Height - V_FUDGE;
SensorGroup.Height := V_SENS_H;
grpVariables.Visible := False;
grpTasks.Visible := False;
SensorGroup.Visible := True;
SensorType0.Enabled := true;
SensorType1.Enabled := true;
SensorType2.Enabled := true;
SensorType3.Enabled := true;
// blech
// sensor types
LoadTypeNames(tmpSL);
SensorType0.Items.Assign(tmpSL);
SensorType1.Items.Assign(tmpSL);
SensorType2.Items.Assign(tmpSL);
SensorType3.Items.Assign(tmpSL);
// EV3 mode names depend on the type
tmpSL.Clear;
tmpSL.Append('0');
tmpSL.Append('1');
tmpSL.Append('2');
tmpSL.Append('3');
tmpSL.Append('4');
tmpSL.Append('5');
tmpSL.Append('6');
tmpSL.Append('7');
SensorMode0.Items.Assign(tmpSL);
SensorMode1.Items.Assign(tmpSL);
SensorMode2.Items.Assign(tmpSL);
SensorMode3.Items.Assign(tmpSL);
end else begin
// cybermaster or spybot (sensor mode only)
delta := V_SENS_DELTA;
if IsSpybotic then
delta := delta * 2;
SensorGroup.Height := V_SENS_H - delta;
grpMotors.Top := V_MOTORS_TOP - delta - V_FUDGE;
grpVariables.Top := V_VARS_TOP - delta - V_FUDGE;
grpTasks.Top := V_TASKS_TOP - delta - V_FUDGE;
Height := V_HEIGHT - delta - V_FUDGE;
SensorGroup.Visible := True;
SensorType0.Enabled := false;
SensorType1.Enabled := false;
SensorType2.Enabled := false;
tmpSL.Clear;
if IsSpybotic then
begin
tmpSL.Append(sRaw);
tmpSL.Append(sBoolean);
tmpSL.Append(sPercent);
end
else
begin
tmpSL.Append(sRaw);
tmpSL.Append(sBoolean);
tmpSL.Append(sTransCount);
tmpSL.Append(sPeriodCount);
tmpSL.Append(sPercent);
end;
SensorMode0.Items.Assign(tmpSL);
SensorMode1.Items.Assign(tmpSL);
SensorMode2.Items.Assign(tmpSL);
tmpSL.Clear;
SensorType0.Items.Assign(tmpSL);
SensorType1.Items.Assign(tmpSL);
SensorType2.Items.Assign(tmpSL);
end;
finally
tmpSL.Free;
end;
// variables
if grpVariables.Visible then
begin
h := 31;
if IsScout then
h := 9;
VariableBox.Items.Clear;
for i := 0 to h do
VariableBox.Items.Add(Format('Var %2d',[i]));
VariableBox.ItemIndex := 0;
OperatorBox.ItemIndex := 0;
cboSource.ItemIndex := 2;
end;
try
{Set the motor items}
ttt := BrickComm.GetOutputStatus(0);
FwdABtn.Down := (ttt div 128 = 1) and ((ttt mod 16) div 8 = 1);
RevABtn.Down := (ttt div 128 = 1) and ((ttt mod 16) div 8 = 0);
OffABtn.Down := (ttt div 128 = 0) and ((ttt mod 128) div 64 = 1);
FloatABtn.Down := (ttt div 128 = 0) and ((ttt mod 128) div 64 = 0);
SpeedA.Position := ttt mod 8;
ttt := BrickComm.GetOutputStatus(1);
FwdBBtn.Down := (ttt div 128 = 1) and ((ttt mod 16) div 8 = 1);
RevBBtn.Down := (ttt div 128 = 1) and ((ttt mod 16) div 8 = 0);
OffBBtn.Down := (ttt div 128 = 0) and ((ttt mod 128) div 64 = 1);
FloatBBtn.Down := (ttt div 128 = 0) and ((ttt mod 128) div 64 = 0);
SpeedB.Position := ttt mod 8;
ttt := BrickComm.GetOutputStatus(2);
FwdCBtn.Down := (ttt div 128 = 1) and ((ttt mod 16) div 8 = 1);
RevCBtn.Down := (ttt div 128 = 1) and ((ttt mod 16) div 8 = 0);
OffCBtn.Down := (ttt div 128 = 0) and ((ttt mod 128) div 64 = 1);
FloatCBtn.Down := (ttt div 128 = 0) and ((ttt mod 128) div 64 = 0);
SpeedC.Position := ttt mod 8;
if IsEV3 then
begin
ttt := BrickComm.GetOutputStatus(3);
FwdDBtn.Down := (ttt div 128 = 1) and ((ttt mod 16) div 8 = 1);
RevDBtn.Down := (ttt div 128 = 1) and ((ttt mod 16) div 8 = 0);
OffDBtn.Down := (ttt div 128 = 0) and ((ttt mod 128) div 64 = 1);
FloatDBtn.Down := (ttt div 128 = 0) and ((ttt mod 128) div 64 = 0);
SpeedD.Position := ttt mod 8;
end;
if not IsScout then
begin
{ Set the sensor Items }
if IsRCX then
begin
SensorType0.ItemIndex := BrickComm.Poll(kRCX_InputTypeType,0);
SensorType1.ItemIndex := BrickComm.Poll(kRCX_InputTypeType,1);
SensorType2.ItemIndex := BrickComm.Poll(kRCX_InputTypeType,2);
end
else if IsNXT or IsEV3 then
begin
SensorType0.ItemIndex := BrickComm.Poll(kRCX_InputTypeType,0);
SensorType1.ItemIndex := BrickComm.Poll(kRCX_InputTypeType,1);
SensorType2.ItemIndex := BrickComm.Poll(kRCX_InputTypeType,2);
SensorType3.ItemIndex := BrickComm.Poll(kRCX_InputTypeType,3);
UpdateModes(SensorType0.ItemIndex, SensorMode0.Items);
UpdateModes(SensorType1.ItemIndex, SensorMode1.Items);
UpdateModes(SensorType2.ItemIndex, SensorMode2.Items);
UpdateModes(SensorType3.ItemIndex, SensorMode3.Items);
end;
ttt := BrickComm.Poll(kRCX_InputModeType,0);
if IsSpybotic then
SensorMode0.ItemIndex := SPY_MODES[ttt]
else
SensorMode0.ItemIndex := ttt div 32;
ttt := BrickComm.Poll(kRCX_InputModeType,1);
if IsSpybotic then
SensorMode1.ItemIndex := SPY_MODES[ttt]
else
SensorMode1.ItemIndex := ttt div 32;
if not IsSpybotic then
SensorMode2.ItemIndex := BrickComm.Poll(kRCX_InputModeType,2) div 32;
if IsNXT or IsEV3 then
SensorMode3.ItemIndex := BrickComm.Poll(kRCX_InputModeType,3) div 32;
end;
except
;
end;
end;
procedure TDirectForm.FormCreate(Sender: TObject);
var
scale_amount : double;
begin
scale_amount := Screen.PixelsPerInch / 96;
V_HEIGHT := Trunc(K_HEIGHT * scale_amount);
V_MOTORS_TOP := Trunc(K_MOTORS_TOP * scale_amount);
V_VARS_TOP := Trunc(K_VARS_TOP * scale_amount);
V_TASKS_TOP := Trunc(K_TASKS_TOP * scale_amount);
V_FUDGE := Trunc(K_FUDGE * scale_amount);
V_SENS_DELTA := Trunc(K_SENS_DELTA * scale_amount);
V_SENS_H := Trunc(K_SENS_H * scale_amount);
end;
procedure TDirectForm.btnHelpClick(Sender: TObject);
begin
Application.HelpContext(HelpContext);
end;
{$IFDEF FPC}
initialization
{$i Controller.lrs}
{$ENDIF}
end.