-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathGPIOConnections.pas
286 lines (271 loc) · 6.71 KB
/
GPIOConnections.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
unit GPIOConnections;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ExtCtrls,
StdCtrls, Buttons, Main;
type
{ TFormGpioConnections }
TFormGpioConnections = class(TForm)
btnCancel: TBitBtn;
btnOk: TBitBtn;
cbGpio10: TComboBox;
cbGpio11: TComboBox;
cbGpio12: TComboBox;
cbGpio13: TComboBox;
cbGpio14: TComboBox;
cbGpio15: TComboBox;
cbGpio16: TComboBox;
cbGpio17: TComboBox;
cbGpio18: TComboBox;
cbGpio19: TComboBox;
cbGpio2: TComboBox;
cbGpio20: TComboBox;
cbGpio21: TComboBox;
cbGpio22: TComboBox;
cbGpio23: TComboBox;
cbGpio24: TComboBox;
cbGpio25: TComboBox;
cbGpio26: TComboBox;
cbGpio27: TComboBox;
cbGpio3: TComboBox;
cbGpio4: TComboBox;
cbGpio5: TComboBox;
cbGpio6: TComboBox;
cbGpio7: TComboBox;
cbGpio8: TComboBox;
cbGpio9: TComboBox;
GroupBox1: TGroupBox;
ImgPin_1: TImage;
ImgPin_10: TImage;
ImgPin_11: TImage;
ImgPin_12: TImage;
ImgPin_13: TImage;
ImgPin_14: TImage;
ImgPin_15: TImage;
ImgPin_16: TImage;
ImgPin_17: TImage;
ImgPin_18: TImage;
ImgPin_19: TImage;
ImgPin_2: TImage;
ImgPin_20: TImage;
ImgPin_21: TImage;
ImgPin_22: TImage;
ImgPin_23: TImage;
ImgPin_24: TImage;
ImgPin_25: TImage;
ImgPin_26: TImage;
ImgPin_27: TImage;
ImgPin_28: TImage;
ImgPin_29: TImage;
ImgPin_3: TImage;
ImgPin_30: TImage;
ImgPin_31: TImage;
ImgPin_32: TImage;
ImgPin_33: TImage;
ImgPin_34: TImage;
ImgPin_35: TImage;
ImgPin_36: TImage;
ImgPin_37: TImage;
ImgPin_38: TImage;
ImgPin_39: TImage;
ImgPin_4: TImage;
ImgPin_40: TImage;
ImgPin_41: TImage;
ImgPin_42: TImage;
ImgPin_43: TImage;
ImgPin_5: TImage;
ImgPin_6: TImage;
ImgPin_7: TImage;
ImgPin_8: TImage;
ImgPin_9: TImage;
Label1: TLabel;
Label10: TLabel;
Label11: TLabel;
Label12: TLabel;
Label13: TLabel;
Label14: TLabel;
Label15: TLabel;
Label16: TLabel;
Label17: TLabel;
Label18: TLabel;
Label19: TLabel;
Label2: TLabel;
Label20: TLabel;
Label21: TLabel;
Label22: TLabel;
Label23: TLabel;
Label24: TLabel;
Label25: TLabel;
Label26: TLabel;
Label27: TLabel;
Label28: TLabel;
Label29: TLabel;
Label3: TLabel;
Label30: TLabel;
Label31: TLabel;
Label32: TLabel;
Label33: TLabel;
Label34: TLabel;
Label35: TLabel;
Label36: TLabel;
Label37: TLabel;
Label38: TLabel;
Label39: TLabel;
Label4: TLabel;
Label40: TLabel;
Label41: TLabel;
Label42: TLabel;
Label5: TLabel;
Label6: TLabel;
Label7: TLabel;
Label8: TLabel;
Label9: TLabel;
Panel1: TPanel;
Panel2: TPanel;
Panel3: TPanel;
procedure CheckAssignedConnection(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ private declarations }
FGpioControls: TGpioControls;
procedure SetGpioControls(GpioControls: TGpioControls);
function GetGpioWirings: TGpioWirings;
public
{ public declarations }
property GpioControls: TGpioControls read FGpioControls write SetGpioControls;
property GpioWirings: TGpioWirings read GetGpioWirings;
end;
var
FormGpioConnections: TFormGpioConnections;
implementation
uses LCLType;
{$R *.lfm}
{
checks all combos to avoid same GPIO assigned to different controls
}
procedure TFormGpioConnections.CheckAssignedConnection(Sender: TObject);
var
i: integer;
can_assign: boolean;
msgtext: string;
msgcaption: string;
answer: integer;
begin
// only assignet to comboboxes
can_assign := true;
if Sender is TComboBox then
begin
// ItemIndex = 0 means no control assigned
if TComboBox(Sender).ItemIndex > 0 then
begin
with FormGpioConnections do
begin
for i := 0 to ControlCount -1 do
begin
if Controls[i] is TComboBox then
begin
if Controls[i] <> Sender then
begin
if TComboBox(Controls[i]).ItemIndex = TComboBox(Sender).ItemIndex then
begin
msgtext := Format(
'Wiring connection for %s already assigned to GPIO %d.'+#13+
'Override connection for GPIO %d ?',
[TComboBox(Sender).Items[TComboBox(Sender).ItemIndex],
Controls[i].Tag,
Controls[i].Tag ]);
msgcaption := 'Wiring conflict';
can_assign := false;
answer := MessageDlg(msgcaption,msgtext, mtConfirmation,[mbYes,mbNo],0);
if answer = IDYES then
begin
TComboBox(Controls[i]).ItemIndex := 0;
end
else
begin
TComboBox(Sender).ItemIndex := 0;
end;
break;
end;
end;
end;
end;
end;
end;
end;
end;
{
populate Wiring comboboxes with list of main's unit defined connections
}
procedure TFormGpioConnections.FormCreate(Sender: TObject);
var
i: integer;
gc: TGpioControl;
begin
with FormGpioConnections do
begin
for i := 0 to ControlCount -1 do
begin
if Controls[i] is TComboBox then
begin
TComboBox(Controls[i]).Items.Clear;
for gc := Low(TGpioControl) to High(TGpioControl) do
begin
TComboBox(Controls[i]).Items.Add(GPIOWiringsDesc[gc]);
end;
end;
end;
end;
end;
{
Update comboboxes' ItemIndex upon values from passed GpioControls
uses control's TAG value, which must be set to corresponding GPIO port
number for each combobox.
}
procedure TFormGpioConnections.SetGpioControls(GpioControls: TGpioControls);
var
i: integer;
begin
FGpioControls := GpioControls;
with FormGpioConnections do
begin
for i := 0 to ControlCount -1 do
begin
if Controls[i] is TComboBox then
begin
TComboBox(Controls[i]).ItemIndex := ord(FGpioControls[Controls[i].Tag]);
end;
end;
end;
end;
{
Update FGpioWinrings to reflect current Wiring connections
TGpioWirings = array[TGpioControl] of longint;
}
function TFormGpioConnections.GetGpioWirings: TGpioWirings;
var
gc :TGpioControl;
gw :TGpioWirings;
i: integer;
begin
for gc := Low(TGpioControl) to High(TGpioControl) do
begin
gw[gc] := 0;
end;
with FormGpioConnections do
begin
for i := 0 to ControlCount -1 do
begin
if Controls[i] is TComboBox then
begin
if TComboBox(Controls[i]).ItemIndex <> 0 then
begin
gw[TGpioControl(TComboBox(Controls[i]).ItemIndex)] := Controls[i].Tag;
end;
end;
end;
end;
GetGpioWirings := gw;
end;
end.