-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathwtlleds.c
More file actions
232 lines (184 loc) · 7.27 KB
/
wtlleds.c
File metadata and controls
232 lines (184 loc) · 7.27 KB
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
/* WACHTTIJD-LANTAARN MET LEDS */
/* =========================== */
/* (C) Copyright 2003-2023 by A.C.M. van Grinsven. All rights reserved. */
/* CCOL : versie 12.0.0 */
/* FILE : wtlled.c */
/* DATUM: 20-02-2023 */
/* include files */
/* ============= */
#include "sysdef.c" /* definitie typen variabelen */
#include "cif.inc" /* declaratie CVN C-interface */
#include "fcvar.h" /* declaratie fasecyclusvariabelen */
#include "tmvar.h" /* declaratie tijdvariabelen */
#include "mevar.h" /* declaratie geheugenvariabelen */
/* macrodefinities */
/* =============== */
#ifndef WTL_MAX_LEDS
#define WTL_MAX_LEDS 31 /* maximum aan te sturen tijdleds */
#endif
#define WTL_TIJD_MAX_LEDS 60 /* ledtijd (TE) bij negatieve waarde (PG[]/OS[]) */
/* definitie wachttijdfuncties */
/* =========================== */
/* de functie wachttijd_leds() verzorgt de aansturing van de leds van de wachttijd-
* lantaarn voor de opgegeven fasecyclus (fc) op basis van de berekende wachttijd
* (T_wacht_ber). de functie wachttijd_leds() geeft het aantal leds dat moet branden
* aan de procesbesturing door m.b.v. een uitgangssignaal (CIF_GUS[uswvt]).
* een wachttijd-lantaarn wordt aangestuurd, indien de opgegeven fasecyclus in
* rood verkeert en een aanvraag heeft. de wachttijd-lantaarn wordt niet aangestuurd
* indien de fasecyclus alleen een mee-aanvraag speciaal heeft (BIT5), omdat deze
* mee-aanvraag kan worden teruggezet.
* de functie gaat uit van een wachttijdlantaarn met 31 wacht-leds en de tekst 'WACHT.
* de functie verdeelt de berekende wachttijd evenredig over de nog brandende leds.
* het volgende led dooft indien de actuele waarde van de dooftijd (T_timer[twtv])
* groter of gelijk is aan de berekende wachttijd gedeeld door het aantal nog brandende
* leds. bij het doven van een led herstart de dooftijd.
* de functie wachttijd_leds()geeft als return-waarde het aantal leds dat moet branden.
*/
mulv wachttijd_leds(count fc, count uswtv, count twtv, mulv T_wacht_ber, mulv T_led_start)
{
/* fc - fasecyclusnummer */
/* uswtv - uitgangsnummer wachttijdlantaarn */
/* twtv - tijdelementnummer, dooftijd voor een led */
/* T_wacht_ber - waarde van de berekende wachttijd */
/* #define T_LED_START 2 * 2 tiendenseconden */
mulv aantal_leds; /* aantal brandende tijd-leds */
RT[twtv]= TRUE; /* set instructievariabele led-tijdmeting */
/* actueel brandende wachttijd-leds */
/* -------------------------------- */
aantal_leds= CIF_GUS[uswtv]; /* actueel aantal brandende tijd-leds */
if (aantal_leds>WTL_MAX_LEDS) {
aantal_leds= WTL_MAX_LEDS;
}
/* aantal wachttijd-leds */
/* --------------------- */
if (R[fc] && (A[fc] & (BIT0+BIT3))) /* rood en detectieaanvraag of starre aanvraag */
{
if (aantal_leds==0) /* start aansturing wachttijd-lantaarn */
{
if (T_wacht_ber>=0)
{
if (T_led_start>0) {
aantal_leds= T_wacht_ber/T_led_start;
}
}
else /* negatieve waarde - b.v. PG[ ] staat op */
{
aantal_leds= WTL_MAX_LEDS;
}
}
else /* tijdens aansturing */
{
if (T_wacht_ber>=0)
{
if (T_timer[twtv]>=((T_wacht_ber+T_timer[twtv])/aantal_leds))
{
aantal_leds--;
/* RT[twtv]= TRUE; */
}
else
{
RT[twtv]= FALSE;
}
}
else { /* negatieve waarde - b.v. PG[ ] staat op */
if (T_timer[twtv]>=WTL_TIJD_MAX_LEDS)
{
aantal_leds--;
/* RT[twtv]= TRUE; */
}
else
{
RT[twtv]= FALSE;
}
}
}
}
/* beveiliging bereik */
/* ------------------ */
if (aantal_leds<0) aantal_leds= 0;
if (aantal_leds>WTL_MAX_LEDS) aantal_leds= WTL_MAX_LEDS;
/* beveiliging groensturing */
/* ------------------------ */
if (G[fc]) aantal_leds= 0;
else if (R[fc] && A[fc] && !aantal_leds && CIF_GUS[uswtv]) aantal_leds= 1;
/* uitsturing wachttijdvoorspeller */
/* ------------------------------- */
CIF_GUS[uswtv]= aantal_leds;
return (mulv) aantal_leds;
}
/* de functie wachttijd_leds_mm() werkt in principe hetzelfde als de functie wachttijd_leds().
* het aantal nog brandende leds wordt nu naar een geheugenelement geschreven i.p.v. naar een uitgangssignaal.
* de functie wachttijd_leds()geeft als return-waarde het aantal leds dat moet branden.
*/
mulv wachttijd_leds_mm(count fc, count mmwtv, count twtv, mulv T_wacht_ber, mulv T_led_start)
{
/* fc - fasecyclusnummer */
/* mmwtv - uitgangsnummer wachttijdlantaarn */
/* twtv - tijdelementnummer, dooftijd voor een led */
/* T_wacht_ber - waarde van de berekende wachttijd */
/* #define T_LED_START 2 * 2 tiendenseconden */
mulv aantal_leds; /* aantal brandende tijd-leds */
RT[twtv]= TRUE; /* set instructievariabele led-tijdmeting */
/* actueel brandende wachttijd-leds */
/* -------------------------------- */
aantal_leds= MM[mmwtv]; /* actueel aantal brandende tijd-leds */
if (aantal_leds>WTL_MAX_LEDS) {
aantal_leds= WTL_MAX_LEDS;
}
/* aantal wachttijd-leds */
/* --------------------- */
if (R[fc] && (A[fc] & (BIT0+BIT3))) /* rood en aanvraag en geen mee-aanvraag speciaal */
{
if (aantal_leds==0) /* start aansturing wachttijd-lantaarn */
{
if (T_wacht_ber>=0)
{
if (T_led_start>0) {
aantal_leds= T_wacht_ber/T_led_start;
}
}
else /* negatieve waarde - b.v. PG[ ] staat op */
{
aantal_leds= WTL_MAX_LEDS;
}
}
else /* tijdens aansturing */
{
if (T_wacht_ber>=0)
{
if (T_timer[twtv]>=((T_wacht_ber+T_timer[twtv])/aantal_leds))
{
aantal_leds--;
/* RT[twtv]= TRUE; */
}
else
{
RT[twtv]= FALSE;
}
}
else { /* negatieve waarde - b.v. PG[ ] staat op */
if (T_timer[twtv]>=WTL_TIJD_MAX_LEDS)
{
aantal_leds--;
/* RT[twtv]= TRUE; */
}
else
{
RT[twtv]= FALSE;
}
}
}
}
/* beveiliging bereik */
/* ------------------ */
if (aantal_leds<0) aantal_leds= 0;
if (aantal_leds>WTL_MAX_LEDS) aantal_leds= WTL_MAX_LEDS;
/* beveiliging groensturing */
/* ------------------------ */
if (G[fc]) aantal_leds= 0;
else if (R[fc] && A[fc] && !aantal_leds && MM[mmwtv]) aantal_leds= 1;
/* uitsturing wachttijdvoorspeller */
/* ------------------------------- */
MM[mmwtv]= aantal_leds;
return (mulv) aantal_leds;
}