blob: 967d2ea1de36b04d1defc839cea2a5efb2444fbc (
plain) (
blame)
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
|
unit ULight;
interface
type
TLight = class
private
Enabled: boolean;
Light: array[0..7] of boolean;
LightTime: array[0..7] of real; // time to stop, need to call update to change state
LastTime: real;
public
constructor Create;
procedure Enable;
procedure SetState(State: integer);
procedure AutoSetState;
procedure TurnOn;
procedure TurnOff;
procedure LightOne(Number: integer; Time: real);
procedure Refresh;
end;
var
Light: TLight;
const
Data = $378; // default port address
Status = Data + 1;
Control = Data + 2;
implementation
uses
SysUtils, zlportio, UTime;
constructor TLight.Create;
begin
Enabled := false;
end;
procedure TLight.Enable;
begin
Enabled := true;
LastTime := GetTime;
end;
procedure TLight.SetState(State: integer);
begin
if Enabled then
PortWriteB($378, State);
end;
procedure TLight.AutoSetState;
var
State: integer;
begin
if Enabled then begin
State := 0;
if Light[0] then State := State + 2;
if Light[1] then State := State + 1;
// etc
SetState(State);
end;
end;
procedure TLight.TurnOn;
begin
if Enabled then
SetState(3);
end;
procedure TLight.TurnOff;
begin
if Enabled then
SetState(0);
end;
procedure TLight.LightOne(Number: integer; Time: real);
begin
if Enabled then begin
if Light[Number] = false then begin
Light[Number] := true;
AutoSetState;
end;
LightTime[Number] := GetTime + Time/1000; // [s]
end;
end;
procedure TLight.Refresh;
var
Time: real;
TimeSkip: real;
L: integer;
begin
if Enabled then begin
Time := GetTime;
TimeSkip := Time - LastTime;
for L := 0 to 7 do begin
if Light[L] = true then begin
if LightTime[L] > Time then begin
// jest jeszcze zapas - bez zmian
//LightTime[L] := LightTime[L] - TimeSkip;
end else begin
// czas minal
Light[L] := false;
end;
end;
end;
LastTime := Time;
AutoSetState;
end;
end;
end.
|