pycom / pycom-micropython-sigfox

A fork of MicroPython with the ESP32 port customized to run on Pycom's IoT multi-network modules.
MIT License
199 stars 167 forks source link

ticks_diff() argument order reversed? #56

Closed rolandvs closed 6 years ago

rolandvs commented 7 years ago

I use both pyboard and xxPy, running both micropython. I used some code cross-boards as far as possible, and I ran into a minor annoyance for a function in utime called ticks_diff() that really doesn't have to be different at all.

The micropython of Pycom reverses the order of the arguments, whereas the implementation on the original micropython platform uses the IMHO right way to do this. Just to illustrate:

micropython's way

# Wait for GPIO pin to be asserted, but at most 500us
start = time.ticks_us()
while pin.value() == 0:
    if time.ticks_diff(time.ticks_us(), start) > 500:
        raise TimeoutError

Pycom's micropython way

# Wait for GPIO pin to be asserted, but at most 500us
start = time.ticks_us()
while pin.value() == 0:
    if time.ticks_diff(start, time.ticks_us()) > 500:
        raise TimeoutError
robert-hh commented 6 years ago

Actually they are reversed, and that is documented. The other inconsistency is the behaviour in exchanging the arguments to the call. In the MicroPython.org version, simply the sign is changed. In the Pycom version the result is told to be not valid, if the parameters are ticks_diff(new, old) instead of (old, new). I submitted a PR to make at least this behavior more robust.

husigeza commented 6 years ago

Hello, The order of the parameters are swapped in development release 1.9.0.b4 (with uasyncio support), so they are consistent with the MicroPython implemented version of the function. Closing this issue.