forked from asanlop/neuroblinks_S720
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathneuroblinks.m
88 lines (73 loc) · 2.97 KB
/
neuroblinks.m
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
% Set up environment and launch app based on which version you want to use
function neuroblinks(varargin)
warning('off','all') %turn off warning messages
% warning('on','all')
% Load local configuration for these rigs
% Should be somewhere in path but not "neuroblinks" directory or subdirectory
neuroblinks_config
% Set up defaults in case user doesn't specify all options
device = DEFAULTDEVICE;
rig = DEFAULTRIG;
% Input parsing
if nargin > 0
for i=1:nargin
if any(strcmpi(varargin{i},ALLOWEDDEVICES))
device = varargin{i};
elseif ismember(varargin{i},1:length(ALLOWEDCAMS))
rig = varargin{i};
end
end
end
% fprintf('Device: %s, Rig: %d\n', device, rig);
% return
% Matlab is inconsistent in how it numbers cameras so we need to explicitely search for the right one
disp('Finding camera...')
% Get list of configured cameras
foundcams = imaqhwinfo('gentl');
founddeviceids = cell2mat(foundcams.DeviceIDs);
if isempty(founddeviceids)
error('No cameras found')
end
if ~isempty(ALLOWEDCAMS)
% This code doesn't work on some versions of Matlab so it's not working for you, you can
% set ALLOWEDCAMS to an empty cell array in "neuroblinks_config"
% and it will default to camera 1 (but then you can only have one
% gige camera connected to your computer.
cam = 0;
for i=1:length(founddeviceids)
vidobj = videoinput('gentl', founddeviceids(i), 'Mono8');
src = getselectedsource(vidobj);
if strcmp(src.DeviceSerialNumber,ALLOWEDCAMS{rig})
cam = i;
end
delete(vidobj)
end
if ~cam
error(sprintf('The camera you specified (%d) could not be found',rig));
end
else
cam = 1;
end
try
switch lower(device)
case 'tdt'
% TDT version
% Set up path for this session
[basedir,mfile,ext]=fileparts(mfilename('fullpath'));
oldpath=addpath(genpath(fullfile(basedir,'tdt')));
addpath(genpath(fullfile(basedir,'shared')));
case 'arduino'
% % Arduino version
% % Set up path for this session
[basedir,mfile,ext]=fileparts(mfilename('fullpath'));
oldpath=addpath(genpath(fullfile(basedir,'arduino')));
addpath(genpath(fullfile(basedir,'shared')));
otherwise
error(sprintf('Device %s not found', device))
end
catch
error('You did not specify a valid device');
end
% A different "launch" function should be called depending on whether we're using TDT or Arduino
% and will be determined by what's in the path generated above
Launch(rig,cam)