tsb_tq_page.lua 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. --[[
  2. @module tsb_tq_page
  3. @summary 提枪信号演示页面
  4. @version 1.0
  5. @date 2026.03.04
  6. @author 李一玮
  7. @usage
  8. 本文件是提枪信号演示页面,展示提枪信号的各种用法。
  9. ]]
  10. local tsb_tq_page = {}
  11. -- 页面UI元素
  12. local main_container = nil
  13. local common_ui = require("tsb_common_page")
  14. -- 创建UI
  15. function tsb_tq_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 = 0xF44336,
  31. })
  32. airui.label({
  33. parent = title_bar,
  34. text = "提枪信号",
  35. x = 200,
  36. y = 8,
  37. w = 80,
  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_tq_page.cleanup)
  45. ---------------------------------------------------
  46. -- 滚动容器
  47. local scroll_container = airui.container({
  48. parent = main_container,
  49. x = 0,
  50. y = 30,
  51. w = 480,
  52. h = 270,
  53. color = 0xF5F5F5,
  54. })
  55. local keyboard1 = airui.keyboard({
  56. x = 0,
  57. y = 0,
  58. w = 480,
  59. h = 160, -- x, y, 键盘默认打开ALIGN_BOTTOM_MID,位置从中下方开始计算
  60. mode = "numeric", -- 键盘模式,可选 "text"/"upper"/"lower"/"numeric"
  61. auto_hide = true, -- 自动隐藏键盘
  62. preview = true,
  63. preview_height = 35,
  64. bg_color = 0xf1f1f1, -- 键盘背景颜色为灰色,可选,不设置则透明
  65. on_commit = function() -- 确认事件回调,只有在按下确认键时才会触发
  66. log.info("keyboard", "commit")
  67. end
  68. })
  69. ------------------- 提枪信号输入 ------------------
  70. local tq_input_container = airui.container({
  71. parent = scroll_container,
  72. x = 10,
  73. y = 5,
  74. w = 200,
  75. h = 260,
  76. color = 0xFFFFFF,
  77. radius = 5,
  78. })
  79. airui.label({
  80. parent = tq_input_container,
  81. text = "提枪信号输入",
  82. x = 35,
  83. y = 10,
  84. w = 140,
  85. h = 30,
  86. font_size = 18,
  87. })
  88. airui.label({
  89. parent = tq_input_container,
  90. text = "油枪状态:",
  91. x = 20,
  92. y = 80,
  93. w = 80,
  94. h = 30,
  95. font_size = 16,
  96. })
  97. local label_cur_vol = airui.label({
  98. parent = tq_input_container,
  99. text = "抬枪",
  100. x = 100,
  101. y = 80,
  102. w = 60,
  103. h = 30,
  104. font_size = 16,
  105. })
  106. airui.label({
  107. parent = tq_input_container,
  108. text = "实时电压:",
  109. x = 20,
  110. y = 140,
  111. w = 100,
  112. h = 30,
  113. font_size = 16,
  114. })
  115. local label_pulse_count = airui.label({
  116. parent = tq_input_container,
  117. text = "5.0V",
  118. x = 100,
  119. y = 140,
  120. w = 70,
  121. h = 30,
  122. font_size = 16,
  123. })
  124. ----------------------------------------------------
  125. ------------------- 提枪信号输出 ------------------
  126. local tq_output_container = airui.container({
  127. parent = scroll_container,
  128. x = 220,
  129. y = 5,
  130. w = 250,
  131. h = 260,
  132. color = 0xFFFFFF,
  133. radius = 5,
  134. })
  135. airui.label({
  136. parent = tq_output_container,
  137. text = "提枪信号输出",
  138. x = 60,
  139. y = 10,
  140. w = 140,
  141. h = 30,
  142. font_size = 18,
  143. })
  144. -- 输出电压
  145. airui.label({
  146. parent = tq_output_container,
  147. text = "输出电压:",
  148. x = 20,
  149. y = 80,
  150. w = 80,
  151. h = 30,
  152. font_size = 16,
  153. })
  154. local voltage_output = airui.textarea({
  155. parent = tq_output_container,
  156. x = 100,
  157. y = 72,
  158. w = 60,
  159. h = 35,
  160. text = "5",
  161. max_len = 2,
  162. keyboard = keyboard1
  163. })
  164. airui.label({
  165. parent = tq_output_container,
  166. text = "V",
  167. x = 165,
  168. y = 80,
  169. w = 30,
  170. h = 30,
  171. font_size = 16,
  172. })
  173. --------------------- 新国标开关 -------------------
  174. airui.label({
  175. parent = tq_output_container,
  176. text = "周期输出:",
  177. x = 20,
  178. y = 140,
  179. w = 80,
  180. h = 20,
  181. font_size = 16,
  182. })
  183. local switch_tq = airui.switch({
  184. parent = tq_output_container,
  185. x = 100,
  186. y = 133,
  187. w = 55,
  188. h = 25,
  189. checked = false,
  190. on_change = function(self)
  191. log.info("NEW_TAX", self:get_state() and "开启" or "关闭")
  192. end
  193. })
  194. airui.label({
  195. parent = tq_output_container,
  196. text = "开启后,提枪信号将按照3s的周期切换输出上面设置的电压和0V。",
  197. x = 20,
  198. y = 170,
  199. w = 200,
  200. h = 40,
  201. font_size = 12,
  202. color = 0x757575,
  203. })
  204. -- 按钮
  205. local start_btn = airui.button({
  206. parent = tq_output_container,
  207. x = 40,
  208. y = 215,
  209. w = 80,
  210. h = 35,
  211. text = "开始",
  212. style = { bg_color = 0x2B6FF1,border_color = 0x2B6FF1, text_color = 0xFFFFFF, radius = 8 },
  213. on_click = function(self)
  214. log.info("button", "开始按钮被点击")
  215. end
  216. })
  217. local stop_btn = airui.button({
  218. parent = tq_output_container,
  219. x = 130,
  220. y = 215,
  221. w = 80,
  222. h = 35,
  223. text = "停止",
  224. on_click = function(self)
  225. log.info("button", "停止按钮被点击")
  226. end
  227. })
  228. ----------------------------------------------------
  229. -- 底部信息
  230. common_ui.create_status_bar(main_container)
  231. end
  232. -- 初始化页面
  233. function tsb_tq_page.init(params)
  234. tsb_tq_page.create_ui()
  235. end
  236. -- 清理页面
  237. function tsb_tq_page.cleanup()
  238. if main_container then
  239. main_container:destroy()
  240. main_container = nil
  241. end
  242. end
  243. return tsb_tq_page