Tscope5
timer.c
Go to the documentation of this file.
1 
2 
3 
4 
5 
6 
7 
8 
9 
10 
11 
12 
13 #include "../include/tscope5/timer.h"
14 #include "../include/tscope5/timer_internal.h"
15 #include "../include/tscope5/system_internal.h"
16 
17 
24 
25 
26 
27 
33 double ts5_get_time()
34 {
35  ts5_check_timer("ts5_get_time");
36  ts5_log(TS5_LOGLEVEL_5, "ts5_get_time()\n");
37 
38  return al_get_time();
39 }
40 
41 
45 void ts5_wait(double waittime)
46 {
47  ts5_check_timer("ts5_wait");
48  ts5_log(TS5_LOGLEVEL_5, "ts5_wait(%f)\n", waittime);
49 
50  // only use up cpu during the last 20 ms.
51  double starttime = al_get_time();
52 
53  if (waittime > 0.02) {
54  al_rest(waittime - 0.02);
55  }
56 
57  while (al_get_time() < starttime+waittime) {
58 
59  }
60 }
61 
62 
66 void ts5_wait_until(double deadline)
67 {
68  ts5_check_timer("ts5_wait_until");
69  ts5_log(TS5_LOGLEVEL_5, "ts5_wait_until(%f)\n", deadline);
70 
71  // only use up cpu during the last 20 ms.
72  double starttime = al_get_time();
73 
74  if (deadline - starttime > 0.02) {
75  al_rest(deadline - starttime - 0.02);
76  }
77 
78  while (al_get_time() < deadline) {
79 
80  }
81 }
82 
83 
85 
86 
87 
88 
108 
109 
110 
111 
124 {
125  ts5_check_timer("ts5_hide_response_key");
126  ts5_check_timer2("ts5_hide_response_key");
127  ts5_log(TS5_LOGLEVEL_3, "ts5_hide_response_key(%d)\n", key);
128 
129  if (key<0 || key>_ts5_status.timer_status.num_defined_buttons) {
130  ts5_fatal("ts5_hide_response_key: key argument is %d, there are %d reponse buttons defined\n",
131  key, _ts5_status.timer_status.num_defined_buttons);
132  }
133 
134  // reactivate
135  int found = 1;
136 
137  if (key==0) {
138 
139  int i, j;
140 
141  if (_ts5_status.timer_status.mouse_is_response_device) {
142 
143  for (i=0; i<_ts5_status.timer_status.mouse.num_buttons; i++) {
144 
145  _ts5_status.timer_status.mouse.button_press_active[i] =
146  _ts5_status.timer_status.mouse.button_press_defined[i];
147 
148  _ts5_status.timer_status.mouse.button_release_active[i] =
149  _ts5_status.timer_status.mouse.button_release_defined[i];
150  }
151 
152  _ts5_status.timer_status.mouse.num_active_buttons =
153  _ts5_status.timer_status.mouse.num_defined_buttons;
154  }
155 
156  if (_ts5_status.timer_status.keyboard_is_response_device) {
157 
158  for (i=0; i<_ts5_status.timer_status.keyboard.num_buttons; i++) {
159 
160  _ts5_status.timer_status.keyboard.button_press_active[i] =
161  _ts5_status.timer_status.keyboard.button_press_defined[i];
162 
163  _ts5_status.timer_status.keyboard.button_release_active[i] =
164  _ts5_status.timer_status.keyboard.button_release_defined[i];
165  }
166 
167  _ts5_status.timer_status.keyboard.num_active_buttons =
168  _ts5_status.timer_status.keyboard.num_defined_buttons;
169  }
170 
171  if (_ts5_status.timer_status.joystick_is_response_device) {
172 
173  for (i=0; i<_ts5_status.timer_status.num_joystick; i++) {
174 
175  for (j=0; j<_ts5_status.timer_status.joystick[i].num_buttons; j++) {
176 
177  _ts5_status.timer_status.joystick[i].button_press_active[j] =
178  _ts5_status.timer_status.joystick[i].button_press_defined[j];
179 
180  _ts5_status.timer_status.joystick[i].button_release_active[j] =
181  _ts5_status.timer_status.joystick[i].button_release_defined[j];
182  }
183  _ts5_status.timer_status.joystick[i].num_active_buttons =
184  _ts5_status.timer_status.joystick[i].num_defined_buttons;
185  }
186  }
187 
188  if (_ts5_status.timer_status.cedrusbox_is_response_device) {
189 
190  for (i=0; i<_ts5_status.timer_status.num_cedrusbox; i++) {
191 
192  for (j=0; j<_ts5_status.timer_status.cedrusbox[i].num_buttons; j++) {
193 
194  _ts5_status.timer_status.cedrusbox[i].button_press_active[j] =
195  _ts5_status.timer_status.cedrusbox[i].button_press_defined[j];
196 
197  _ts5_status.timer_status.cedrusbox[i].button_release_active[j] =
198  _ts5_status.timer_status.cedrusbox[i].button_release_defined[j];
199  }
200  _ts5_status.timer_status.cedrusbox[i].num_active_buttons =
201  _ts5_status.timer_status.cedrusbox[i].num_defined_buttons;
202  }
203  }
204  _ts5_status.timer_status.num_active_buttons = _ts5_status.timer_status.num_defined_buttons;
205  }
206  else {
207  int i, j;
208  found=0;
209 
210  if (_ts5_status.timer_status.mouse_is_response_device) {
211 
212  for (i=0; i<_ts5_status.timer_status.mouse.num_buttons; i++) {
213 
214  if (key==_ts5_status.timer_status.mouse.button_press_active[i]) {
215  _ts5_status.timer_status.mouse.button_press_active[i] = 0;
216  found = 1;
217  }
218  else if (key==_ts5_status.timer_status.mouse.button_release_active[i]) {
219  _ts5_status.timer_status.mouse.button_release_active[i] = 0;
220  found = 1;
221  }
222 
223  if (found) {
224  _ts5_status.timer_status.mouse.num_active_buttons--;
225  _ts5_status.timer_status.num_active_buttons--;
226  goto end;
227  }
228  }
229  }
230 
231  if (_ts5_status.timer_status.keyboard_is_response_device) {
232 
233  for (i=0; i<_ts5_status.timer_status.keyboard.num_buttons; i++) {
234 
235  if (key==_ts5_status.timer_status.keyboard.button_press_active[i]) {
236  _ts5_status.timer_status.keyboard.button_press_active[i] = 0;
237  found = 1;
238  }
239  else if (key==_ts5_status.timer_status.keyboard.button_release_active[i]) {
240  _ts5_status.timer_status.keyboard.button_release_active[i] = 0;
241  found = 1;
242  }
243 
244  if (found) {
245  _ts5_status.timer_status.keyboard.num_active_buttons--;
246  _ts5_status.timer_status.num_active_buttons--;
247  goto end;
248  }
249  }
250  }
251 
252  if (_ts5_status.timer_status.joystick_is_response_device) {
253 
254  for (i=0; i<_ts5_status.timer_status.num_joystick; i++) {
255 
256  for (j=0; j<_ts5_status.timer_status.joystick[i].num_buttons; j++) {
257 
258  if (key==_ts5_status.timer_status.joystick[i].button_press_active[j]) {
259  _ts5_status.timer_status.joystick[i].button_press_active[j] = 0;
260  found = 1;
261  }
262  else if (key==_ts5_status.timer_status.joystick[i].button_release_active[j]) {
263  _ts5_status.timer_status.joystick[i].button_release_active[j] = 0;
264  found = 1;
265  }
266 
267  if (found) {
268  _ts5_status.timer_status.joystick[i].num_active_buttons--;
269  _ts5_status.timer_status.num_active_buttons--;
270  goto end;
271  }
272  }
273  }
274  }
275 
276  if (_ts5_status.timer_status.cedrusbox_is_response_device) {
277 
278  for (i=0; i<_ts5_status.timer_status.num_cedrusbox; i++) {
279 
280  for (j=0; j<_ts5_status.timer_status.cedrusbox[i].num_buttons; j++) {
281 
282  if (key==_ts5_status.timer_status.cedrusbox[i].button_press_active[j]) {
283  _ts5_status.timer_status.cedrusbox[i].button_press_active[j] = 0;
284  found = 1;
285  }
286  else if (key==_ts5_status.timer_status.cedrusbox[i].button_release_active[j]) {
287  _ts5_status.timer_status.cedrusbox[i].button_release_active[j] = 0;
288  found = 1;
289  }
290 
291  if (found) {
292  _ts5_status.timer_status.cedrusbox[i].num_active_buttons--;
293  _ts5_status.timer_status.num_active_buttons--;
294  goto end;
295  }
296  }
297  }
298  }
299  }
300 
301  end:
302 
303  if (!found) {
304  ts5_fatal("ts5_hide_response_key: response key %d not found\n", key);
305  }
306 
307  if (_ts5_status.timer_status.num_active_buttons<1) {
308  ts5_fatal("ts5_hide_response_key: there are no active response buttons left\n");
309  }
310 
311  return _ts5_status.timer_status.num_active_buttons;
312 }
313 
314 
319 {
320  ts5_check_timer("ts5_remove_response_keys");
321  ts5_log(TS5_LOGLEVEL_3, "ts5_remove_response_keys()\n");
322 
323  int i, j;
324 
325  // mouse
326  if (_ts5_status.timer_status.mouse_is_response_device) {
327 
328  for (i=0; i<_ts5_status.timer_status.mouse.num_buttons; i++) {
329 
330  _ts5_status.timer_status.mouse.button_press_defined[i] = 0;
331  _ts5_status.timer_status.mouse.button_press_active[i] = 0;
332  _ts5_status.timer_status.mouse.button_release_defined[i] = 0;
333  _ts5_status.timer_status.mouse.button_release_active[i] = 0;
334  }
335 
336  _ts5_status.timer_status.mouse_is_response_device = 0;
337  }
338 
339  // keyboard
340  if (_ts5_status.timer_status.keyboard_is_response_device) {
341 
342  for (i=0; i<_ts5_status.timer_status.keyboard.num_buttons; i++) {
343 
344  _ts5_status.timer_status.keyboard.button_press_defined[i] = 0;
345  _ts5_status.timer_status.keyboard.button_press_active[i] = 0;
346  _ts5_status.timer_status.keyboard.button_release_defined[i] = 0;
347  _ts5_status.timer_status.keyboard.button_release_active[i] = 0;
348  }
349 
350  _ts5_status.timer_status.keyboard_is_response_device = 0;
351  }
352 
353  // joystick
354  if (_ts5_status.timer_status.joystick_is_response_device) {
355 
356  for (i=0; i<_ts5_status.timer_status.num_joystick; i++) {
357 
358  for (j=0; j<_ts5_status.timer_status.joystick[i].num_buttons; j++) {
359 
360  _ts5_status.timer_status.joystick[i].button_press_defined[j] = 0;
361  _ts5_status.timer_status.joystick[i].button_press_active[j] = 0;
362  _ts5_status.timer_status.joystick[i].button_release_defined[j] = 0;
363  _ts5_status.timer_status.joystick[i].button_release_active[j] = 0;
364  }
365  }
366 
367  _ts5_status.timer_status.joystick_is_response_device = 0;
368  }
369 
370  // joystick
371  if (_ts5_status.timer_status.joystick_is_response_device) {
372 
373  for (i=0; i<_ts5_status.timer_status.num_joystick; i++) {
374 
375  for (j=0; j<_ts5_status.timer_status.joystick[i].num_buttons; j++) {
376 
377  _ts5_status.timer_status.joystick[i].button_press_defined[j] = 0;
378  _ts5_status.timer_status.joystick[i].button_press_active[j] = 0;
379  _ts5_status.timer_status.joystick[i].button_release_defined[j] = 0;
380  _ts5_status.timer_status.joystick[i].button_release_active[j] = 0;
381  }
382  }
383 
384  _ts5_status.timer_status.joystick_is_response_device = 0;
385  }
386 
387  // cedrusbox
388  if (_ts5_status.timer_status.cedrusbox_is_response_device) {
389 
390  for (i=0; i<_ts5_status.timer_status.num_cedrusbox; i++) {
391 
392  for (j=0; j<_ts5_status.timer_status.cedrusbox[i].num_buttons; j++) {
393 
394  _ts5_status.timer_status.cedrusbox[i].button_press_defined[j] = 0;
395  _ts5_status.timer_status.cedrusbox[i].button_press_active[j] = 0;
396  _ts5_status.timer_status.cedrusbox[i].button_release_defined[j] = 0;
397  _ts5_status.timer_status.cedrusbox[i].button_release_active[j] = 0;
398  }
399  }
400  _ts5_status.timer_status.cedrusbox_is_response_device = 0;
401  }
402 
403  _ts5_status.timer_status.num_defined_buttons=0;
404  _ts5_status.timer_status.num_active_buttons=0;
405 }
406 
407 
412 {
413  ts5_check_timer("ts5_flush_responses");
414  ts5_log(TS5_LOGLEVEL_5, "ts5_flush_responses()\n");
415 
416  al_flush_event_queue(_ts5_status.timer_status.response_queue);
417 }
418 
419 
430 int ts5_check_response(double *resptime, double *timing_error)
431 {
432  ts5_check_timer("ts5_check_response");
433  ts5_check_timer2("ts5_check_response");
434  ts5_log(TS5_LOGLEVEL_6, "ts5_check_response(%p,%p)\n", resptime, timing_error);
435 
436  int resp=0;
437  ALLEGRO_EVENT event;
438 
439  if (!al_get_next_event(_ts5_status.timer_status.response_queue, &event)) {
440 
441  if (resptime!=NULL) {
442  *resptime = al_get_time();
443  }
444  if (timing_error!=NULL) {
445  *timing_error = 0.0;
446  }
447  }
448  else {
449 
450  if (resptime!=NULL) {
451  *resptime = event.any.timestamp;
452  }
453 
454  if (timing_error!=NULL) {
455  *timing_error = 0.0;
456  }
457 
458  int i;
459 
460  // mouse (driver response codes are counted from 1)
461  if (_ts5_status.timer_status.mouse_is_response_device) {
462 
463  if (_ts5_status.timer_status.mouse.num_active_buttons) {
464 
465  if (event.type==ALLEGRO_EVENT_MOUSE_BUTTON_DOWN) {
466 
467  resp = _ts5_status.timer_status.mouse.button_press_active[event.mouse.button-1];
468  }
469 
470  if (event.type==ALLEGRO_EVENT_MOUSE_BUTTON_UP) {
471  resp = _ts5_status.timer_status.mouse.button_release_active[event.mouse.button-1];
472  }
473  }
474  }
475 
476  // keyboard (driver response codes are counted from 1)
477  if (_ts5_status.timer_status.keyboard_is_response_device) {
478 
479  if (_ts5_status.timer_status.keyboard.num_active_buttons) {
480 
481  if (event.type==ALLEGRO_EVENT_KEY_DOWN) {
482  resp = _ts5_status.timer_status.keyboard.
483  button_press_active[event.keyboard.keycode-1];
484  }
485 
486  if (event.type==ALLEGRO_EVENT_KEY_UP) {
487  resp = _ts5_status.timer_status.keyboard.
488  button_release_active[event.keyboard.keycode-1];
489  }
490  }
491  }
492 
493  // joystick (driver response codes are counted from 0)
494  if (_ts5_status.timer_status.joystick_is_response_device) {
495 
496  for (i=0; i<_ts5_status.timer_status.num_joystick; i++) {
497 
498  if (_ts5_status.timer_status.joystick[i].num_active_buttons) {
499 
500  if (event.type==ALLEGRO_EVENT_JOYSTICK_BUTTON_DOWN) {
501 
502  ALLEGRO_JOYSTICK *stick = al_get_joystick(i);
503 
504  if (event.joystick.id == stick) {
505  resp = _ts5_status.timer_status.joystick[i].
506  button_press_active[event.joystick.button];
507  }
508  }
509 
510  if (event.type==ALLEGRO_EVENT_JOYSTICK_BUTTON_UP) {
511 
512  ALLEGRO_JOYSTICK *stick = al_get_joystick(i);
513 
514  if (event.joystick.id == stick) {
515  resp = _ts5_status.timer_status.joystick[i].
516  button_release_active[event.joystick.button];
517  }
518  }
519  }
520  }
521  }
522 
523  // cedrusbox (driver response codes are counted from 0)
524  if (_ts5_status.timer_status.cedrusbox_is_response_device) {
525 
526  for (i=0; i<_ts5_status.timer_status.num_cedrusbox; i++) {
527 
528  if (_ts5_status.timer_status.cedrusbox[i].num_active_buttons) {
529 
530  if (event.type==TS5_EVENT_CEDRUS_BUTTON_DOWN) {
531 
532  if (event.user.data1 == i) {
533  resp = _ts5_status.timer_status.cedrusbox[i].
534  button_press_active[event.user.data2];
535  }
536  }
537 
538  if (event.type==TS5_EVENT_CEDRUS_BUTTON_UP) {
539 
540  if (event.user.data1 == i) {
541  resp = _ts5_status.timer_status.cedrusbox[i].
542  button_release_active[event.user.data2];
543  }
544  }
545 
546  if (resp && timing_error!=NULL) {
547  *timing_error = ((double)event.user.data3)/1000000.0;
548  }
549  }
550  }
551  }
552 
553  // parallel port (driver response codes are counted from 1)
554  if (_ts5_status.timer_status.parport_is_response_device) {
555 
556  for (i=0; i<_ts5_status.timer_status.num_parport; i++) {
557 
558  if (_ts5_status.timer_status.parport[i].num_active_buttons) {
559 
560  if (event.type==TS5_EVENT_PARPORT_BUTTON_DOWN) {
561 
562  if (event.user.data1 == i) {
563  resp = _ts5_status.timer_status.parport[i].
564  button_press_active[event.user.data2-1];
565  }
566  }
567 
568  if (event.type==TS5_EVENT_PARPORT_BUTTON_UP) {
569 
570  if (event.user.data1 == i) {
571  resp = _ts5_status.timer_status.parport[i].
572  button_release_active[event.user.data2-1];
573  }
574  }
575 
576  if (resp && timing_error!=NULL) {
577  *timing_error = ((double)event.user.data3)/1000000.0;
578  }
579  }
580  }
581  }
582  }
583 
584  return resp;
585 }
586 
587 
596 int ts5_wait_for_response(double *resptime, double *timing_error)
597 {
598  ts5_check_timer("ts5_wait_for_response");
599  ts5_check_timer2("ts5_wait_for_response");
600  ts5_log(TS5_LOGLEVEL_5, "ts5_wait_for_response(%p,%p)\n", resptime, timing_error);
601 
602  int resp=0;
603 
604  while (!resp) {
605  resp = ts5_check_response(resptime, timing_error);
606  }
607 
608  return resp;
609 }
610 
611 
621 int ts5_wait_for_response_timed(double *resptime, double *timing_error, double maxtime)
622 {
623  ts5_check_timer("ts5_wait_for_response_timed");
624  ts5_check_timer2("ts5_wait_for_response_timed");
625  ts5_log(TS5_LOGLEVEL_5, "ts5_wait_for_response_timed(%p,%p,%f)\n", resptime, timing_error, maxtime);
626 
627  if (maxtime<0) {
628  ts5_fatal("ts5_wait_for_response_timed: maxtime is negative (%f)\n", maxtime);
629  }
630 
631  int resp=0, deadline=0;
632  double starttime = al_get_time();
633 
634  while (!resp && !deadline) {
635 
636  resp = ts5_check_response(resptime, timing_error);
637 
638  if (al_get_time()-starttime>=maxtime) {
639  deadline=1;
640  }
641  }
642 
643  return resp;
644 }
645 
646 
656 int ts5_wait_for_response_until(double *resptime, double *timing_error, double deadline)
657 {
658  ts5_check_timer("ts5_wait_for_response_until");
659  ts5_check_timer2("ts5_wait_for_response_until");
660  ts5_log(TS5_LOGLEVEL_5, "ts5_wait_for_response_until(%p,%p,%f)\n", resptime, timing_error, deadline);
661 
662  if (deadline<al_get_time()) {
663  ts5_fatal("ts5_wait_for_response_until: response deadline is in the past (%f)\n",
664  deadline-al_get_time());
665  }
666 
667  int resp=0, maxtime=0;
668 
669  while (!resp && !maxtime) {
670 
671  resp = ts5_check_response(resptime, timing_error);
672 
673  if (al_get_time()>=deadline) {
674  maxtime=1;
675  }
676  }
677 
678  return resp;
679 }
680 
681 
683 
684 
685 
686 
710 
711 
712 
713 
718 {
719  ts5_check_timer("ts5_flush_triggers");
720  ts5_log(TS5_LOGLEVEL_5, "ts5_flush_triggers()\n");
721 
722  al_flush_event_queue(_ts5_status.timer_status.trigger_queue);
723 }
724 
725 
736 int ts5_check_trigger(double *trigtime, double *timing_error)
737 {
738  ts5_check_timer("ts5_check_trigger");
739  ts5_check_timer3("ts5_check_trigger");
740  ts5_log(TS5_LOGLEVEL_6, "ts5_check_trigger(%p,%p)\n", trigtime, timing_error);
741 
742  int trigger=0;
743  ALLEGRO_EVENT event;
744 
745  if (trigtime!=NULL) {
746  *trigtime = al_get_time();
747  }
748  if (timing_error!=NULL) {
749  *timing_error = 0.0;
750  }
751 
752  if (al_get_next_event(_ts5_status.timer_status.trigger_queue, &event)) {
753 
754  if(_ts5_status.timer_status.parport_is_trigger_device) {
755 
756  int i;
757  for (i=0; i<_ts5_status.timer_status.num_parport; i++) {
758 
759  if (_ts5_status.timer_status.parport[i].is_trigger_input_device) {
760 
761  if (event.type==TS5_EVENT_PARPORT_TRIGGER && event.user.data1 == i) {
762 
763  if (trigtime!=NULL) {
764  *trigtime = event.any.timestamp;
765  }
766 
767  if (timing_error!=NULL) {
768  *timing_error = ((double)event.user.data3)/1000000.0;
769  }
770 
771  trigger = event.user.data2;
772  }
773  }
774  }
775  }
776 
777  if(_ts5_status.timer_status.serialport_is_trigger_device) {
778 
779  int i;
780  for (i=0; i<_ts5_status.timer_status.num_serialport; i++) {
781 
782  if (_ts5_status.timer_status.serialport[i].is_trigger_input_device) {
783 
784  if (event.type==TS5_EVENT_SERIALPORT_TRIGGER && event.user.data1 == i) {
785 
786  if (trigtime!=NULL) {
787  *trigtime = event.any.timestamp;
788  }
789 
790  if (timing_error!=NULL) {
791  *timing_error = ((double)event.user.data3)/1000000.0;
792  }
793 
794  trigger = event.user.data2;
795  }
796  }
797  }
798  }
799  }
800 
801  return trigger;
802 }
803 
804 
813 int ts5_wait_for_trigger(double *trigtime, double *timing_error)
814 {
815  ts5_check_timer("ts5_wait_for_trigger");
816  ts5_check_timer2("ts5_wait_for_trigger");
817  ts5_log(TS5_LOGLEVEL_5, "ts5_wait_for_trigger(%p,%p)\n", trigtime, timing_error);
818 
819  int trigger=0;
820 
821  while (!trigger) {
822  trigger = ts5_check_trigger(trigtime, timing_error);
823  }
824 
825  return trigger;
826 }
827 
828 
838 int ts5_wait_for_trigger_timed(double *trigtime, double *timing_error, double maxtime)
839 {
840  ts5_check_timer("ts5_wait_for_trigger_timed");
841  ts5_check_timer2("ts5_wait_for_trigger_timed");
842  ts5_log(TS5_LOGLEVEL_5, "ts5_wait_for_trigger_timed(%p,%p,%f)\n", trigtime, timing_error, maxtime);
843 
844  if (maxtime<0) {
845  ts5_fatal("ts5_wait_for_trigger_timed: maxtime is negative (%f)\n", maxtime);
846  }
847 
848  int trigger=0, deadline=0;
849  double starttime = al_get_time();
850 
851  while (!trigger && !deadline) {
852 
853  trigger = ts5_check_trigger(trigtime, timing_error);
854 
855  if (al_get_time()-starttime>=maxtime) {
856  deadline=1;
857  }
858  }
859 
860  return trigger;
861 }
862 
863 
874 int ts5_wait_for_trigger_until(double *trigtime, double *timing_error, double deadline)
875 {
876  ts5_check_timer("ts5_wait_for_trigger_until");
877  ts5_check_timer2("ts5_wait_for_trigger_until");
878  ts5_log(TS5_LOGLEVEL_5, "ts5_wait_for_trigger_until(%p,%p,%f)\n", trigtime, timing_error, deadline);
879 
880  if (deadline<al_get_time()) {
881  ts5_fatal("ts5_wait_for_trigger_until: trigger deadline is in the past (%f)\n",
882  deadline-al_get_time());
883  }
884 
885  int trigger=0, maxtime=0;
886 
887  while (!trigger && !maxtime) {
888 
889  trigger = ts5_check_trigger(trigtime, timing_error);
890 
891  if (al_get_time()>=deadline) {
892  maxtime=1;
893  }
894  }
895 
896  return trigger;
897 }
898 
899 
905 void ts5_write_all_triggers(char *filename)
906 {
907  ts5_check_timer("ts5_write_all_triggers");
908  ts5_check_timer3("ts5_write_all_triggers");
909  ts5_log(TS5_LOGLEVEL_5, "ts5_write_all_triggers(%s)\n", filename);
910 
911  FILE *fp;
912  fp = fopen(filename, "a+");
913  if (!fp) {
914  ts5_fatal("ts5_write_all_triggers: could not open output file %s\n", filename);
915  }
916 
917  ALLEGRO_EVENT event;
918 
919  while (al_get_next_event(_ts5_status.timer_status.trigger_log, &event)) {
920 
921  fprintf(fp, "%10.8f ", event.any.timestamp);
922 
923  double timing_error = ((double)event.user.data3)/1000000.0;
924  fprintf(fp, "%10.8f ", timing_error);
925 
926  if (event.type==TS5_EVENT_PARPORT_TRIGGER) {
927  fprintf(fp, "PARPORT ");
928  }
929  else if (event.type==TS5_EVENT_SERIALPORT_TRIGGER) {
930  fprintf(fp, "SERIALPORT ");
931  }
932  else {
933  fprintf(fp, "UNKNOWN ");
934  }
935 
936  fprintf(fp, "%d ", (int)event.user.data1+1);
937  fprintf(fp, "%d ", (int)event.user.data2);
938  fprintf(fp, "\n");
939  }
940 
941  fclose(fp);
942 }
943 
944 
946 
947 
948 
949 
950 
951