Show
Ignore:
Timestamp:
12/05/08 16:07:15 (4 years ago)
Author:
atorf
Message:

Updated analog sensor functions to work on very fast USB connections (check valid flag)

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/mfiles/GetLight.m

    r307 r502  
    3030% Signature 
    3131%   Author: Linus Atorf, Alexander Behrens (see AUTHORS) 
    32 %   Date: 2007/10/15 
     32%   Date: 2008/12/05 
    3333%   Copyright: 2007-2008, RWTH Aachen University 
    3434% 
     
    6060    in = NXT_GetInputValues(port, handle); 
    6161 
     62%% Check valid-flag, re-request data if necessary 
     63    if ~in.Valid 
     64        % init timeout-counter 
     65        startTime = clock(); 
     66        timeOut = 0.1; % in seconds 
     67        % loop until valid 
     68        while (~in.Valid) && (etime(clock, startTime) < timeOut) 
     69            in = NXT_GetInputValues(port, handle); 
     70        end%while 
     71        %TODO please note that we DO NOT warn or do anything else if this 
     72        %procedure above times out -- that seems ok, since we didn't do 
     73        %that before (old ver. up to 2.02) either... 
     74        % in that case, the returned value will probably be invalid... 
     75        % dangerous. 
     76        % solutions: either WARN, or return NaN... 
     77    end%if 
     78     
    6279%% Return normalized sound value (0...1023 / 10 Bit)     
    6380    light = double(in.NormalizedADVal);