When using ping_timer(), then check_timer(), it only returns true once a ping
is received, requiring the timeout to be tracked both in the library and
outside the library, requiring extra ram and processing cycles.
Changing the check_timer() method to type int8_t instead of boolean, then in
the "Outside the timeout limit" block return -1, and in the "Ping echo
received" return 1, and default return 0 allows the sketch to piggyback off the
library code, saving ram and extra conditional checks.
new method would look like:
int8_t NewPing::check_timer() {
if (micros() > _max_time) { // Outside the timeout limit.
timer_stop(); // Disable timer interrupt
return -1; // return ping echo timed out.
}
if (!(*_echoInput & _echoBit)) { // Ping echo received.
timer_stop(); // Disable timer interrupt
ping_result = (micros() - (_max_time - _maxEchoTime) - 13); // Calculate ping time, 13uS of overhead.
return 1; // Return ping echo positive.
}
return 0; // Return 0 because there's no ping echo yet.
}
Original issue reported on code.google.com by cwe...@gmail.com on 28 Feb 2014 at 4:18
Original issue reported on code.google.com by
cwe...@gmail.com
on 28 Feb 2014 at 4:18