Tscope5
timer.c File Reference

Go to the source code of this file.

Functions

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 ()
void ts5_wait (double waittime)
void ts5_wait_until (double deadline)
Response registration

The response registration functions require you to define response keys first using ts5_define_mouse_key(), ts5_define_keyboard_key(), ts5_define_joystick_key(), ts5_define_cedrusbox_key() or ts5_define_parport_key().

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

Registration of responses is done asynchronously. All key 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 befor 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_key() or ts5_remove_response_keys().

int ts5_hide_response_key (int key)
void ts5_remove_response_keys ()
void ts5_flush_responses ()
int ts5_check_response (double *resptime, double *timing_error)
int ts5_wait_for_response (double *resptime, double *timing_error)
int ts5_wait_for_response_timed (double *resptime, double *timing_error, double maxtime)
int ts5_wait_for_response_until (double *resptime, double *timing_error, double deadline)
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 ()
int ts5_check_trigger (double *trigtime, double *timing_error)
int ts5_wait_for_trigger (double *trigtime, double *timing_error)
int ts5_wait_for_trigger_timed (double *trigtime, double *timing_error, double maxtime)
int ts5_wait_for_trigger_until (double *trigtime, double *timing_error, double deadline)
void ts5_write_all_triggers (char *filename)

Detailed Description

Definition in file timer.c.


Function Documentation

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:
timer1.c.

Definition at line 33 of file timer.c.

void ts5_wait ( double  waittime)

Wait for a number of seconds.

Examples:
audio1.c, bitmaps5.c, display1.c, display2.c, display3.c, display4.c, display5.c, graphics10.c, timer1.c, timer2.c, timer3.c, timer4.c, timer5.c, and timer6.c.

Definition at line 45 of file timer.c.

void ts5_wait_until ( double  deadline)

Wait until a deadline.

Examples:
timer1.c, and timer2.c.

Definition at line 66 of file timer.c.

int ts5_hide_response_key ( int  key)

Temporarily deactivates a response key.

Parameters:
keyThe key that has to be deactivated.
Returns:
The number of active keys left.

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

Reactivating all defined keys is possible by calling ts5_hide_response_key(0).

Examples:
timer4.c, and timer6.c.

Definition at line 123 of file timer.c.

void ts5_remove_response_keys ( )

Completely removes the response key definition.

Definition at line 318 of file timer.c.

void ts5_flush_responses ( )

Flush the response queue.

Examples:
timer3.c, timer4.c, timer5.c, and timer6.c.

Definition at line 411 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).
Returns:
The key that was pressed (0 if no key was pressed within the deadline).

This function checks for a response and returns immediately.

Definition at line 430 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).
Returns:
The key that was pressed.

Definition at line 596 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).
maxtimeMaximum time for a response.
Returns:
The key that was pressed (0 if no key was pressed within the maximum time).
Examples:
timer3.c, and timer6.c.

Definition at line 621 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).
deadlineDeadline for a response.
Returns:
The key that was pressed (0 if no key was pressed within the deadline).
Examples:
timer4.c, and timer5.c.

Definition at line 656 of file timer.c.

void ts5_flush_triggers ( )

Flush the trigger queue.

Definition at line 717 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 736 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).
Returns:
The key that was pressed.

Definition at line 813 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).
maxtimeMaximum time for a trigger.
Returns:
The key that was pressed (0 if no key was pressed within the maximum time).

Definition at line 838 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).
deadlineDeadline for a trigger.
Returns:
The key that was pressed (0 if no key was pressed within the deadline).

Definition at line 874 of file timer.c.

void ts5_write_all_triggers ( char *  filename)

Write all triggers to an output file.

Parameters:
filenamePath to the output file

Definition at line 905 of file timer.c.