idle.lua 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. --- 模块功能:待机界面
  2. -- @author openLuat
  3. -- @module ui.idle
  4. -- @license MIT
  5. -- @copyright openLuat
  6. -- @release 2018.03.27
  7. module(...,package.seeall)
  8. require"misc"
  9. require"ntp"
  10. require"common"
  11. --appid:窗口id
  12. local appid
  13. --[[
  14. 函数名:refresh
  15. 功能 :窗口刷新处理
  16. 参数 :无
  17. 返回值:无
  18. ]]
  19. local function refresh()
  20. --清空LCD显示缓冲区
  21. disp.clear()
  22. local oldColor = lcd.setcolor(0xF100)
  23. disp.puttext(common.utf8ToGb2312("待机界面"),lcd.getxpos(common.utf8ToGb2312("待机界面")),0)
  24. local tm = misc.getClock()
  25. local datestr = string.format("%04d",tm.year).."-"..string.format("%02d",tm.month).."-"..string.format("%02d",tm.day)
  26. local timestr = string.format("%02d",tm.hour)..":"..string.format("%02d",tm.min)..":"..string.format("%02d",tm.sec)
  27. --显示日期
  28. lcd.setcolor(0x07E0)
  29. disp.puttext(datestr,lcd.getxpos(datestr),24)
  30. --显示时间
  31. lcd.setcolor(0x001F)
  32. disp.puttext(timestr,lcd.getxpos(timestr),44)
  33. --刷新LCD显示缓冲区到LCD屏幕上
  34. disp.update()
  35. lcd.setcolor(oldColor)
  36. end
  37. --窗口类型的消息处理函数表
  38. local winapp =
  39. {
  40. onUpdate = refresh,
  41. }
  42. --[[
  43. 函数名:clkind
  44. 功能 :时间更新处理
  45. 参数 :无
  46. 返回值:无
  47. ]]
  48. local function clkind()
  49. if uiWin.isActive(appid) then
  50. refresh()
  51. end
  52. end
  53. --[[
  54. 函数名:open
  55. 功能 :打开待机界面窗口
  56. 参数 :无
  57. 返回值:无
  58. ]]
  59. function open()
  60. appid = uiWin.add(winapp)
  61. end
  62. ntp.timeSync()
  63. sys.timerLoopStart(clkind,1000)
  64. sys.subscribe("TIME_UPDATE_IND",clkind)