pb_runLSL.m 2.57 KB
Newer Older
Jesse Heckman's avatar
updates    
Jesse Heckman committed
1
function [ses,str] = pb_runLSL(varargin)
Jesse Heckman's avatar
add LSL  
Jesse Heckman committed
2
3
% PB_RUNLSL()
%
Jesse Heckman's avatar
add LSL    
Jesse Heckman committed
4
% PB_RUNLSL() creates a LSL session for VC.
Jesse Heckman's avatar
add LSL  
Jesse Heckman committed
5
%
Jesse Heckman's avatar
add LSL    
Jesse Heckman committed
6
% See also PB_VRUNEXP
Jesse Heckman's avatar
add LSL  
Jesse Heckman committed
7
8
9

% PBToolbox (2018): JJH: j.heckman@donders.ru.nl

Jesse Heckman's avatar
updates    
Jesse Heckman committed
10
11
   de = pb_keyval('de', varargin, true);
   pl = pb_keyval('pl', varargin, true);
Jesse Heckman's avatar
Jesse Heckman committed
12
   gz = pb_keyval('gz', varargin, true);
Jesse Heckman's avatar
updates    
Jesse Heckman committed
13
14
15
16
   ot = pb_keyval('ot', varargin, true);
   
   tmp = {};
   
Jesse Heckman's avatar
Jesse Heckman committed
17
   streams  = {'type=''Digital Events @ lslder01'' and name=''Digital Events 0''', ...
Jesse Heckman's avatar
Jesse Heckman committed
18
               'type=''Pupil Capture @ pupil-desktop'' and name=''Pupil Python Representation - Eye 0''', ...
Jesse Heckman's avatar
Jesse Heckman committed
19
               'type=''Pupil Capture @ pupil-desktop'' and name=''Gaze Python Representation''', ...
Jesse Heckman's avatar
add LSL    
Jesse Heckman committed
20
               'type=''OptiTrack Mocap @ DCN-VSO3'' and name=''Labeled Markers'''};
Jesse Heckman's avatar
updates    
Jesse Heckman committed
21
   
Jesse Heckman's avatar
Jesse Heckman committed
22
23
   if de; tmp(end+1) = streams(1); end
   if pl; tmp(end+1) = streams(2); end 
Jesse Heckman's avatar
Jesse Heckman committed
24
25
   if gz; tmp(end+1) = streams(3); end
   if ot; tmp(end+1) = streams(4); end
Jesse Heckman's avatar
updates    
Jesse Heckman committed
26
27
   
   streams = tmp;
Jesse Heckman's avatar
add LSL  
Jesse Heckman committed
28
29
         
   ses      = lsl_session();
Jesse Heckman's avatar
Jesse Heckman committed
30
31
   ls       = length(streams);
   str      = lsl_istream.empty(0,ls);
Jesse Heckman's avatar
updates    
Jesse Heckman committed
32
33
   
   clear tmp;
Jesse Heckman's avatar
Jesse Heckman committed
34
   for iStrm = 1:ls
Jesse Heckman's avatar
add LSL  
Jesse Heckman committed
35
      % Find, select and make streams for LSL.
Jesse Heckman's avatar
add LSL    
Jesse Heckman committed
36
37
      tmp = strrep(streams(iStrm),'type=''','');
      tmp = tmp{1}(1:find(tmp{1} == '@',1)-2);
Jesse Heckman's avatar
Jesse Heckman committed
38
      %disp([newline 'Looking for ' tmp ' stream...'])
Jesse Heckman's avatar
add LSL  
Jesse Heckman committed
39
      
Jesse Heckman's avatar
Jesse Heckman committed
40
      info  = lsl_resolver(streams{iStrm});
Jesse Heckman's avatar
add LSL    
Jesse Heckman committed
41
      l     = info.list();
Jesse Heckman's avatar
add LSL  
Jesse Heckman committed
42
43
      if isempty(l); error('No streams found'); end

Jesse Heckman's avatar
Jesse Heckman committed
44
      for iList = 1:size(l,1)
Jesse Heckman's avatar
Jesse Heckman committed
45
        %fprintf('%d: name: ''%s'' type: ''%s''\n',iList,l(iList).name,l(iList).type);
Jesse Heckman's avatar
add LSL  
Jesse Heckman committed
46
47
      end

Jesse Heckman's avatar
add LSL    
Jesse Heckman committed
48
      str(iStrm) = lsl_istream(info{1});
Jesse Heckman's avatar
Jesse Heckman committed
49
      ses.add_stream(str(iStrm));
Jesse Heckman's avatar
add LSL  
Jesse Heckman committed
50
51
   end
   
Jesse Heckman's avatar
updates    
Jesse Heckman committed
52
53
54
   c = 1;
   if de; addlistener(str(c),'DataAvailable', @ev_listener); c = c+1; end
   if pl; addlistener(str(c),'DataAvailable', @pl_listener); c = c+1; end
Jesse Heckman's avatar
Jesse Heckman committed
55
   if gz; addlistener(str(c),'DataAvailable', @gz_listener); c = c+1; end
Jesse Heckman's avatar
updates    
Jesse Heckman committed
56
   if ot; addlistener(str(c),'DataAvailable', @ot_listener); end
Jesse Heckman's avatar
add LSL  
Jesse Heckman committed
57
58
end

Jesse Heckman's avatar
Jesse Heckman committed
59
function ev_listener(~, event)
Jesse Heckman's avatar
add LSL    
Jesse Heckman committed
60
   disp('ev_listener called')
Jesse Heckman's avatar
Jesse Heckman committed
61
   %disp(event);
Jesse Heckman's avatar
add LSL  
Jesse Heckman committed
62
63
end

Jesse Heckman's avatar
Jesse Heckman committed
64
function pl_listener(~, event)
Jesse Heckman's avatar
add LSL    
Jesse Heckman committed
65
   disp('pl_listener called');
Jesse Heckman's avatar
Jesse Heckman committed
66
   %disp(event);
Jesse Heckman's avatar
add LSL  
Jesse Heckman committed
67
68
end

Jesse Heckman's avatar
Jesse Heckman committed
69
function gz_listener(~, event)
Jesse Heckman's avatar
Jesse Heckman committed
70
   disp('gz_listener called');
Jesse Heckman's avatar
Jesse Heckman committed
71
72
73
   %disp(event);
end

Jesse Heckman's avatar
Jesse Heckman committed
74
function ot_listener(~, event)
Jesse Heckman's avatar
add LSL    
Jesse Heckman committed
75
   disp('ot_listener called');
Jesse Heckman's avatar
Jesse Heckman committed
76
   %disp(event);
Jesse Heckman's avatar
add LSL  
Jesse Heckman committed
77
78
79
80
81
82
83
84
85
end

% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % 
%                                                           %
%       Part of Programmeer Beer Toolbox (PBToolbox)        %
%       Written by: Jesse J. Heckman (2018)                 %
%                                                           %
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %