UIFlow Guide
通过 TimerPWR 模块获取电池、USB 和 Grove 端口的状态信息,设置模块的各种功能(如按钮、Grove 输出、OLED 背光等),并处理与设备睡眠和唤醒相关的事件。
from m5stack import *
from m5ui import *
from uiflow import *
import unit
timerpwr_1 = unit.get(unit.TIMERPWR, unit.PORTA)
timerpwr_1.init_i2c_address(0x56)
timerpwr_1.set_oled_backlight_status(True)
timerpwr_1.set_wakeup_trigger(timerpwr_1.TRIG_ALL)
while True:
timerpwr_1.sleep_cycle(0, 0, 5, 0, 0, 5)
print(timerpwr_1.get_battery_voltage())
print(timerpwr_1.get_battery_current())
print(timerpwr_1.get_usb_voltage())
print(timerpwr_1.get_usb_current())
print(timerpwr_1.get_grove_voltage())
print(timerpwr_1.get_grove_current())
print(timerpwr_1.get_firmware_version())
wait_ms(2)
timerpwr_1.init_i2c_address(0x56)
timerpwr_1.get_battery_voltage()
timerpwr_1.get_battery_current()
timerpwr_1.get_usb_voltage()
timerpwr_1.get_usb_current()
timerpwr_1.get_grove_voltage()
timerpwr_1.get_grove_current()
timerpwr_1.get_button_status(0)
timerpwr_1.get_grove_output_status()
timerpwr_1.get_oled_backlight_status()
timerpwr_1.get_firmware_version()
timerpwr_1.save_data_to_flash()
timerpwr_1.set_grove_output_status(True)
timerpwr_1.set_oled_backlight_status(True)
timerpwr_1.set_wakeup_trigger(timerpwr_1.TRIG_ALL)
timerpwr_1.set_sleep_trigger(timerpwr_1.TRIG_ALL)
timerpwr_1.sleep_once(0, 0, 5, 0, 0, 5)
timerpwr_1.sleep_cycle(0, 0, 5, 0, 0, 5)
def timerpwr_1_btna_released_event(args):
# global params
pass
timerpwr_1.set_callback(timerpwr_1.EVENT_BUTTONA_RELEASED, timerpwr_1_btna_released_event)
def timerpwr_1_charging_event(args):
# global params
pass
timerpwr_1.set_callback(timerpwr_1.EVENT_CHARGING, timerpwr_1_charging_event)
def timerpwr_1_usb_inserted_event(args):
# global params
pass
timerpwr_1.set_callback(timerpwr_1.EVENT_USB_INSERTED, timerpwr_1_usb_inserted_event)
timerpwr_1.tick()