Lua 应用开发LVGL全局函数与常量全局函数

Timer 定时器

LVGL 定时器

构造

Timer(opts?: table) -> timer

opts 参数

键类型说明
periodinteger周期(ms),省略或 0 则自动暂停
pausedinteger/boolean是否暂停
repeat_countinteger重复次数,-1 为无限
cbfunction回调,签名 function(timer)

实例方法

方法说明
t:set(opts)更新参数
t:pause暂停
t:resume恢复
t:ready立即触发一次回调
t:delete删除定时器

示例

local t = Timer({
  period = 500,
  repeat_count = -1,
  cb = function(timer)
    print("tick", lvgl.tick_get)
  end
})
t:resume

社区补充(洛汐文档库)

以下内容来自洛汐文档库《LVGL 辅助模块》:docs.luoxe.cn/docs/vela/lua/lvgl-modules

local timer = lvgl.Timer {
  period = 1000,
  repeat_count = -1,
  cb = function(timer)
    print("tick")
  end,
}

timer:pause
timer:resume
timer:set { period = 500 }
timer:ready
timer:delete
成员说明
period触发周期,毫秒
repeat_count剩余次数;-1 表示无限
cb定时回调
pause / resume暂停和恢复
set更新 period、paused、repeat_count 或 cb
ready令定时器尽快执行一次
delete删除定时器

参考来源:官方 docs-lua / 洛汐文档库

大纲