ssd1306_test I2C uses OD pins. Old code in timed_function replaced.

pull/7/head
Peter Hinch 2018-08-01 09:29:31 +01:00
rodzic f01ec022da
commit f92c10d511
2 zmienionych plików z 20 dodań i 14 usunięć

Wyświetl plik

@ -64,8 +64,8 @@ def test(use_spi=False):
# Gnd Gnd
# Y9 CLK
# Y10 DATA
pscl = machine.Pin('Y9', machine.Pin.OUT_PP)
psda = machine.Pin('Y10', machine.Pin.OUT_PP)
pscl = machine.Pin('Y9', machine.Pin.OPEN_DRAIN)
psda = machine.Pin('Y10', machine.Pin.OPEN_DRAIN)
i2c = machine.I2C(scl=pscl, sda=psda)
# i2c = machine.I2C(2)
ssd = SSD1306_I2C(WIDTH, HEIGHT, i2c)

Wyświetl plik

@ -1,16 +1,16 @@
# Time a function call by means of a decorator
# On or shortly beore 1st November 2016 the semantics of utime.ticks_diff changed. If using
# older firmware please use the second example below
import utime
# @timed_function
# Print time taken by a function call
def timed_function(f, *args, **kwargs):
myname = str(f).split(' ')[1]
def new_func(*args, **kwargs):
t = utime.ticks_us()
result = f(*args, **kwargs)
delta = utime.ticks_diff(utime.ticks_us(), t) # Argument order new, old
print('Function {} Time = {:6.3f}ms'.format(myname, delta/1000))
delta = utime.ticks_diff(utime.ticks_us(), t)
print('Function {} Time = {:6.3f}ms'.format(f.__name__, delta/1000))
return result
return new_func
@ -18,15 +18,21 @@ def timed_function(f, *args, **kwargs):
def test():
utime.sleep_us(10000)
# Version for use with older firmware
def timed_function(f, *args, **kwargs):
myname = str(f).split(' ')[1]
# @time_acc_function
# applied to a function causes it to print the number of times it was called
# with the accumulated time used.
def time_acc_function(f, *args, **kwargs):
ncalls = 0
ttime = 0.0
def new_func(*args, **kwargs):
nonlocal ncalls, ttime
t = utime.ticks_us()
result = f(*args, **kwargs)
delta = utime.ticks_diff(t, utime.ticks_us()) # Argument order old, new
print('Function {} Time = {:6.3f}ms'.format(myname, delta/1000))
delta = utime.ticks_diff(utime.ticks_us(), t)
ncalls += 1
ttime += delta
print('Function: {} Call count = {} Total time = {:6.3f}ms'.format(f.__name__, ncalls, ttime/1000))
return result
return new_func