| 80 | | |
| 81 | | % This is the nested function for the function closure. The variable |
| 82 | | % "data", which is in the scope of the outer function, can be accessed from |
| 83 | | % within the nested function. A handel to this function is returned to the |
| 84 | | % caller of the outer function. This makes the variable "data" persistent |
| 85 | | % and from now on it can be accessed from within the nested function, even |
| 86 | | % when it is called from another scope. |
| 87 | | function val = dataClosure(varargin) |
| 88 | | |
| 89 | | % if there are two arguments, this indicates, that a property field |
| 90 | | % shall be set. varargin{1} is the field name and varargin{2} the |
| 91 | | % value, to which it should be set. |
| 92 | | if nargin == 2 |
| 93 | | switch varargin{1} |
| 94 | | case {'port'} |
| 95 | | data.port = varargin{2}; |
| 96 | | |
| 97 | | case {'power'} |
| 98 | | data.power = varargin{2}; |
| 99 | | |
| 100 | | case {'motorOn'} |
| 101 | | data.mode.motorOn = varargin{2}; |
| 102 | | |
| 103 | | case {'brake'} |
| 104 | | data.mode.brake = varargin{2}; |
| 105 | | |
| 106 | | case {'regulationMode'} |
| 107 | | data.regulationMode = varargin{2}; |
| 108 | | |
| 109 | | case {'turnRatio'} |
| 110 | | data.turnRatio = varargin{2}; |
| 111 | | |
| 112 | | case {'runState'} |
| 113 | | data.runState = varargin{2}; |
| 114 | | |
| 115 | | case {'tachoLimit'} |
| 116 | | data.tachoLimit = varargin{2}; |
| 117 | | end |
| 118 | | end |
| 119 | | val = data; |
| 120 | | end |
| 121 | | % END OF NESTED FUNCTION dataClosure() |