-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwait_for_scanner.m
63 lines (55 loc) · 2.1 KB
/
wait_for_scanner.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
function [ onset_first_trigger] = wait_for_scanner( nScans, bitsiScanner, trigger, fid, mainstart,block, PTB)
%wait_for_scanner Wait for specified number of Scanner-trigger events
%
% Input:
% nScans number of scan-trigger events to wait for
% bitsiScanner bitsibox object, which to listen to for triggers
% trigger ASCI code of trigger (aka scanner-trigger) to wait for
% PTB boolean, indicating whether to show count-down on
% screen. This assumes PsychToolBox is already running, and
% only drawing/flipping is necessary.
%
% Output:
% onset_first_trigger onset time of first trigger-event
%
% adapted by: Peter Vavra
% version: 2014/05/19
%
% remove all previous codes from Bitsibox
bitsiScanner.clearResponses();
nEvents = 0;
txt = 'Waiting for Scanner';
% get PTB-window pointer
if PTB
windowpointers=Screen('Windows');
window = windowpointers(1);
[screenXpixels, screenYpixels] = Screen('WindowSize', window);
textRect = Screen('TextBounds', window , txt);
Screen('DrawText',window, txt, (screenXpixels/2)-(textRect(3)/2), (screenYpixels/2), 0);
Screen('DrawText',window, int2str(nScans-nEvents), 500,680, 255);
Screen(window,'Flip');
end
% wait for trigger-events
while nEvents < nScans;
[response, timestamp] = bitsiScanner.getResponse(1, true);
if response == trigger;
nEvents = nEvents + 1;
if nEvents == 1
onset_first_trigger=timestamp;
end
% clear response from buffer
bitsiScanner.clearResponses();
% show countdown on screen
if PTB
Screen('DrawText',window, txt, (screenXpixels/2)-(textRect(3)/2), (screenYpixels/2), 0);
if nScans-nEvents > 0 % don't show zero
Screen('DrawText',window, int2str(nScans-nEvents), 500,680, 0);
end
Screen(window,'Flip');
end
fprintf(fid, '%f\t%i\t%f\t%i\n', toc(mainstart), nEvents, timestamp, block);
% log status to console
fprintf('trigger nr: %i -- timestamp: %f\n',nEvents, timestamp);
end
end
end