Skip to content

Commit 26a51ab

Browse files
authored
Merge pull request #11 from adafruit/ticks-exception-like-micropython
raise an OverflowError like micropython for too big a value
2 parents 527d90e + 892cca3 commit 26a51ab

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

adafruit_ticks.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,9 @@ def ticks_ms() -> int:
122122

123123
def ticks_add(ticks: int, delta: int) -> int:
124124
"Add a delta to a base number of ticks, performing wraparound at 2**29ms."
125-
return (ticks + delta) % _TICKS_PERIOD
125+
if -_TICKS_HALFPERIOD < delta < _TICKS_HALFPERIOD:
126+
return (ticks + delta) % _TICKS_PERIOD
127+
raise OverflowError("ticks interval overflow")
126128

127129

128130
def ticks_diff(ticks1: int, ticks2: int) -> int:

0 commit comments

Comments
 (0)