tsb_bmq_page.lua 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  1. --[[
  2. @module tsb_bmq_page
  3. @summary 编码器演示页面
  4. @version 1.0
  5. @date 2026.03.04
  6. @author 李一玮
  7. @usage
  8. 本文件是编码器演示页面,展示编码器的各种用法。
  9. ]]
  10. local tsb_bmq_page = {}
  11. -- 页面UI元素
  12. local main_container = nil
  13. local common_ui = require("tsb_common_page")
  14. -- 创建UI
  15. function tsb_bmq_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 = 0xFF9800,
  31. })
  32. airui.label({
  33. parent = title_bar,
  34. text = "编码器",
  35. x = 210,
  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_bmq_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 bmq_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 = bmq_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 = bmq_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 = bmq_input_container,
  97. text = "高",
  98. x = 100,
  99. y = 80,
  100. w = 80,
  101. h = 30,
  102. font_size = 16,
  103. })
  104. airui.label({
  105. parent = bmq_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 = bmq_input_container,
  115. text = "12345",
  116. x = 120,
  117. y = 140,
  118. w = 70,
  119. h = 30,
  120. font_size = 16,
  121. })
  122. local tax_serial_btn = airui.button({
  123. parent = bmq_input_container,
  124. x = 65,
  125. y = 215,
  126. w = 80,
  127. h = 35,
  128. text = "清零",
  129. on_click = function(self)
  130. log.info("button", "基本按钮被点击")
  131. label_pulse_count:set_text("0")
  132. end
  133. })
  134. ----------------------------------------------------
  135. ------------------- 模拟编码器输出 ------------------
  136. local bmq_output_container = airui.container({
  137. parent = scroll_container,
  138. x = 220,
  139. y = 5,
  140. w = 250,
  141. h = 260,
  142. color = 0xFFFFFF,
  143. radius = 5,
  144. })
  145. airui.label({
  146. parent = bmq_output_container,
  147. text = "编码器信号输出",
  148. x = 60,
  149. y = 10,
  150. w = 140,
  151. h = 30,
  152. font_size = 18,
  153. })
  154. -- 脉冲周期
  155. airui.label({
  156. parent = bmq_output_container,
  157. text = "脉冲周期:",
  158. x = 20,
  159. y = 50,
  160. w = 80,
  161. h = 30,
  162. font_size = 16,
  163. })
  164. local cycle_input = airui.textarea({
  165. parent = bmq_output_container,
  166. x = 100,
  167. y = 40,
  168. w = 60,
  169. h = 35,
  170. text = "5",
  171. max_len = 5,
  172. keyboard = keyboard1
  173. })
  174. airui.label({
  175. parent = bmq_output_container,
  176. text = "ms",
  177. x = 165,
  178. y = 50,
  179. w = 30,
  180. h = 30,
  181. font_size = 16,
  182. })
  183. -- 电压幅度
  184. airui.label({
  185. parent = bmq_output_container,
  186. text = "电压幅度:",
  187. x = 20,
  188. y = 90,
  189. w = 80,
  190. h = 30,
  191. font_size = 16,
  192. })
  193. local voltage_input = airui.textarea({
  194. parent = bmq_output_container,
  195. x = 100,
  196. y = 80,
  197. w = 60,
  198. h = 35,
  199. text = "5",
  200. max_len = 2,
  201. keyboard = keyboard1
  202. })
  203. airui.label({
  204. parent = bmq_output_container,
  205. text = "V",
  206. x = 170,
  207. y = 90,
  208. w = 30,
  209. h = 30,
  210. font_size = 16,
  211. })
  212. -- 当前电平
  213. airui.label({
  214. parent = bmq_output_container,
  215. text = "当前电平:",
  216. x = 20,
  217. y = 130,
  218. w = 80,
  219. h = 30,
  220. font_size = 16,
  221. })
  222. local label_output_level = airui.label({
  223. parent = bmq_output_container,
  224. text = "高",
  225. x = 100,
  226. y = 130,
  227. w = 80,
  228. h = 30,
  229. font_size = 16,
  230. })
  231. -- 输出脉冲数
  232. airui.label({
  233. parent = bmq_output_container,
  234. text = "输出脉冲数:",
  235. x = 20,
  236. y = 170,
  237. w = 100,
  238. h = 30,
  239. font_size = 16,
  240. })
  241. local label_output_pulse = airui.label({
  242. parent = bmq_output_container,
  243. text = "0",
  244. x = 120,
  245. y = 170,
  246. w = 80,
  247. h = 30,
  248. font_size = 16,
  249. })
  250. -- 按钮
  251. local start_btn = airui.button({
  252. parent = bmq_output_container,
  253. x = 40,
  254. y = 215,
  255. w = 80,
  256. h = 35,
  257. text = "开始",
  258. stype = { bg_color = 0x2B6FF1,border_color = 0x2B6FF1, text_color = 0xFFFFFF, radius = 8 },
  259. on_click = function(self)
  260. log.info("button", "开始按钮被点击")
  261. end
  262. })
  263. local clear_btn = airui.button({
  264. parent = bmq_output_container,
  265. x = 130,
  266. y = 215,
  267. w = 80,
  268. h = 35,
  269. text = "清零",
  270. on_click = function(self)
  271. log.info("button", "清零按钮被点击")
  272. end
  273. })
  274. ----------------------------------------------------
  275. -- 底部信息
  276. common_ui.create_status_bar(main_container)
  277. end
  278. -- 初始化页面
  279. function tsb_bmq_page.init(params)
  280. tsb_bmq_page.create_ui()
  281. end
  282. -- 清理页面
  283. function tsb_bmq_page.cleanup()
  284. if main_container then
  285. main_container:destroy()
  286. main_container = nil
  287. end
  288. end
  289. return tsb_bmq_page