-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmyTimerAct.java
More file actions
executable file
·333 lines (314 loc) · 11.5 KB
/
myTimerAct.java
File metadata and controls
executable file
·333 lines (314 loc) · 11.5 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
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
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
/*
* myTimerAct.java
* actuated timing clock for green phase ONLY
* Created on February 22, 2007, 4:44 PM
*/
/**
* @author Chen-Fu Liao
* Sr. Systems Engineer
* ITS Institute, ITS Laboratory
* Center For Transportation Studies
* University of Minnesota
* 200 Transportation and Safety Building
* 511 Washington Ave. SE
* Minneapolis, MN 55455
*/
public class myTimerAct {
// private float currentCount=0f ; // current timer count
private long tLast, tNow ;
private Runnable runThread0 ;
private Thread tTimer ;
private boolean timerPaused = true ;
private boolean max_out = false ;
private boolean gap_out = false ;
private boolean init_out = false ;
//private boolean extention_ready = false ;
private float grn_initial = 0 ; // INIT counter
private float grn_extension = 0 ; // EXT counter
private float grn_maximum = 0 ; // MAX counter
private float last_initial = 0 ; // last intial when using step sim
private float last_extension = 0 ; // last intial when using step sim
private float last_maximum = 0 ; // last intial when using step sim
private float Setting_EXT = 0 ; // EXT setting
private float Setting_INI = 0 ; // INIT setting
private float Setting_MAX = 0 ; // MAX setting
private boolean EXT_start = false ;
private boolean hold_recall_flag = false ; // hold max & extension counter on recall phase
public boolean stepSim = false ; // sec by sec simulation, if true
private boolean first_start = true ;
public float elapsedTimeSec = 0f ;
// 4/1/08 added
public boolean extension_reset_flag = false ; // extension clock was reset at previous step, if true
public boolean step_finished = true ;
/** Creates a new instance of myTimer */
public myTimerAct() {
init() ;
}
private void init() {
runThread0 = new Runnable() {
public void run() {
while (true) {
if (!timerPaused){
step_finished = false ;
// Get elapsed time in milliseconds
long tNow = System.currentTimeMillis() ;
if (!first_start) {
if (grn_maximum<=0f) {
// MAX out
grn_maximum = 0f ;
max_out = true ; // set max_out flag
timerPaused = true ; // pause timer
} // if grn_maximum<=0f
if (grn_extension<=0f) {
// GAP out
grn_extension=0f ;
gap_out = true ; // set gap_out flag
//timerPaused = true ; // pause timer
} // if grn_extension<=0f
if (!timerPaused){
// =============================================
long elapsedTimeMillis = tNow-tLast;
// Get elapsed time in seconds
elapsedTimeSec = elapsedTimeMillis/1000f;
if (stepSim) {
last_initial = grn_initial ;
last_extension = grn_extension ;
last_maximum = grn_maximum ;
elapsedTimeSec = 1.0f ; // 1 seconf step simulation
} // end if stepSim
grn_initial -= elapsedTimeSec ;
if (hold_recall_flag) {
grn_extension = Setting_EXT ;
grn_maximum = Setting_MAX ;
extension_reset_flag = false ;
} else {
grn_maximum -= elapsedTimeSec ;
//grn_extension -= elapsedTimeSec ;
// 4/1/08 added
if (extension_reset_flag) {
// extension clock was reset at previous step
// hold MAX extension for one step
extension_reset_flag = false ;
} else {
grn_extension -= elapsedTimeSec ;
}
} // end if
if (grn_initial<0f) {
grn_initial = 0f ;
init_out = true ;
} // end if
if (grn_maximum<=0f) {
// max out
grn_maximum = 0f ;
} // if grn_maximum<=0f
if (grn_extension<=0f) {
// gap out
grn_extension=0f ;
} // if grn_extension<=0f
} // if not paused
// ===============================
} else {
first_start = false ;
} // end if first_stop
tLast = tNow ;
if (stepSim) {
timerPaused = true ; // stop the loop after one 1-sec step
step_finished = true ;
}
//System.out.println("actuatedGreen INIT="+grn_initial+", EXT="+grn_extension) ;
try {Thread.sleep(100) ;}
catch (InterruptedException ie) {} ;
} else { // motion paused
// Get current time
//tLast = System.currentTimeMillis();
//tTimer.yield();
try {Thread.sleep(200) ;}
catch (InterruptedException ie) {} ;
} // end if timer paused
} // while loop
} // void run
} ; // runThread 0
tTimer = new Thread(runThread0, "Timer") ;
tTimer.start() ;
grn_initial = 0f ; // INIT
grn_extension = 0f ; // EXT
grn_maximum = 0f ; // MAX
}
public void start() {
hold_recall_flag = false ;
EXT_start = false ;
Setting_EXT = grn_extension ;
Setting_INI = grn_initial ;
Setting_MAX = grn_maximum ;
tLast = System.currentTimeMillis();
max_out = false ;
gap_out = false ;
init_out = false ;
timerPaused = false ;
first_start = true ;
}
public void resume() {
timerPaused = false ;
tLast = System.currentTimeMillis();
}
public void clear() {
max_out = false ;
gap_out = false ;
init_out = false ;
}
public void pause() {
timerPaused = true ;
}
// reset timer
public boolean isMaxOut() {
if (stepSim) {
do { // wait till step finished
try {Thread.sleep(50) ;}
catch (InterruptedException ie) {} ;
} while (!step_finished) ;
}
return max_out ;
}
public boolean isGapOut() {
if (stepSim) {
do { // wait till step finished
try {Thread.sleep(50) ;}
catch (InterruptedException ie) {} ;
} while (!step_finished) ;
}
return gap_out ;
}
public boolean isInitOut() {
if (stepSim) {
do { // wait till step finished
try {Thread.sleep(50) ;}
catch (InterruptedException ie) {} ;
} while (!step_finished) ;
}
return init_out ;
}
// actuated timers
public void set_extension(float _ext) {
gap_out = false ;
grn_extension = _ext ;
//System.out.println("actuatedGreen EXT="+grn_extension) ;
}
public void set_initial(float _initial) {
grn_initial = _initial ;
}
public void set_maximum(float _maximum) {
grn_maximum = _maximum ;
}
// get EXT, INIT, MAX count
public float get_extension() {
return grn_extension ;
}
public float get_initial() {
return grn_initial ;
}
public float get_maximum() {
return grn_maximum ;
}
public float getCount() {
float count ;
if (grn_extension<grn_maximum) {
count = grn_extension ;
} else {
count = grn_maximum ;
}
return count ;
}
public void hold_recall(boolean state) {
hold_recall_flag = state ;
}
public void stepBack() {
grn_initial = last_initial ;
grn_extension = last_extension ;
grn_maximum = last_maximum ;
}
public void resetTimer() {
grn_initial = Setting_INI ;
grn_extension = Setting_EXT ;
grn_maximum = Setting_MAX ;
//System.out.println("RESET timers INIT="+grn_initial+", EXT="+grn_extension+", MAX="+grn_maximum) ;
} // reset Timers
// public methods
public boolean getTimerPaused() {
return timerPaused ;
}
public void setTimerPaused(boolean status) {
timerPaused = status ;
}
public boolean getMaxOut() {
return max_out ;
}
public void setMaxOut(boolean status) {
max_out = status ;
}
public boolean getGapOut() {
return gap_out ;
}
public void setGapOut(boolean status) {
gap_out = status ;
}
public boolean getInitOut() {
return init_out ;
}
public void setInitOut(boolean status) {
init_out = status ;
}
public float get_lastextension() {
return last_extension ;
}
public float get_lastinitial() {
return last_initial ;
}
public float get_lastmaximum() {
return last_maximum ;
}
public void set_lastextension(float _ext) {
last_extension = _ext ;
}
public void set_lastinitial(float _initial) {
last_initial = _initial ;
}
public void set_lastmaximum(float _maximum) {
last_maximum = _maximum ;
}
public float get_setting_EXT() {
return Setting_EXT ;
}
public float get_setting_INI() {
return Setting_INI ;
}
public float get_setting_MAX() {
return Setting_MAX ;
}
public void set_setting_EXT(float _ext) {
Setting_EXT = _ext ;
}
public void set_setting_INI(float _initial) {
Setting_INI = _initial ;
}
public void set_setting_MAX(float _maximum) {
Setting_MAX = _maximum ;
}
public boolean get_EXT_start() {
return EXT_start ;
}
public void set_EXT_start(boolean status) {
EXT_start = status ;
}
public boolean get_hold_recall_flag() {
return hold_recall_flag ;
}
public void set_hold_recall_flag(boolean status) {
hold_recall_flag = status ;
}
public boolean get_first_start() {
return first_start ;
}
public void set_first_start(boolean status) {
first_start = status ;
}
}