File: iViewXSimulator.m

package info (click to toggle)
psychtoolbox-3 3.0.19.14.dfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 86,796 kB
  • sloc: ansic: 176,245; cpp: 20,103; objc: 5,393; sh: 2,753; python: 1,397; php: 384; makefile: 193; java: 113
file content (136 lines) | stat: -rw-r--r-- 4,427 bytes parent folder | download | duplicates (5)
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
% iviewxsimulator
% simulates iviewx host behaviour


fprintf([mfilename ' start\n']);
clear;
try
    streaming=0;
    %     [result, ivx]=iViewX('clear', ivx);

    pnet('closeall');

    host='localhost';
    port=4444;
    ivx=iViewXInitDefaults([],[], host, port);
    ivx.localport=6666;
    %     ivx.stopSimulatorKey=KbName('ESC');
    ivx;
    [result, ivx]=iViewX('openconnection', ivx);

    while KbCheck; end

    % start a loop, waiting for commands from client
    tEnd=GetSecs+300;
    i=0;
    while GetSecs<tEnd

        [keyIsDown,secs,keyCode] = KbCheck;
        if 0 && 1==keyCode(ivx.modifierKey) && 1==keyCode(ivx.breakKey)
            break;
        end

        if streaming==1

            message=['ET_SPL ' num2str(round(GetSecs*100000)) ' ' num2str(round(rand*ivx.screenHSize)) ' ' num2str(round(rand*ivx.screenVSize)) ];
            [result, ivx]=iViewX('command', ivx, message);
        end

        [data, ivx]=iViewX('receivedata', ivx);

        if ~isempty(data) && data ~=-1
            % data
            if strfind(data, 'ET_STR')
                fprintf('Start Streaming\n');
                streaming=1;
            elseif strfind(data, 'ET_ACC')
                fprintf('Accept point\n');
            elseif strfind(data, 'ET_EST')
                fprintf('End Streaming\n');
                streaming=0;
            elseif strfind(data, 'ET_REC')
                fprintf('Start Recording\n');
            elseif strfind(data, 'ET_STP')
                fprintf('Stop Recording\n');
            elseif strfind(data, 'ET_PNT')
                coords=str2num(data(8:end));
                fprintf('Coords for point %d:\t%d\t%d\n', coords(1), coords(2), coords(3));
                
                ivx.absCalPos(coords(1),1)=coords(2);
                ivx.absCalPos(coords(1),2)=coords(3);
                
            elseif strfind(data, 'ET_CAL')
                ct=str2num(data(8:end));
                fprintf('Calibration type: %d\n', ct);
                ivx.nCalPoints=ct;

                % send screen info
                WaitSecs(0.01);

                message=['ET_CSZ ' num2str(ivx.screenHSize) ' ' num2str(ivx.screenVSize) ];
                [result, ivx]=iViewX('command', ivx, message);
                fprintf('Sending screen info \n');
                % now start sending calibration point info

                for i=1:ivx.nCalPoints
                    message=['ET_PNT ' num2str(i) ' ' num2str(ivx.absCalPos(i,1)) ' ' num2str(ivx.absCalPos(i,2))];
                    message;
                    [result, ivx]=iViewX('command', ivx, message);
                    fprintf('Sending point info %d\n', i);

                    WaitSecs(0.01);
                end

                for i=[1:ivx.nCalPoints 1]
                    message=['ET_CHG ' num2str(i)];

                    [result, ivx]=iViewX('command', ivx, message);
                    fprintf('Sending point change info %d\n', i);

                    WaitSecs(1+rand*1);
                end
                message=['ET_FIN ' num2str(i)];
                [result, ivx]=iViewX('command', ivx, message);

            elseif strfind(data, 'ET_CHG')
                pt=str2num(data(8:end));
                fprintf('Change to point: %d\n', pt);
            elseif strfind(data, 'ET_PT')
                coords=str2num(data(8:end));
                fprintf('Coords for point %d:\t%d\t%d\n', coords(1), coords(2), coords(3));
            elseif strfind(data, 'ET_CSZ')
                scr_size=str2num(data(8:end));
                ivx.screenHSize=scr_size(1);
                ivx.screenVSize=scr_size(2);


                fprintf('Screen: %d\t%d\n', scr_size(1), scr_size(2));
            else
                fprintf('Unknown command.\n');

            end
            data=[];
        end
    end
    %     params='ET_REC';
    %     [result, ivx]=iViewX('command', ivx, params);
    %     params='ET_CAL 9';
    %     [result, ivx]=iViewX('command', ivx, params);
    %
    [result, ivx]=iViewX('closeconnection', ivx);

    %     result

    %     [result, ivx]=iViewX('stoprecording', ivx);

    %     result
    pnet('closeall');
    fprintf([mfilename ' end\n']);

catch
    %this "catch" section executes in case of an error in the "try" section
    %above.  Importantly, it closes the onscreen window if its open.
    pnet('closeall');
    Screen('CloseAll');    rethrow(lasterror);
end %try..catch..