/*
          __
         / /_______________  ____  ___
        / __/ ___/ ___/ __ \/ __ \/ _ \
       / /_(__  ) /__/ /_/ / /_/ /  __/
       \__/____/\___/\____/ .___/\___/
                         /_/

    timer3.c
    double keypress response
*/

#include <tscope.h>

#define FIXTM   mtt(500)
#define BLANKTM mtt(500)
#define MAXTM   mtt(1500)
#define ITI     mtt(1500)

struct {
    int t1, e1;
    int t2, e2;
    int r1, r2;                 // 2 responses
} data[2];

struct {
    __int64 junk;
    __int64 t1, e1;
    __int64 t2, e2;
    __int64 t3, e3;
} tmp;

void trial(int i)
{
    // fixation
    ts_vsync(&tmp.junk, &tmp.junk);
    ts_printf_centre(0, 0, "+");
    ts_wait(FIXTM);

    // blank screen
    ts_vsync(&tmp.junk, &tmp.junk);
    ts_clrscr();
    ts_wait(BLANKTM);

    // stimulus = timing mark 1
    ts_vsync(&tmp.t1, &tmp.e1);
    ts_printf_centre(0, 0, "stimulus");

    // wait for the first response ( = timing mark 2)
    data[i].r1 = ts_resp(&tmp.t2, &tmp.e2, MAXTM);

    // if there is a response, wait for the second one
    if (data[i].r1) {
        // hide the response button that is being pressed
        ts_hidekey(data[i].r1);

        // adjust maximum rection time 
        tmp.junk = MAXTM - (tmp.t2 - tmp.t1);

        // wait for the second response ( = timing mark 3)
        data[i].r2 = ts_resp(&tmp.t3, &tmp.e3, tmp.junk);

        // unhide response button 
        ts_hidekey(0);
    }
    // if there was no reponse, reset values timing mark 3
    else {
        tmp.t3 = tmp.t2;
        tmp.e2 = 0;
    }

    // compute rt and error
    data[i].t1 = ttm(tmp.t2 - tmp.t1);
    data[i].t2 = ttm(tmp.t3 - tmp.t1);
    data[i].e1 = ttmu(tmp.e1 + tmp.e2);
    data[i].e2 = ttmu(tmp.e1 + tmp.e3);

    // clear screen and wait for the next trial
    ts_clrscr();
    ts_wait(ITI);
}

int main()
{
    // set response values
    ts_defkey(KEY_F1);
    ts_defkey(KEY_F2);
    ts_defkey(KEY_F3);
    ts_defkey(KEY_F4);

    // prepare the subject
    ts_printf_centre(0, 40, "press two of the following buttons:");
    ts_printf_centre(0, 20, "F1 F2 F3 F4");
    ts_printf_centre(0, 0, "within 1500ms after the appearance");
    ts_printf_centre(0, -20, "of the stimulus.");
    ts_printf_centre(0, -40, "there are two trials");
    ts_button(XMAX - 20, -YMAX + 20);
    ts_clrscr();


    // execute trial
    trial(0);
    trial(1);

    // print some results
    ts_printf_centre(0, 80, "            r  rt    re");
    ts_printf_centre(0, 40, "trial 1 A : %d %4d %4d", data[0].r1,
                     data[0].t1, data[0].e1);
    ts_printf_centre(0, 20, "trial 1 B : %d %4d %4d", data[0].r2,
                     data[0].t2, data[0].e2);
    ts_printf_centre(0, -20, "trial 2 A : %d %4d %4d", data[1].r1,
                     data[1].t1, data[1].e1);
    ts_printf_centre(0, -40, "trial 2 B : %d %4d %4d", data[1].r2,
                     data[1].t2, data[1].e2);

    ts_button(XMAX - 20, -YMAX + 20);
    return 0;
}

END_OF_MAIN();


top
Persoonlijke pagina Universiteit GentTscope
Allegro | Cygwin | Gcc
© See license.html for copyright information