-
Notifications
You must be signed in to change notification settings - Fork 0
/
utimeconfig.pas
150 lines (126 loc) · 3.9 KB
/
utimeconfig.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
//-----------------------------------------------------------------------------
// USB / Serial, Multi Channel Timer Programmer Console.
// System time window.
//
// Copyright (C) 2020 SriKIT contributors.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
//
// Last updated: Dilshan Jayakody [24th Nov 2020]
//
// Update log:
// [24/11/2020] - Initial version - Dilshan Jayakody.
//-----------------------------------------------------------------------------
unit utimeconfig;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, ComCtrls,
ExtCtrls, ucommon;
type
{ TfrmTimeConfig }
TfrmTimeConfig = class(TForm)
bvPCTimeFrame: TBevel;
btnSync: TButton;
btnClose: TButton;
btnSyncToPC: TButton;
btnReload: TButton;
cmbMonth: TComboBox;
lblTimeView: TLabel;
lblDate: TLabel;
lblMonth: TLabel;
lblHour: TLabel;
lblMinute: TLabel;
lblSeconds: TLabel;
lblSystemDate: TLabel;
lblSystemTime: TLabel;
lblPCTime: TLabel;
lblYear: TLabel;
tmrPCClockSync: TTimer;
txtDate: TEdit;
txtHour: TEdit;
txtMinute: TEdit;
txtSeconds: TEdit;
txtYear: TEdit;
updDate: TUpDown;
updHour: TUpDown;
updMinute: TUpDown;
updSeconds: TUpDown;
updYear: TUpDown;
mainWindow: TForm;
procedure btnCloseClick(Sender: TObject);
procedure btnReloadClick(Sender: TObject);
procedure btnSyncClick(Sender: TObject);
procedure btnSyncToPCClick(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure tmrPCClockSyncTimer(Sender: TObject);
private
public
procedure SetMainWindow(mForm: TForm);
procedure SetSystemTime(sysTime: TTimeInfo);
end;
var
frmTimeConfig: TfrmTimeConfig;
implementation
uses
umain;
{$R *.lfm}
{ TfrmTimeConfig }
procedure TfrmTimeConfig.SetMainWindow(mForm: TForm);
begin
mainWindow := mForm;
end;
procedure TfrmTimeConfig.tmrPCClockSyncTimer(Sender: TObject);
begin
lblTimeView.Caption := FormatDateTime('mmmm d - yyyy hh:nn:ss', Now);
end;
procedure TfrmTimeConfig.FormShow(Sender: TObject);
begin
// Set current PC time on UI.
Self.CancelControl := btnClose;
tmrPCClockSyncTimer(Sender);
end;
procedure TfrmTimeConfig.btnReloadClick(Sender: TObject);
begin
TfrmMain(mainWindow).GetSystemTime();
end;
procedure TfrmTimeConfig.btnSyncClick(Sender: TObject);
begin
// Set date/time to the given values.
TfrmMain(mainWindow).SetSystemTime((updYear.Position - 2000), (cmbMonth.ItemIndex + 1), updDate.Position, updHour.Position, updMinute.Position, updSeconds.Position);
ModalResult := mrOK;
end;
procedure TfrmTimeConfig.btnSyncToPCClick(Sender: TObject);
var
pcTime: TTimeInfo;
begin
// Set date/time to the PC date/time.
pcTime := DateTimeToTimeInfo(Now);
TfrmMain(mainWindow).SetSystemTime((pcTime.Year - 2000), pcTime.Month, pcTime.Date, pcTime.Hour, pcTime.Minute, pcTime.Second);
ModalResult := mrOK;
end;
procedure TfrmTimeConfig.btnCloseClick(Sender: TObject);
begin
ModalResult := mrClose;
end;
procedure TfrmTimeConfig.SetSystemTime(sysTime: TTimeInfo);
begin
updYear.Position := sysTime.Year + 2000;
cmbMonth.ItemIndex := (sysTime.Month - 1);
updDate.Position := sysTime.Date;
updHour.Position := sysTime.Hour;
updMinute.Position := sysTime.Minute;
updSeconds.Position := sysTime.Second;
end;
end.