Skip to content

ping_timer Event based return NO_ECHO #1

@nespotts

Description

@nespotts

Hi,

When using the event based ping_timer function, I noticed that the code would not return any value if the distance was out of range. I looked into the library and found the check_timer() function and added/changed a few lines shown below. Is there a reason that you did not have it the way I changed it to?

Original Code

boolean NewPing::check_timer() {
      if (micros() > _max_time) { // Outside the timeout limit.
		timer_stop();           // Disable timer interrupt
                return false;         // Cancel ping timer.
	}

	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 true;                 // Return ping echo true.
	}

	return false; // Return false because there's no ping echo yet.
}

New Code

boolean NewPing::check_timer() {
      if (micros() > _max_time) { // Outside the timeout limit.
		timer_stop();           // Disable timer interrupt
                ping_result = NO_ECHO  // Added by Nathan
		return true;            // Added by Nathan
	}

	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 true;                 // Return ping echo true.
	}

	return false; // Return false because there's no ping echo yet.
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions