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

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

Jesse Heckman's avatar
add LSL    
Jesse Heckman committed
45
      str(iStrm) = lsl_istream(info{1});
Jesse Heckman's avatar
Jesse Heckman committed
46
     ses.add_stream(str(iStrm));
Jesse Heckman's avatar
add LSL  
Jesse Heckman committed
47
48
   end
   
Jesse Heckman's avatar
updates    
Jesse Heckman committed
49
50
51
52
   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
   if ot; addlistener(str(c),'DataAvailable', @ot_listener); end
Jesse Heckman's avatar
add LSL  
Jesse Heckman committed
53
54
end

Jesse Heckman's avatar
Jesse Heckman committed
55
function ev_listener(~, event)
Jesse Heckman's avatar
add LSL    
Jesse Heckman committed
56
   disp('ev_listener called')
Jesse Heckman's avatar
Jesse Heckman committed
57
   disp(event);
Jesse Heckman's avatar
add LSL  
Jesse Heckman committed
58
59
end

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

Jesse Heckman's avatar
Jesse Heckman committed
65
function ot_listener(~, event)
Jesse Heckman's avatar
add LSL    
Jesse Heckman committed
66
   disp('ot_listener called');
Jesse Heckman's avatar
Jesse Heckman committed
67
   disp(event);
Jesse Heckman's avatar
add LSL  
Jesse Heckman committed
68
69
70
71
72
73
74
75
76
end

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