pb_runLSL.m 2.79 KB
Newer Older
Jesse Heckman's avatar
updates  
Jesse Heckman committed
1
function [ses,str] = pb_runLSL(varargin)
2
% PB_RUNLSL
Jesse Heckman's avatar
add LSL  
Jesse Heckman committed
3
%
4
% PB_RUNLSL(varargin) 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
Jesse Heckman committed
10 11
% check if all streams are necesary

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

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

Jesse Heckman's avatar
add LSL  
Jesse Heckman committed
56
      str(iStrm) = lsl_istream(info{1});
Jesse Heckman's avatar
Jesse Heckman committed
57
      ses.add_stream(str(iStrm));
Jesse Heckman's avatar
add LSL  
Jesse Heckman committed
58 59
   end
   
Jesse Heckman's avatar
updates  
Jesse Heckman committed
60
   c = 1;
Jesse Heckman's avatar
Jesse Heckman committed
61 62 63 64
   if de; addlistener(str(c),'DataAvailable', @listener); c = c+1; end
   if pl; addlistener(str(c),'DataAvailable', @listener); c = c+1; end
   if gz; addlistener(str(c),'DataAvailable', @listener); c = c+1; end
   if pd; addlistener(str(c),'DataAvailable', @listener); c = c+1; end
Jesse Heckman's avatar
Jesse Heckman committed
65 66
   if ot; addlistener(str(c),'DataAvailable', @listener); c = c+1; end
   if sh; addlistener(str(c),'DataAvailable', @listener); end
Jesse Heckman's avatar
add LSL  
Jesse Heckman committed
67 68
end

Jesse Heckman's avatar
Jesse Heckman committed
69
function listener(~, event)
Jesse Heckman's avatar
Jesse Heckman committed
70
   %disp(event);
Jesse Heckman's avatar
add LSL  
Jesse Heckman committed
71 72 73 74 75 76 77 78 79 80
end


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