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

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

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

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

Jesse Heckman's avatar
Jesse Heckman committed
59
function pl_listener(~, event)
Jesse Heckman's avatar
add LSL    
Jesse Heckman committed
60
   disp('pl_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 ot_listener(~, event)
Jesse Heckman's avatar
add LSL    
Jesse Heckman committed
65
   disp('ot_listener called');
Jesse Heckman's avatar
Jesse Heckman committed
66
   disp(event);
Jesse Heckman's avatar
add LSL  
Jesse Heckman committed
67
68
69
70
71
72
73
74
75
end

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