Tscope5
joystick01.c
////////////////////////////////////////////////////////////////////////////////
//
// __ ______
// / /_______________ ____ ___ / ____/
// / __/ ___/ ___/ __ \/ __ \/ _ \ /___ )
// / /_(__ ) /__/ /_/ / /_/ / __/ ____/ /
// \__/____/\___/\____/ .___/\___/ /_____/
// /_/
//
// joystick01.c
// - Basic response timing example.
// - Use the joystick for response registration.
////////////////////////////////////////////////////////////////////////////////
#include <tscope5.h>
int main()
{
// open a display
ts5_set_coordinate_scale(TS5_RELATIVE_COORDINATES);
ts5_set_coordinate_system(TS5_DISPLAY_COORDINATES);
ts5_set_text_alignment(TS5_ALIGN_LEFT);
// define all buttons on all joysticks as responses
int i, njoystick = ts5_get_num_joysticks();
if (njoystick==0) {
ts5_fatal("joystick01.c: no joysticks attached to the system\n");
}
for(i=0; i<njoystick; i++) {
// devices are counted from 1
int j, nbuttons = ts5_get_num_joystick_buttons(i+1);
for (j=0; j<nbuttons; j++) {
// buttons are counted from one
}
}
// timing variables
double start, stop, rt, error;
int resp;
// instruction
ts5_printf(0.1, 0.1, "press a joystick button");
ts5_printf(0.1, 0.2, "within 5 seconds");
start = ts5_flip_display();
// flush the response buffer
// wait for a response
resp = ts5_wait_for_response_timed(&stop, &error, 5.0);
rt = stop-start;
// print response time and measurement error
// measurement error is only known
// for parallel port response boxes
// and cedrusboxes
ts5_printf(0.1, 0.3, "response %d", resp);
ts5_printf(0.1, 0.4, "start time %f", start);
ts5_printf(0.1, 0.5, "stop time %f", stop);
ts5_printf(0.1, 0.6, "response time %f", rt);
ts5_printf(0.1, 0.7, "measurement error %f", error);
// wait for a click
return 0;
}