tsb_tq_page.lua 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  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. bg_color = 0xf1f1f1, -- 键盘背景颜色为灰色,可选,不设置则透明
  63. on_commit = function() -- 确认事件回调,只有在按下确认键时才会触发
  64. log.info("keyboard", "commit")
  65. end
  66. })
  67. ------------------- 提枪信号输入 ------------------
  68. local tq_input_container = airui.container({
  69. parent = scroll_container,
  70. x = 10,
  71. y = 5,
  72. w = 200,
  73. h = 260,
  74. color = 0xFFFFFF,
  75. radius = 5,
  76. })
  77. airui.label({
  78. parent = tq_input_container,
  79. text = "提枪信号输入",
  80. x = 35,
  81. y = 10,
  82. w = 140,
  83. h = 30,
  84. font_size = 18,
  85. })
  86. airui.label({
  87. parent = tq_input_container,
  88. text = "油枪状态:",
  89. x = 20,
  90. y = 80,
  91. w = 80,
  92. h = 30,
  93. font_size = 16,
  94. })
  95. local label_cur_vol = airui.label({
  96. parent = tq_input_container,
  97. text = "抬枪",
  98. x = 100,
  99. y = 80,
  100. w = 60,
  101. h = 30,
  102. font_size = 16,
  103. })
  104. airui.label({
  105. parent = tq_input_container,
  106. text = "实时电压:",
  107. x = 20,
  108. y = 140,
  109. w = 100,
  110. h = 30,
  111. font_size = 16,
  112. })
  113. local label_pulse_count = airui.label({
  114. parent = tq_input_container,
  115. text = "5.0V",
  116. x = 100,
  117. y = 140,
  118. w = 70,
  119. h = 30,
  120. font_size = 16,
  121. })
  122. ----------------------------------------------------
  123. ------------------- 提枪信号输出 ------------------
  124. local tq_output_container = airui.container({
  125. parent = scroll_container,
  126. x = 220,
  127. y = 5,
  128. w = 250,
  129. h = 260,
  130. color = 0xFFFFFF,
  131. radius = 5,
  132. })
  133. airui.label({
  134. parent = tq_output_container,
  135. text = "提枪信号输出",
  136. x = 60,
  137. y = 10,
  138. w = 140,
  139. h = 30,
  140. font_size = 18,
  141. })
  142. -- 输出电压
  143. airui.label({
  144. parent = tq_output_container,
  145. text = "输出电压:",
  146. x = 20,
  147. y = 80,
  148. w = 80,
  149. h = 30,
  150. font_size = 16,
  151. })
  152. local voltage_output = airui.textarea({
  153. parent = tq_output_container,
  154. x = 100,
  155. y = 72,
  156. w = 60,
  157. h = 35,
  158. text = "5",
  159. max_len = 2,
  160. keyboard = keyboard1
  161. })
  162. airui.label({
  163. parent = tq_output_container,
  164. text = "V",
  165. x = 165,
  166. y = 80,
  167. w = 30,
  168. h = 30,
  169. font_size = 16,
  170. })
  171. --------------------- 新国标开关 -------------------
  172. airui.label({
  173. parent = tq_output_container,
  174. text = "周期输出:",
  175. x = 20,
  176. y = 140,
  177. w = 80,
  178. h = 20,
  179. font_size = 16,
  180. })
  181. local switch_tq = airui.switch({
  182. parent = tq_output_container,
  183. x = 100,
  184. y = 133,
  185. w = 55,
  186. h = 25,
  187. checked = false,
  188. on_change = function(self)
  189. log.info("NEW_TAX", self:get_state() and "开启" or "关闭")
  190. end
  191. })
  192. airui.label({
  193. parent = tq_output_container,
  194. text = "开启后,提枪信号将按照3s的周期切换输出上面设置的电压和0V。",
  195. x = 20,
  196. y = 170,
  197. w = 200,
  198. h = 40,
  199. font_size = 12,
  200. color = 0x757575,
  201. })
  202. -- 按钮
  203. local start_btn = airui.button({
  204. parent = tq_output_container,
  205. x = 40,
  206. y = 215,
  207. w = 80,
  208. h = 35,
  209. text = "开始",
  210. stype = { bg_color = 0x2B6FF1,border_color = 0x2B6FF1, text_color = 0xFFFFFF, radius = 8 },
  211. on_click = function(self)
  212. log.info("button", "开始按钮被点击")
  213. end
  214. })
  215. local stop_btn = airui.button({
  216. parent = tq_output_container,
  217. x = 130,
  218. y = 215,
  219. w = 80,
  220. h = 35,
  221. text = "停止",
  222. on_click = function(self)
  223. log.info("button", "停止按钮被点击")
  224. end
  225. })
  226. ----------------------------------------------------
  227. -- 底部信息
  228. common_ui.create_status_bar(main_container)
  229. end
  230. -- 初始化页面
  231. function tsb_tq_page.init(params)
  232. tsb_tq_page.create_ui()
  233. end
  234. -- 清理页面
  235. function tsb_tq_page.cleanup()
  236. if main_container then
  237. main_container:destroy()
  238. main_container = nil
  239. end
  240. end
  241. return tsb_tq_page