Tscope5
timer.c File Reference

Definitions of timer functions. More...

Go to the source code of this file.

Functions

Program priority functions

You can increase your program's priority to get better timing accuracy.

int ts5_set_priority (int priority)
 Set the program's priority. More...
 
int ts5_get_priority ()
 Get the program's priority. More...
 
General timing functions

The general timing functions are mainly used to control stimulus timing.

You can either wait for a given amount of time, or until some time in the future.

double ts5_get_time ()
 Get the number of seconds since the program started. More...
 
void ts5_wait (double waittime)
 Wait for a number of seconds. More...
 
void ts5_wait_until (double deadline)
 Wait until a deadline. More...
 
Response registration

The response registration functions require you to define response buttons first using ts5_define_mouse_button(), ts5_define_keyboard_button(), ts5_define_joystick_button(), ts5_define_cedrusbox_button() or ts5_define_parport_button().

Each response button will get a response value. The first button that is defined will get number 1, etc.

Registration of responses is done asynchronously. All button presses that are defined will be buffered continuously during the program.

Waiting for a response to a stimulus will typically involve flushing all buffered responses that occurred before stimulus onset using ts5_flush_responses() and then checking for new responses using ts5_check_response(), ts5_wait_for_response(), ts5_wait_for_response_timed() or ts5_wait_for_response_until().

The response definition can be altered during the program using ts5_hide_response_button() or ts5_remove_response_buttons().

int ts5_hide_response_button (int button)
 Temporarily deactivates a response button. More...
 
void ts5_remove_response_buttons ()
 Completely removes the response button definition. More...
 
void ts5_flush_responses ()
 Flush the response queue. More...
 
int ts5_check_response (double *resptime, double *timing_error)
 Check for a reponse. More...
 
int ts5_wait_for_response (double *resptime, double *timing_error)
 Wait for a response. More...
 
int ts5_wait_for_response_timed (double *resptime, double *timing_error, double maxtime)
 Wait for a response for a given time. More...
 
int ts5_wait_for_response_until (double *resptime, double *timing_error, double deadline)
 Wait for a response until a deadline. More...
 
Trigger input/output

The trigger input functions require you to define trigger devices using ts5_define_parport_trigger_input() or ts5_define_serialport_trigger_input().

Registration of trigger input is done asynchronously. All triggers received on the parallel and/or serial port(s) will be buffered continuously during the program.

Waiting for a trigger is similar to waiting for a reponse. Old triggers that were not processed yet can be flushed using ts5_flush_triggers(). One can either wait for a trigger indefinitely, for a given amount of time or until some deadline has passed.

The value of the trigger is defined by the computer that sends the trigger.

During the development of the program it is not necessary to connect a computer that sends the triggers. Trigger input can be simulated using ts5_simulate_parport_trigger_input() or ts5_simulate_serialport_trigger_input().

At the end of the program all triggers can be written to a logfile using ts5_write_all_triggers().

Trigger output is simple, call ts5_send_parport_trigger() or ts5_send_serialport_trigger() each time you want to send a trigger.

void ts5_flush_triggers ()
 Flush the trigger queue. More...
 
int ts5_check_trigger (double *trigtime, double *timing_error)
 Check for a trigger. More...
 
int ts5_wait_for_trigger (double *trigtime, double *timing_error)
 Wait for a trigger. More...
 
int ts5_wait_for_trigger_timed (double *trigtime, double *timing_error, double maxtime)
 Wait for a trigger for a given time. More...
 
int ts5_wait_for_trigger_until (double *trigtime, double *timing_error, double deadline)
 Wait for a trigger until a deadline. More...
 
void ts5_write_all_triggers (char *filename)
 Write all triggers to an output file. More...
 

Detailed Description

Definitions of timer functions.

Definition in file timer.c.

Function Documentation

int ts5_set_priority ( int  priority)

Set the program's priority.

Parameters
priorityPriority.
Returns
The previous priority.

There are five possible settings:

  • TS5_HIGH_PRIORITY
  • TS5_ABOVE_NORMAL_PRIORITY
  • TS5_NORMAL_PRIORITY
  • TS5_BELOW_NORMAL_PRIORITY
  • TS5_LOW_PRIORITY.

The default priority is TS5_NORMAL_PRIORITY.

Examples:
timer02.c.

Definition at line 62 of file timer.c.

int ts5_get_priority ( )

Get the program's priority.

Returns
The program's priority.

Definition at line 178 of file timer.c.

double ts5_get_time ( )

Get the number of seconds since the program started.

Returns
The number of seconds since the program started (as a double precision float).
Examples:
audio04.c, parport03.c, serialport03.c, timer01.c, and video01.c.

Definition at line 208 of file timer.c.

void ts5_wait ( double  waittime)
void ts5_wait_until ( double  deadline)

