tsb_lora_page.lua 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  1. --[[
  2. @module tsb_lora_page
  3. @summary 无线局域网监测演示页面
  4. @version 1.0
  5. @date 2026.03.04
  6. @author 李一玮
  7. @usage
  8. 本文件是LORA信号检测演示页面,展示LORA信号的各种用法。
  9. ]]
  10. local tsb_lora_page = {}
  11. -- 页面UI元素
  12. local main_container = nil
  13. local common_ui = require("tsb_common_page")
  14. -- 创建UI
  15. function tsb_lora_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 = 0xFFE082,
  31. })
  32. airui.label({
  33. parent = title_bar,
  34. text = "射频局域网监测",
  35. x = 180,
  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_lora_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 = 290,
  53. color = 0xFFFFFF,
  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. -- 当前lora信道标签
  71. airui.label({
  72. parent = scroll_container,
  73. text = "当前lora信道",
  74. x = 10,
  75. y = 12,
  76. w = 100,
  77. h = 30,
  78. font_size = 14,
  79. })
  80. -- 当前lora信道值
  81. local current_channel_label = airui.label({
  82. parent = scroll_container,
  83. text = "1",
  84. x = 110,
  85. y = 12,
  86. w = 30,
  87. h = 30,
  88. font_size = 14,
  89. })
  90. -- 设置lora信道标签
  91. airui.label({
  92. parent = scroll_container,
  93. text = "设置lora信道",
  94. x = 130,
  95. y = 12,
  96. w = 100,
  97. h = 30,
  98. font_size = 14,
  99. })
  100. -- 设置lora信道下拉框
  101. local channel_dropdown = airui.dropdown({
  102. parent = scroll_container,
  103. x = 230,
  104. y = 7,
  105. w = 80,
  106. h = 30,
  107. options = {"1", "2", "3", "4", "5", "6"},
  108. default_index = 0, -- 默认选择1
  109. on_change = function(self,idx)
  110. log.info("lora_channel", "选择了信道:" .. self.options[idx + 1])
  111. end
  112. })
  113. -- 开始监测按钮
  114. local start_btn = airui.button({
  115. parent = scroll_container,
  116. x = 320,
  117. y = 5,
  118. w = 80,
  119. h = 30,
  120. text = "开始监测",
  121. style = { bg_color = 0x2B6FF1,border_color = 0x2B6FF1, text_color = 0xFFFFFF, radius = 8 },
  122. on_click = function(self)
  123. log.info("lora_monitor", "开始监测按钮被点击")
  124. end
  125. })
  126. -- 重置按钮
  127. local reset_btn = airui.button({
  128. parent = scroll_container,
  129. x = 405,
  130. y = 5,
  131. w = 60,
  132. h = 30,
  133. text = "重置",
  134. on_click = function(self)
  135. log.info("lora_monitor", "重置按钮被点击")
  136. end
  137. })
  138. ---------------------------------------------------
  139. --------------------- 第二行控制区 ------------------------
  140. -- 监测设备类型标签
  141. airui.label({
  142. parent = scroll_container,
  143. text = "监测设备类型",
  144. x = 10,
  145. y = 53,
  146. w = 100,
  147. h = 30,
  148. font_size = 14,
  149. })
  150. -- 监测设备类型下拉框
  151. local device_type_dropdown = airui.dropdown({
  152. parent = scroll_container,
  153. x = 110,
  154. y = 45,
  155. w = 100,
  156. h = 30,
  157. options = {"路由器", "连接器", "全部设备"},
  158. default_index = 0, -- 默认选择路由器
  159. on_change = function(self,idx)
  160. log.info("device_type", "选择了设备类型:" .. self.options[idx + 1])
  161. end
  162. })
  163. -- 连接器SN标签
  164. airui.label({
  165. parent = scroll_container,
  166. text = "连接器SN",
  167. x = 220,
  168. y = 53,
  169. w = 80,
  170. h = 30,
  171. font_size = 14,
  172. })
  173. -- 连接器SN输入框
  174. local sn_input = airui.textarea({
  175. parent = scroll_container,
  176. x = 290,
  177. y = 45,
  178. w = 80,
  179. h = 30,
  180. text = "",
  181. max_length = 5,
  182. keyboard = keyboard1
  183. })
  184. -- 上传服务器标签
  185. airui.label({
  186. parent = scroll_container,
  187. text = "上传",
  188. x = 380,
  189. y = 50,
  190. w = 60,
  191. h = 30,
  192. font_size = 14,
  193. })
  194. -- 上传服务器开关
  195. local upload_switch = airui.switch({
  196. parent = scroll_container,
  197. x = 415,
  198. y = 45,
  199. w = 50,
  200. h = 25,
  201. checked = true,
  202. on_change = function(self, checked)
  203. log.info("upload_switch", "上传服务器:" .. (checked and "开启" or "关闭"))
  204. end
  205. })
  206. ---------------------------------------------------
  207. --------------------- 表格区域 ------------------------
  208. -- 创建表格
  209. local lora_table = airui.table({
  210. parent = scroll_container,
  211. x = 0,
  212. y = 80,
  213. w = 480,
  214. h = 210,
  215. rows = 11, -- 10行数据 + 表头
  216. cols = 9,
  217. col_width = {70, 80, 90, 70, 70, 100, 100, 70, 150}, -- 调整列宽以适应内容
  218. border_color = 0xFFE082,
  219. })
  220. -- 设置表头
  221. local headers = {"序号", "发送方", "连接器SN", "信号", "版本", "一级类型", "二级类型", "数据", "时间"}
  222. for i, header in ipairs(headers) do
  223. lora_table:set_cell_text(0, i-1, header)
  224. end
  225. -- 示例数据
  226. local lora_data = {
  227. {"1", "设备1", "12345", "-65", "v1.0", "路由器", "A型", "00 01 02", "2024/07/02 09:30:46"},
  228. {"2", "设备2", "67890", "-70", "v1.1", "连接器", "B型", "03 04 05", "2024/07/02 09:31:00"},
  229. {"3", "设备3", "54321", "-60", "v1.0", "路由器", "A型", "06 07 08", "2024/07/02 09:32:15"},
  230. {"4", "设备4", "09876", "-75", "v1.1", "连接器", "C型", "09 0A 0B", "2024/07/02 09:33:30"},
  231. {"5", "设备5", "13579", "-68", "v1.0", "路由器", "B型", "0C 0D 0E", "2024/07/02 09:34:45"},
  232. {"6", "设备6", "24680", "-72", "v1.1", "连接器", "A型", "0F 10 11", "2024/07/02 09:35:00"},
  233. {"7", "设备7", "97531", "-63", "v1.0", "路由器", "C型", "12 13 14", "2024/07/02 09:36:15"},
  234. {"8", "设备8", "86420", "-69", "v1.1", "连接器", "B型", "15 16 17", "2024/07/02 09:37:30"},
  235. {"9", "设备9", "12457", "-66", "v1.0", "路由器", "A型", "18 19 1A", "2024/07/02 09:38:45"},
  236. {"10", "设备10", "36925", "-71", "v1.1", "连接器", "C型", "1B 1C 1D", "2024/07/02 09:39:00"},
  237. }
  238. -- 填充表格数据
  239. for i, data in ipairs(lora_data) do
  240. for j, value in ipairs(data) do
  241. lora_table:set_cell_text(i, j-1, value)
  242. end
  243. end
  244. ---------------------------------------------------
  245. -- 底部信息
  246. --common_ui.create_status_bar(main_container)
  247. end
  248. -- 初始化页面
  249. function tsb_lora_page.init(params)
  250. tsb_lora_page.create_ui()
  251. end
  252. -- 清理页面
  253. function tsb_lora_page.cleanup()
  254. -- 停止定时器
  255. common_ui.cleanup()
  256. if main_container then
  257. main_container:destroy()
  258. main_container = nil
  259. end
  260. end
  261. return tsb_lora_page