Example #1
0
# ------------------------------------------------------------
#        Developping with MicroPython in an async way
#
# ------------------------------------------------------------
#                      === asyncio tests  ===
# ------------------------------------------------------------
print("==== /test/asyncio/test_createkilldye.py")

import logging
log = logging.getlogger("test")
logs = logging.getlogger("scheduler")
logs.setLevel(logging.TRACE)
logging.setGlobal(logging.DEBUG)
loge = logging.getlogger("esp")
loge.setLevel(logging.INFO)

import utime as time, sys
import asyncio

from neopixels import Neopixels

neo = Neopixels(13, 4)
neo.brightness = 50
neo.clearBuffer()

# ------------------------------------------------------------
#                      === Example ===
# ------------------------------------------------------------
total = 0
# 4 tasks
Example #2
0
# ------------------------------------------------------------
#        Developping with MicroPython in an async way
#
# ------------------------------------------------------------
#                      === library  tests  ===
# ------------------------------------------------------------
import logging


logging.setGlobal(logging.TRACE)
log = logging.getlogger("test")
log.debug("Test message (not printed): %d (%s)", 100, "INFO / global: TRACE")
log.info("Test message2 (printed): %d (%s)", 100, "INFO / global: TRACE")

log.setLevel(logging.DEBUG)
log.info("lower level of test: %d (%s)", 100, "DEBUG / global: TRACE")
log.debug("Test message (printed): %d (%s)", 100, "DEBUG / global: TRACE")

logging.setGlobal(logging.WARNING)
log.warn( "raise global level: %d (%s)", 100, "DEBUG / global: WARN"  )
log.debug("Test message (not printed): %d(%s)", 100, "DEBUG / global: WARN")

log.error("xxx" )
# ------------------------------------------------------------
# pyos.py  -  The Python Cooperative Operating System
#
# ------------------------------------------------------------
print("==== /sd/test/asyncio/test_gettaskref.py")

import logging
log = logging.getlogger("test_taskref")
logs = logging.getlogger("scheduler")
logs.setLevel(logging.TRACE)

logging.setGlobal(logging.DEBUG)

import pyb
import time,sys
import asyncio

leds = []
for i in range(1,5):
    led = pyb.LED( i  )
    led.on()
    leds.append(   led )

# ------------------------------------------------------------
#                      === Example ===
# ------------------------------------------------------------
total = 0
# 4 tasks
def  led0():
    sos = [(1,1),(1,1),(1,1),   (2,1),(2,1),(2,1),    (1,1),(1,1),(1,10) ]
    yield
Example #4
0
# ------------------------------------------------------------
#        Developping with MicroPython in an async way
#
# ------------------------------------------------------------
#                      === asyncio tests  ===
# ------------------------------------------------------------
print("==== /sd/test/asyncio/test_taskprio.py")

import logging

log = logging.getlogger("test_taskprio")
logging.setGlobal(logging.TRACE)

import utime as time
import sys
from asyncio import Task
from asyncio import Scheduler


# dummy coroutine
def dummy():
    yield


taskLate = Task(dummy(), name="taskLate", prio=10)
taskEarly = Task(dummy(), name="taskEarly", prio=10)
taskMedium5 = Task(dummy(), name="taskMedium5", prio=5)
taskMedium15 = Task(dummy(), name="taskMedium15", prio=15)

taskLate.time2run = 1001
taskEarly.time2run = 110
# ------------------------------------------------------------
# pyos.py  -  The Python Cooperative Operating System
#
# ------------------------------------------------------------
print("==== /sd/test/asyncio/test_taskprio.py")

import logging

log = logging.getlogger("test_taskprio")
logging.setGlobal(logging.TRACE)

import time
import sys
from  asyncio import Task
from  asyncio import Scheduler



# dummy coroutine
def  dummy():
    yield

taskLate = Task(dummy(), name = "taskLate", prio = 10)
taskEarly = Task(dummy(), name = "taskEarly", prio = 10)
taskMedium5 = Task(dummy(), name = "taskMedium5", prio = 5)
taskMedium15 = Task(dummy(), name = "taskMedium15", prio = 15)

taskLate.time2run  = 1001
taskEarly.time2run  = 110
taskMedium5.time2run  = 500
taskMedium15.time2run  = 500