check_timer should be modified to return different values for different cases
Issue #5
resolved
currently check_timer returns false in 2 different cases: 1. on time out and 2. on no echo yet
the end user programs will be much more simpler if the returned values would have been different:
in my tests I have return 2 if time out and 0 if no echo yet.
here is the modification:
byte NewPing::check_timer() {
if (micros() > _max_time) { // Outside the time-out limit.
timer_stop(); // Disable timer interrupt
return 2; // Cancel ping timer.
}
#if URM37_ENABLED == false
if (!(*_echoInput & _echoBit)) { // Ping echo received.
#else
if (*_echoInput & _echoBit) { // Ping echo received.
#endif
timer_stop(); // Disable timer interrupt
ping_result = (micros() - (_max_time - _maxEchoTime) - PING_TIMER_OVERHEAD); // Calculate ping time including overhead.
return 1; // Return ping echo true.
}
return 0; // Return false because there's no ping echo yet.
}
regards, mihai
Comments (5)
-
repo owner -
repo owner - changed status to wontfix
-
repo owner - marked as trivial
-
repo owner - changed status to resolved
-
repo owner -
assigned issue to
-
assigned issue to
- Log in to comment
This change would render existing sketches non-functional because a canceled ping (returning a value of 2) would be "true" (not zero) yet it wouldn't really be a returned ping.
In the vast majority of cases, there's no additional programming required by the end user to know when a ping has timed out. As the ping_timer() method runs in the background, knowing a ping timed out is not important. It could be you need this information because you're using the ping_timer() method in blocking mode instead of non-blocking (as the method is designed to be used). You may want to post on my support forum your sketch for me to review and point you in the right direction.
In any case, the suggestion can't be implemented due to breaking existing sketches and the very low need for such a feature.