Get battery, USB, and Grove port status information from the TimerPWR module, configure various functions of the module (such as button, Grove output, OLED backlight, etc.), and handle events related to device sleep and wake-up.
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(timer
pwr_1.EVENT_BUTTONA_RELEASED, timerpwr_1_btna_released_event) timerpwr_1_btna_released_event function when button A is released. The args parameter contains relevant data when the event is triggered.def timerpwr_1_charging_event(args):
# global params
pass
timerpwr_1.set_callback(timerpwr_1.EVENT_CHARGING, timerpwr_1_charging_event) timerpwr_1_charging_event function when the charging status changes.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_usb_inserted_event function when USB is inserted.timerpwr_1.tick()