Argument order of time.ticks_diff()



  • The release candidate branch of the firmware implements a silent change of time.ticks_diff() since Nov 8, 2018. The argument order has been swapped. it is now time.ticks_diff(new, old). That is good and bad.

    Good, in that it matches what the uasyncio library expects and
    Good in that it is now compatible with the micropython.org branch.
    Bad, since existing code for the Pycom devices which make use of this call now breaks.

    Code can be made resilient to that order, e.g by using:

    # get the sign of ticks_diff, e.g. in init code.
    ticks_sign = time.ticks_diff(1, 2)
    # and later in the code, when using ticks_diff:
    elapsed_ticks = time.ticks_diff(time1, time2)  * ticks_sign
    

Log in to reply
 

Pycom on Twitter