| 1 | function byte = outputmode2byte(varargin) |
|---|
| 2 | % Determines mode byte bit field from given output mode |
|---|
| 3 | % |
|---|
| 4 | % Syntax |
|---|
| 5 | % byte = outputmode2byte(varargin) |
|---|
| 6 | % |
|---|
| 7 | % Description |
|---|
| 8 | % The constant names and enumerations are directly taken from the LEGO |
|---|
| 9 | % Mindstorms Bluetooth SDK and Direct Commands Appendix |
|---|
| 10 | % |
|---|
| 11 | % Signature |
|---|
| 12 | % Author: Linus Atorf (see AUTHORS) |
|---|
| 13 | % Date: 2007/10/14 |
|---|
| 14 | % Copyright: 2007, RWTH Aachen University |
|---|
| 15 | % |
|---|
| 16 | % |
|---|
| 17 | % *********************************************************************************************** |
|---|
| 18 | % * This file is part of the RWTH - Mindstorms NXT Toolbox. * |
|---|
| 19 | % * * |
|---|
| 20 | % * The RWTH - Mindstorms NXT Toolbox is free software: you can redistribute it and/or modify * |
|---|
| 21 | % * it under the terms of the GNU General Public License as published by the Free Software * |
|---|
| 22 | % * Foundation, either version 3 of the License, or (at your option) any later version. * |
|---|
| 23 | % * * |
|---|
| 24 | % * The RWTH - Mindstorms NXT Toolbox is distributed in the hope that it will be useful, * |
|---|
| 25 | % * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * |
|---|
| 26 | % * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. * |
|---|
| 27 | % * * |
|---|
| 28 | % * You should have received a copy of the GNU General Public License along with the * |
|---|
| 29 | % * RWTH - Mindstorms NXT Toolbox. If not, see <http: |
|---|
| 30 | % *********************************************************************************************** |
|---|
| 31 | |
|---|
| 32 | %% Create look up table |
|---|
| 33 | NXT__MOTORON = uint8(1); |
|---|
| 34 | NXT__BRAKE = uint8(2); |
|---|
| 35 | NXT__REGULATED = uint8(4); |
|---|
| 36 | |
|---|
| 37 | byte = uint8(0); |
|---|
| 38 | |
|---|
| 39 | %% Check parameter |
|---|
| 40 | if nargin == 0 |
|---|
| 41 | return |
|---|
| 42 | end%if |
|---|
| 43 | |
|---|
| 44 | %% Interpret output mode |
|---|
| 45 | for j = 1 : nargin |
|---|
| 46 | if ~ischar(varargin{j}) |
|---|
| 47 | error('MATLAB:RWTHMindstormsNXT:invalidVararginParameter', 'Input arguments must be a combination of these strings: ''MOTORON'', ''BRAKE'', ''REGULATED''') |
|---|
| 48 | end%if |
|---|
| 49 | if strcmpi(varargin{j}, 'MOTORON') |
|---|
| 50 | byte = bitor(byte, NXT__MOTORON); |
|---|
| 51 | elseif strcmpi(varargin{j}, 'BRAKE') |
|---|
| 52 | byte = bitor(byte, NXT__BRAKE); |
|---|
| 53 | elseif strcmpi(varargin{j}, 'REGULATED') |
|---|
| 54 | byte = bitor(byte, NXT__REGULATED); |
|---|
| 55 | else |
|---|
| 56 | %TODO Raise error here to announce unknown outputmode? |
|---|
| 57 | %error('MATLAB:RWTHMindstormsNXT:Motor:invalidOutputModeName', 'Input arguments must be a combination of these strings: ''MOTORON'', ''BRAKE'', ''REGULATED'''); |
|---|
| 58 | end%if |
|---|
| 59 | end%for |
|---|
| 60 | |
|---|
| 61 | end%function |
|---|