-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathCalibDlg.pas
193 lines (155 loc) · 5.05 KB
/
CalibDlg.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
//This Source Code Form is subject to the terms of the Mozilla Public
//License, v. 2.0. If a copy of the MPL was not distributed with this
//file, You can obtain one at http://mozilla.org/MPL/2.0/.
//Copyright (c) 2013 Alex Shovkoplyas VE3NEA
unit CalibDlg;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls, Spin, ComCtrls, Buttons, ImgList, AppEvnts,
VnaCli, Ini;
type
TCalibrationDialog = class(TForm)
Panel1: TPanel;
OkBtn: TButton;
GroupBox1: TGroupBox;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
SpinEdit1: TSpinEdit;
SpinEdit2: TSpinEdit;
SpinEdit3: TSpinEdit;
CheckBox1: TCheckBox;
ImageList1: TImageList;
LoadBtn: TSpeedButton;
SaveBtn: TSpeedButton;
ApplicationEvents1: TApplicationEvents;
SpeedButton1: TSpeedButton;
Panel2: TPanel;
GroupBox2: TGroupBox;
OpenBtn: TSpeedButton;
CalibrateSBtn: TSpeedButton;
CalibrateLBtn: TSpeedButton;
Panel3: TPanel;
Image1: TImage;
Panel4: TPanel;
Image2: TImage;
Panel5: TPanel;
Image3: TImage;
Panel6: TPanel;
OpenDialog1: TOpenDialog;
SaveDialog1: TSaveDialog;
FileNameLabel: TLabel;
procedure ApplicationEvents1Idle(Sender: TObject; var Done: Boolean);
procedure CalibrateBtnClick(Sender: TObject);
procedure LoadBtnClick(Sender: TObject);
procedure SaveBtnClick(Sender: TObject);
procedure SpeedButton1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormShow(Sender: TObject);
private
CalibrationType: integer;
function IsSameParams: boolean;
procedure ToDlg;
public
procedure ProcessScannedData(AData: TScanArray);
end;
var
CalibrationDialog: TCalibrationDialog;
implementation
{$R *.dfm}
uses
Main, ProgrDlg;
function TCalibrationDialog.IsSameParams: boolean;
begin
Result := ((SpinEdit1.Value * 1000) = MainForm.Clb.FreqB) and
((SpinEdit2.Value * 1000) = MainForm.Clb.FreqE) and
(SpinEdit3.Value = MainForm.Clb.PointCnt) and
(CheckBox1.Checked = MainForm.Clb.Atten);
end;
procedure TCalibrationDialog.ApplicationEvents1Idle(Sender: TObject;
var Done: Boolean);
var
SameParams: boolean;
begin
SameParams := IsSameParams;
if SameParams and (MainForm.Clb.DataO <> nil)
then Image1.Left := -16 else Image1.Left := 0;
if SameParams and (MainForm.Clb.DataS <> nil)
then Image2.Left := -16 else Image2.Left := 0;
if SameParams and (MainForm.Clb.DataL <> nil)
then Image3.Left := -16 else Image3.Left := 0;
SaveBtn.Enabled := MainForm.Clb.Changed;
end;
//start calibration
procedure TCalibrationDialog.CalibrateBtnClick(Sender: TObject);
begin
if MainForm.Cli.State < vsRunning then begin Beep; Exit; end;
CalibrationType := (Sender as TSpeedButton).Tag;
MainForm.Cli.SetAtten(CheckBox1.Checked);
MainForm.Cli.Scan(SpinEdit1.Value * 1000, SpinEdit2.Value * 1000, SpinEdit3.Value);
ProgressDialog.ProgressBar1.Position := 0;
ProgressDialog.ShowModal;
end;
procedure TCalibrationDialog.FormCreate(Sender: TObject);
var
Dir: TFileName;
begin
Dir := GetIniFolder + 'Calibration';
ForceDirectories(Dir);
OpenDialog1.InitialDir := Dir;
SaveDialog1.InitialDir := Dir;
end;
procedure TCalibrationDialog.FormShow(Sender: TObject);
begin
ToDlg;
end;
procedure TCalibrationDialog.ToDlg;
begin
SpinEdit1.Value := Round(MainForm.Clb.FreqB / 1000);
SpinEdit2.Value := Round(MainForm.Clb.FreqE / 1000);
SpinEdit3.Value := MainForm.Clb.PointCnt;
CheckBox1.Checked := MainForm.Clb.Atten;
FileNameLabel.Caption := 'Calibration File: ' + ExtractFileName(MainForm.Clb.FileName);
FileNameLabel.Hint := MainForm.Clb.FileName;
end;
//scan finished
procedure TCalibrationDialog.ProcessScannedData(AData: TScanArray);
begin
//calibration preformed for different parameters, erase old data
if not IsSameParams then MainForm.Clb.SetParams(SpinEdit1.Value * 1000,
SpinEdit2.Value * 1000, SpinEdit3.Value, CheckBox1.Checked);
//store new data
case CalibrationType of
1: MainForm.Clb.DataO := AData;
2: MainForm.Clb.DataS := AData;
3: MainForm.Clb.DataL := AData;
end;
MainForm.Clb.Changed := true;
end;
//load calibration data
procedure TCalibrationDialog.LoadBtnClick(Sender: TObject);
begin
if not OpenDialog1.Execute then Exit;
MainForm.Clb.LoadFromFile(OpenDialog1.FileName);
ToDlg;
end;
//save calibration data
procedure TCalibrationDialog.SaveBtnClick(Sender: TObject);
begin
if not SaveDialog1.Execute then Exit;
Screen.Cursor := crHourGlass;
try
MainForm.Clb.SaveToFile(SaveDialog1.FileName);
ToDlg;
finally
Screen.Cursor := crDefault;
end;
end;
//erase calibration data
procedure TCalibrationDialog.SpeedButton1Click(Sender: TObject);
begin
MainForm.Clb.SetParams(SpinEdit1.Value * 1000,
SpinEdit2.Value * 1000, SpinEdit3.Value, CheckBox1.Checked);
end;
end.