tsb_lora_page.lua 7.9 KB

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