kopia lustrzana https://github.com/peterhinch/micropython-samples
Add timeout sample. Remove make axtls from buildnew script.
rodzic
ac350c1e28
commit
11d6db9d68
|
@ -44,7 +44,8 @@ Raise an exception if a firmware build is earlier than a given date.
|
||||||
|
|
||||||
# timed_function
|
# timed_function
|
||||||
|
|
||||||
Time a function's execution using a decorator.
|
Time a function's execution using a decorator. Also a way to implement timeouts
|
||||||
|
using a closure.
|
||||||
|
|
||||||
# ESP8266 (MQTT benchmark)
|
# ESP8266 (MQTT benchmark)
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,6 @@ cd ../esp8266
|
||||||
make clean
|
make clean
|
||||||
cd ../unix
|
cd ../unix
|
||||||
make clean
|
make clean
|
||||||
make -j 8 axtls
|
|
||||||
# If you're going to enable deplibs: see micropython/README
|
# If you're going to enable deplibs: see micropython/README
|
||||||
#make deplibs
|
#make deplibs
|
||||||
make -j 8
|
make -j 8
|
||||||
|
|
|
@ -0,0 +1,15 @@
|
||||||
|
# Implement a timeout using a closure
|
||||||
|
import utime
|
||||||
|
|
||||||
|
def to(t):
|
||||||
|
tstart = utime.ticks_ms()
|
||||||
|
def foo():
|
||||||
|
return utime.ticks_diff(utime.ticks_ms(), tstart) > t
|
||||||
|
return foo
|
||||||
|
|
||||||
|
# Usage
|
||||||
|
t = to(3000)
|
||||||
|
for _ in range(10):
|
||||||
|
print(t())
|
||||||
|
utime.sleep(0.5)
|
||||||
|
|
Ładowanie…
Reference in New Issue