tsb_232log_page.lua 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. --[[
  2. @module tsb_232log_page
  3. @summary 232日志页面
  4. @version 1.0
  5. @date 2026.03.17
  6. @author 李一玮
  7. @usage
  8. 本文件是232日志页面,展示232日志的各种用法。
  9. ]]
  10. local tsb_232log_page = {}
  11. -- 页面UI元素
  12. local main_container = nil
  13. local common_ui = require("tsb_common_page")
  14. -- 创建UI
  15. function tsb_232log_page.create_ui()
  16. main_container = airui.container({
  17. x = 0,
  18. y = 0,
  19. w = 480,
  20. h = 320,
  21. color = 0xF5F5F5,
  22. })
  23. --------------------- 标题栏 ------------------------
  24. local title_bar = airui.container({
  25. parent = main_container,
  26. x = 0,
  27. y = 0,
  28. w = 480,
  29. h = 30,
  30. color = 0xFFCCBC,
  31. })
  32. airui.label({
  33. parent = title_bar,
  34. text = "232监测界面",
  35. x = 190,
  36. y = 8,
  37. w = 200,
  38. h = 20,
  39. font_size = 16,
  40. color = 0xFFFFFF,
  41. })
  42. -- 标题栏公共信息展示
  43. common_ui.add_battery_display(title_bar)
  44. common_ui.create_back_button(title_bar, tsb_232log_page.cleanup)
  45. -- 滚动容器
  46. local scroll_container = airui.container({
  47. parent = main_container,
  48. x = 0,
  49. y = 30,
  50. w = 480,
  51. h = 270,
  52. color = 0xFFFFFF,
  53. })
  54. --------------------- 控制区 ------------------------
  55. -- 波特率标签
  56. airui.label({
  57. parent = scroll_container,
  58. text = "波特率:",
  59. x = 5,
  60. y = 16,
  61. w = 60,
  62. h = 30,
  63. font_size = 15,
  64. })
  65. -- 波特率下拉框
  66. local baudrate_dropdown = airui.dropdown({
  67. parent = scroll_container,
  68. x = 65,
  69. y = 7,
  70. w = 100,
  71. h = 35,
  72. options = {"2400", "4800", "9600", "19200", "38400", "57600", "115200"},
  73. default_index = 2, -- 默认选择9600
  74. on_change = function(self,idx)
  75. log.info("485_baudrate", "选择了波特率:" .. self.options[idx + 1])
  76. end
  77. })
  78. airui.label({
  79. parent = scroll_container,
  80. text = "推测:",
  81. x = 180,
  82. y = 16,
  83. w = 40,
  84. h = 30,
  85. font_size = 15,
  86. })
  87. local baud_predict = airui.label({
  88. parent = scroll_container,
  89. text = "2400",
  90. x = 220,
  91. y = 15,
  92. w = 50,
  93. h = 20,
  94. font_size = 15,
  95. })
  96. --------------------- 485日志显示 ------------------------
  97. local log_container = airui.container({
  98. parent = scroll_container,
  99. x = 0,
  100. y = 45,
  101. w = 480,
  102. h = 222,
  103. color = 0xFFFFFF,
  104. })
  105. -- 日志内容显示
  106. local log_content = airui.textarea({
  107. parent = log_container,
  108. x = 5,
  109. y = 5,
  110. w = 470,
  111. h = 212,
  112. text = "00 01 02 03 04 05 06 07\n" ..
  113. "08 09 0A 0B 0C 0D 0E 0F\n"
  114. })
  115. -- 开始监测按钮
  116. local start_btn = airui.button({
  117. parent = scroll_container,
  118. x = 285,
  119. y = 5,
  120. w = 100,
  121. h = 35,
  122. text = "开始监测",
  123. stype = { bg_color = 0x2B6FF1,border_color = 0x2B6FF1, text_color = 0xFFFFFF, radius = 8 },
  124. on_click = function(self)
  125. log.info("485_log", "开始监测按钮被点击")
  126. end
  127. })
  128. -- 清空按钮
  129. local clear_btn = airui.button({
  130. parent = scroll_container,
  131. x = 395,
  132. y = 5,
  133. w = 80,
  134. h = 35,
  135. text = "清空",
  136. on_click = function(self)
  137. log.info("485_log", "清空按钮被点击")
  138. -- 清空日志内容
  139. log_content:set_text("")
  140. end
  141. })
  142. ---------------------------------------------------
  143. -- 底部信息
  144. common_ui.create_status_bar(main_container)
  145. end
  146. -- 初始化页面
  147. function tsb_232log_page.init(params)
  148. tsb_232log_page.create_ui()
  149. end
  150. -- 清理页面
  151. function tsb_232log_page.cleanup()
  152. if main_container then
  153. main_container:destroy()
  154. main_container = nil
  155. end
  156. end
  157. return tsb_232log_page