~ubuntu-branches/ubuntu/trusty/psychtoolbox-3/trusty-proposed

« back to all changes in this revision

Viewing changes to Psychtoolbox/PsychHardware/PR705Toolbox/PR705config.m

  • Committer: Package Import Robot
  • Author(s): Yaroslav Halchenko
  • Date: 2013-11-19 23:34:50 UTC
  • mfrom: (3.1.4 experimental)
  • Revision ID: package-import@ubuntu.com-20131119233450-f7nf92vb8qavjmk8
Tags: 3.0.11.20131017.dfsg1-3
Upload to unsable since fresh glew has arrived to sid!

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
function out = PR705config(varargin)
 
2
% PR705config - Update the PR-705 configuration.
 
3
%
 
4
% Syntax:
 
5
% config_str (string) = PR705config
 
6
% errcode (scalar) = PR705config('Option1', value1, 'Option2', value2, ...)
 
7
%
 
8
% Description:
 
9
% A wrapper for setting various options on the PR-705 using the 'S'
 
10
% command. With no input arguments, the function merely returns the device's
 
11
% current configuration string. In the multiple input arguments case, here
 
12
% are the case-insensitive options and the values they take:
 
13
% Lens         ID Number of PRIMARY accessory
 
14
% Add1         ID Number of 1st ADD ON accessory
 
15
% Add2         ID Number of 2nd ADD ON accessory
 
16
% Aperture     ID Number of Aperture
 
17
% Units        0 for English
 
18
%              1 for Metric
 
19
% ExposureTime 0 - Adaptive
 
20
%              25 ... 60000 ms
 
21
% CaptureMode  0 - Single Capture
 
22
%              1 - Continuous Capture
 
23
% Cycles       1 .. 99 - Number of Captures to average
 
24
% CalcMode     0 - Power
 
25
%              1 - Energy
 
26
% TriggerMode  0 - Manual
 
27
%              1 - External
 
28
% ViewShutter  0 - Open During Measurement
 
29
%              1 - Closed During Measurement
 
30
% CIEObserver  0 -  2 Degree
 
31
%              1 - 10 Degree
 
32
%
 
33
% Example:
 
34
% errcode = PR705config('Lens', 0, 'Units', 1, 'Cycles', 2, 'ViewShutter', 1);
 
35
%
 
36
% 12/06/12    zlb   Wrote it.
 
37
 
 
38
global g_serialPort
 
39
 
 
40
if ~nargin
 
41
    IOPort('Purge', g_serialPort);
 
42
    PR705write('D601');
 
43
    out = PR705read(1, 100);
 
44
    return
 
45
end
 
46
 
 
47
values = validate_sort_input(varargin);
 
48
 
 
49
setup_str = 'S%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d';
 
50
setup_str = sprintf(setup_str, values{:});
 
51
 
 
52
if length(setup_str) > 12 % i.e., 'values' had at least 1 non-empty element
 
53
    IOPort('Purge', g_serialPort);
 
54
    PR705write(setup_str);
 
55
    errcode = PR705read(1, 10);
 
56
    out = sscanf(errcode, '%d');
 
57
else % a noop is trivially successful
 
58
    out = 0;
 
59
end
 
60
 
 
61
function sorted_values = validate_sort_input(raw_input)
 
62
valid_sorted_options = {'Lens' 'Add1' 'Add2' 'Aperture' 'Units' 'ExposureTime' ...
 
63
    'CaptureMode' 'Cycles' 'CalcMode' 'TriggerMode' 'ViewShutter' 'CIEObserver'};
 
64
 
 
65
sorted_values = cell(size(valid_sorted_options));
 
66
if mod(numel(raw_input), 2)
 
67
    fprintf('Expecting an even number of arguments (option-value pairs)!\n');
 
68
    return
 
69
end
 
70
 
 
71
options = raw_input(1:2:end);
 
72
values = raw_input(2:2:end);
 
73
if ~all(cellfun(@ischar, options)) || ~all(cellfun(@isscalar, values))
 
74
    fprintf('Improper formatting of the option-value pairs!\n');
 
75
    return
 
76
end
 
77
 
 
78
[valid_members,location] = ismember(lower(options), lower(valid_sorted_options));
 
79
if ~all(valid_members)
 
80
    invalid_options = options(~valid_members);
 
81
    fprintf('The following options aren''t recognized and will be ignored:\n');
 
82
    fprintf('\t%s\n', invalid_options{:});
 
83
end
 
84
 
 
85
values = values(valid_members);
 
86
location = location(valid_members);
 
87
 
 
88
sorted_values(location) = values(:);