Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit c437761

Browse files
committed
pulseIn: be consistent with standard API
return 0 if timeout has been reached
1 parent d2a38e4 commit c437761

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

‎hardware/arduino/avr/cores/arduino/wiring_pulse.c‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,12 @@ unsigned long pulseIn(uint8_t pin, uint8_t state, unsigned long timeout)
4848
unsigned long maxloops = microsecondsToClockCycles(timeout)/16;
4949

5050
width = countPulseASM(portInputRegister(port), bit, stateMask, maxloops);
51-
return clockCyclesToMicroseconds(width * 16 + 16);
51+
52+
//prevent clockCyclesToMicroseconds to return bogus values if countPulseASM timed out
53+
if (width)
54+
return clockCyclesToMicroseconds(width * 16 + 16);
55+
else
56+
return 0;
5257
}
5358

5459
/* Measures the length (in microseconds) of a pulse on the pin; state is HIGH

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /