示例#1
0
def _on_boot_(app_name=None, *app_args, **app_kws):
    __init_dict()
    # >>>> init screen <<<<
    import hal_screen
    hal_screen.init()
    hal_screen.get_framebuffer().fill(0)
    render_boot_image()
    # >>>> init <<<<
    # init your need.
    # import hal_keypad, hal_buzz, hal_led, hal_battery
    # hal_keypad.init()
    # hal_buzz.init()
    # hal_led.init()
    # hal_battery.init()
    # >>>> start <<<<
    if app_name != None:
        boot_app, args, kws = app_name, app_args, app_kws
    else:
        boot_app, args, kws = get_boot_app()
    clear_boot_app()
    clear_boot_image()
    clear_temporary_dir()
    if isinstance(boot_app, str) and boot_app != "":
        # app.clear_boot_app()
        gc.collect()
        run_app(boot_app, *args, **kws)
    else:
        call_component('app_selector')
    print("Program ended, entering REPL mode when running on Play32.")
    usys.exit(0)
示例#2
0
def do_connect():
    wlan.active(True)                 # Activate the interface so you can use it.
    if not wlan.isconnected():        # Unless already connected, try to connect.
        print('connecting to network...')
        wlan.connect(settings["wifi_name"], settings["password"])  # Connect to the station using
                                                                   # credentials from the json file.
        if not wlan.isconnected():
            print("Can't connect to network with given credentials.")
            usys.exit(0)  # This will programmatically break the execution of this script and return to shell.
        print('network config:', wlan.ifconfig())
示例#3
0
def main2():

    usys.exit(1)

    global mcp3008_spi
    global mcp3008_cs
    global mcp3008_out_buf
    global mcp3008_in_buf
    # initialize
    mcp3008_spi = SPI(0, sck=Pin(2), mosi=Pin(3), miso=Pin(4), baudrate=10000)
    mcp3008_cs = Pin(5, Pin.OUT)
    mcp3008_cs.value(1)  # disable chip at start

    mcp3008_cs.value(1)  # ncs on
    mcp3008_out_buf = bytearray(3)
    mcp3008_out_buf[0] = 0x01
    mcp3008_in_buf = bytearray(3)

    global m
    m = [7, 6, 5, 4, 0, 1, 2, 3]

    led = Pin(25, Pin.OUT)
    led.off()

    o = 64
    so = 0
    t = 3
    for i in range(600):
        t0 = ticks_ms()
        m = mcp3008_read(7)
        so = co(so, m)
        #print(so)
        t1 = ticks_ms()
        m1, m2 = divmod(m, 16)
        print(so, m1, ticks_diff(t1, t0))
        if so - m1 > 2:
            so = m1 + 0
            print("a1", so)
        else:
            if so - m1 < -2:
                so = m1 - 0
                print("a2", so)
        sleep(0.1)
import usys as sys
from lv_colors import lv_colors

try:
    with open('../../../assets/img_hand_argb.bin', 'rb') as f:
        hand_img_data = f.read()
except:
    try:
        with open('images/img_hand_rgb565.bin', 'rb') as f:
            hand_img_data = f.read()
    except:
        print("Could not find img_hand file")
        sys.exit()

# create the hands image data

img_hand_dsc = lv.img_dsc_t({
    "header": {
        "always_zero": 0,
        "w": 100,
        "h": 9,
        "cf": lv.img.CF.TRUE_COLOR_ALPHA
    },
    "data": hand_img_data,
    "data_size": len(hand_img_data),
})

# needle colors
needle_colors = [lv_colors.BLUE, lv_colors.ORANGE, lv_colors.PURPLE]

# create the gauge
示例#5
0
# coding=utf-8
# This is a sample Python script.

import usys
import utime
import network
from video import Recorder

# 检查参数
if len(usys.argv) < 3:
    print("Usage: %s <ssid> <password>" % usys.argv[0])
    usys.exit(1)


# 定义网络事件回调函数
def network_evt_cb(eid):
    print('%s:%d' % ('eid', eid))


# 连接网络
network.init(network.WIFI)
network.connect(usys.argv[1], usys.argv[2], network_evt_cb)
network.close()

# 等待网络连接
utime.sleep_ms(10000)
print("start recorder with rtsp test")

# 开启视频流功能
recorder = Recorder()
recorder.open(0, recorder.H264)
示例#6
0
ntptime.host = "0.au.pool.ntp.org"  # Find your local NTP server here: https://www.ntppool.org/en/

rtc = RTC()

if wlan.isconnected(
) == True:  # This test is redundant since connection is tested in the do_connect() method
    try:
        print("Utime time before synchronization:%s" % str(utime.localtime()))
        #make sure to have internet connection
        ntptime.settime()
        print("Utime/UTC time after synchronization:%s" %
              str(utime.localtime()))
    except:
        print("Error syncing time")
        usys.exit()
else:
    print("Not connected")
    sys.exit()

current_time_date_utc = utime.localtime(
)  # The ntptime library will set utime.localtime to the UTC time automatically.
current_time_date_local = utime.mktime(
    current_time_date_utc)  # Create a new time object to store the local time.
current_time_date_local += 11 * 3600  # Sydney is 11 hours ahead of UTC. One hour has 60*60 = 3600 seconds
print("Local time:, ", utime.localtime(
    current_time_date_local))  # This shows time at your location

# You can set the ESP32 RTC to your local time, or UTC time. Bellow, I am setting to UTC:
'''
rtc.datetime(  (current_time_date_utc[0],
示例#7
0
# test sys module's exit function

try:
    import usys as sys
except ImportError:
    import sys

try:
    sys.exit
except AttributeError:
    print("SKIP")
    raise SystemExit

try:
    raise SystemExit
except SystemExit as e:
    print("SystemExit", e.args)

try:
    sys.exit()
except SystemExit as e:
    print("SystemExit", e.args)

try:
    sys.exit(42)
except SystemExit as e:
    print("SystemExit", e.args)
  - Wires
  - Breadboard

 Documentation:
 ESP32 sleep modes: https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/system/sleep_modes.html
 Deep sleep: http://docs.micropython.org/en/latest/esp32/quickref.html#deep-sleep-mode
 Machine power-related functions: DEEPSLEEP_RESET
 
 Course:
 MicroPython with the ESP32
 https://techexplorations.com

'''

# machine constants: http://docs.micropython.org/en/latest/library/machine.html?highlight=reset_cause#machine-constants

import machine, usys

print("Reset cause: ", machine.reset_cause())

# check if the device woke from a deep sleep
if machine.reset_cause(
) == machine.DEEPSLEEP_RESET:  # If you are testing for light sleep, use machine.SOFT_RESET
    print("Woke from a deep sleep")
    usys.exit(
    )  # # This will programmatically break the execution of this script and return to shell.
else:
    # put the device to sleep for 10 seconds
    print("Going to sleep for 10 seconds...")
    machine.deepsleep(10000)
    # you can also use machine.lightsleep(1000) to place the ESP32 in light sleep (retains RAM)