Wait until a deadline.

Examples:
parport03.c, serialport03.c, timer01.c, and timer02.c.

Definition at line 243 of file timer.c.

int ts5_hide_response_button ( int  button)

Temporarily deactivates a response button.

Parameters
buttonThe button that has to be deactivated.
Returns
The number of active buttons left.

This function also checks whether there are any active response left. Aborts if necessary.

Reactivating all defined buttons is possible by calling ts5_hide_response_button(0).

Examples:
timer04.c, and timer06.c.

Definition at line 307 of file timer.c.

void ts5_remove_response_buttons ( )

Completely removes the response button definition.

Definition at line 628 of file timer.c.

void ts5_flush_responses ( )

Flush the response queue.

Examples:
audio03.c, audio04.c, cedrusbox01.c, joystick01.c, keyboard01.c, mouse01.c, parport01.c, serialport01.c, timer03.c, timer04.c, timer05.c, and timer06.c.

Definition at line 737 of file timer.c.

int ts5_check_response ( double *  resptime,
double *  timing_error 
)

Check for a reponse.

Parameters
resptimeVariable that will store the response time.
timing_errorVariable that will store the timing error (works only for cedrusboxes and parallel port boxes).
Returns
The button that was pressed (0 if no button was pressed within the deadline).

This function checks for a response and returns immediately.

Examples:
audio03.c, audio04.c, and mouse02.c.

Definition at line 758 of file timer.c.

int ts5_wait_for_response ( double *  resptime,
double *  timing_error 
)

Wait for a response.

Parameters
resptimeVariable that will store the response time.
timing_errorVariable that will store the timing error (works only for cedrusboxes and parallel port boxes).
Returns
The button that was pressed.

Definition at line 983 of file timer.c.

int ts5_wait_for_response_timed ( double *  resptime,
double *  timing_error,
double  maxtime 
)

Wait for a response for a given time.

Parameters
resptimeVariable that will store the response time.
timing_errorVariable that will store the timing error (works only for cedrusboxes and parallel port boxes).
maxtimeMaximum time for a response.
Returns
The button that was pressed (0 if no button was pressed within the maximum time).
Examples:
cedrusbox01.c, joystick01.c, keyboard01.c, mouse01.c, parport01.c, serialport01.c, timer03.c, and timer06.c.

Definition at line 1011 of file timer.c.

int ts5_wait_for_response_until ( double *  resptime,
double *  timing_error,
double  deadline 
)

Wait for a response until a deadline.

Parameters
resptimeVariable that will store the response time.
timing_errorVariable that will store the timing error (works only for cedrusboxes and parallel port boxes).
deadlineDeadline for a response.
Returns
The button that was pressed (0 if no button was pressed within the deadline).
Examples:
timer04.c, and timer05.c.

Definition at line 1051 of file timer.c.

void ts5_flush_triggers ( )

Flush the trigger queue.

Definition at line 1121 of file timer.c.

int ts5_check_trigger ( double *  trigtime,
double *  timing_error 
)

Check for a trigger.

Parameters
trigtimeVariable that will store the trigger time.
timing_errorVariable that will store the timing error.
Returns
The value of the trigger

This function checks for a trigger and returns immediately.

Definition at line 1140 of file timer.c.

int ts5_wait_for_trigger ( double *  trigtime,
double *  timing_error 
)

Wait for a trigger.

Parameters
trigtimeVariable that will store the trigger time.
timing_errorVariable that will store the timing error (works only for cedrusboxes and parallel port boxes).
Returns
The button that was pressed.
Examples:
cedrusbox02.c, parport02.c, and serialport02.c.

Definition at line 1250 of file timer.c.

int ts5_wait_for_trigger_timed ( double *  trigtime,
double *  timing_error,
double  maxtime 
)

Wait for a trigger for a given time.

Parameters
trigtimeVariable that will store the trigger time.
timing_errorVariable that will store the timing error (works only for cedrusboxes and parallel port boxes).
maxtimeMaximum time for a trigger.
Returns
The button that was pressed (0 if no button was pressed within the maximum time).

Definition at line 1278 of file timer.c.

int ts5_wait_for_trigger_until ( double *  trigtime,
double *  timing_error,
double  deadline 
)

Wait for a trigger until a deadline.

Parameters
trigtimeVariable that will store the trigger time.
timing_errorVariable that will store the timing error (works only for cedrusboxes and parallel port boxes).
deadlineDeadline for a trigger.
Returns
The button that was pressed (0 if no button was pressed within the deadline).

Definition at line 1319 of file timer.c.

void ts5_write_all_triggers ( char *  filename)

Write all triggers to an output file.

Parameters
filenamePath to the output file
Examples:
cedrusbox02.c, parport02.c, and serialport02.c.

Definition at line 1353 of file timer.c.