| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289 |
- --[[
- @module tsb_lora_page
- @summary 无线局域网监测演示页面
- @version 1.0
- @date 2026.03.04
- @author 李一玮
- @usage
- 本文件是LORA信号检测演示页面,展示LORA信号的各种用法。
- ]]
- local tsb_lora_page = {}
- -- 页面UI元素
- local main_container = nil
- local common_ui = require("tsb_common_page")
- -- 创建UI
- function tsb_lora_page.create_ui()
- main_container = airui.container({
- x = 0,
- y = 0,
- w = 480,
- h = 320,
- color = 0xF5F5F5,
- })
- --------------------- 标题栏 ------------------------
- local title_bar = airui.container({
- parent = main_container,
- x = 0,
- y = 0,
- w = 480,
- h = 30,
- color = 0xFFE082,
- })
- airui.label({
- parent = title_bar,
- text = "射频局域网监测",
- x = 180,
- y = 8,
- w = 200,
- h = 20,
- font_size = 16,
- color = 0xFFFFFF,
- })
- -- 标题栏公共信息展示
- common_ui.add_battery_display(title_bar)
- common_ui.create_back_button(title_bar, tsb_lora_page.cleanup)
- ---------------------------------------------------
- -- 滚动容器
- local scroll_container = airui.container({
- parent = main_container,
- x = 0,
- y = 30,
- w = 480,
- h = 290,
- color = 0xFFFFFF,
- })
- local keyboard1 = airui.keyboard({
- x = 0,
- y = 0,
- w = 480,
- h = 160, -- x, y, 键盘默认打开ALIGN_BOTTOM_MID,位置从中下方开始计算
- mode = "numeric", -- 键盘模式,可选 "text"/"upper"/"lower"/"numeric"
- auto_hide = true, -- 自动隐藏键盘
- bg_color = 0xf1f1f1, -- 键盘背景颜色为灰色,可选,不设置则透明
- on_commit = function() -- 确认事件回调,只有在按下确认键时才会触发
- log.info("keyboard", "commit")
- end
- })
- --------------------- 第一行控制区 ------------------------
- -- 当前lora信道标签
- airui.label({
- parent = scroll_container,
- text = "当前lora信道",
- x = 10,
- y = 12,
- w = 100,
- h = 30,
- font_size = 14,
- })
- -- 当前lora信道值
- local current_channel_label = airui.label({
- parent = scroll_container,
- text = "1",
- x = 110,
- y = 12,
- w = 30,
- h = 30,
- font_size = 14,
- })
- -- 设置lora信道标签
- airui.label({
- parent = scroll_container,
- text = "设置lora信道",
- x = 130,
- y = 12,
- w = 100,
- h = 30,
- font_size = 14,
- })
- -- 设置lora信道下拉框
- local channel_dropdown = airui.dropdown({
- parent = scroll_container,
- x = 230,
- y = 7,
- w = 80,
- h = 30,
- options = {"1", "2", "3", "4", "5", "6"},
- default_index = 0, -- 默认选择1
- on_change = function(self,idx)
- log.info("lora_channel", "选择了信道:" .. self.options[idx + 1])
- end
- })
- -- 开始监测按钮
- local start_btn = airui.button({
- parent = scroll_container,
- x = 320,
- y = 5,
- w = 80,
- h = 30,
- text = "开始监测",
- stype = { bg_color = 0x2B6FF1,border_color = 0x2B6FF1, text_color = 0xFFFFFF, radius = 8 },
- on_click = function(self)
- log.info("lora_monitor", "开始监测按钮被点击")
- end
- })
- -- 重置按钮
- local reset_btn = airui.button({
- parent = scroll_container,
- x = 405,
- y = 5,
- w = 60,
- h = 30,
- text = "重置",
- on_click = function(self)
- log.info("lora_monitor", "重置按钮被点击")
- end
- })
- ---------------------------------------------------
- --------------------- 第二行控制区 ------------------------
- -- 监测设备类型标签
- airui.label({
- parent = scroll_container,
- text = "监测设备类型",
- x = 10,
- y = 53,
- w = 100,
- h = 30,
- font_size = 14,
- })
- -- 监测设备类型下拉框
- local device_type_dropdown = airui.dropdown({
- parent = scroll_container,
- x = 110,
- y = 45,
- w = 100,
- h = 30,
- options = {"路由器", "连接器", "全部设备"},
- default_index = 0, -- 默认选择路由器
- on_change = function(self,idx)
- log.info("device_type", "选择了设备类型:" .. self.options[idx + 1])
- end
- })
- -- 连接器SN标签
- airui.label({
- parent = scroll_container,
- text = "连接器SN",
- x = 220,
- y = 53,
- w = 80,
- h = 30,
- font_size = 14,
- })
- -- 连接器SN输入框
- local sn_input = airui.textarea({
- parent = scroll_container,
- x = 290,
- y = 45,
- w = 80,
- h = 30,
- text = "",
- max_length = 5,
- keyboard = keyboard1
- })
- -- 上传服务器标签
- airui.label({
- parent = scroll_container,
- text = "上传",
- x = 380,
- y = 50,
- w = 60,
- h = 30,
- font_size = 14,
- })
- -- 上传服务器开关
- local upload_switch = airui.switch({
- parent = scroll_container,
- x = 415,
- y = 45,
- w = 50,
- h = 25,
- checked = true,
- on_change = function(self, checked)
- log.info("upload_switch", "上传服务器:" .. (checked and "开启" or "关闭"))
- end
- })
- ---------------------------------------------------
- --------------------- 表格区域 ------------------------
- -- 创建表格
- local lora_table = airui.table({
- parent = scroll_container,
- x = 0,
- y = 80,
- w = 480,
- h = 210,
- rows = 11, -- 10行数据 + 表头
- cols = 9,
- col_width = {70, 80, 90, 70, 70, 100, 100, 70, 150}, -- 调整列宽以适应内容
- border_color = 0xFFE082,
- })
- -- 设置表头
- local headers = {"序号", "发送方", "连接器SN", "信号", "版本", "一级类型", "二级类型", "数据", "时间"}
- for i, header in ipairs(headers) do
- lora_table:set_cell_text(0, i-1, header)
- end
- -- 示例数据
- local lora_data = {
- {"1", "设备1", "12345", "-65", "v1.0", "路由器", "A型", "00 01 02", "2024/07/02 09:30:46"},
- {"2", "设备2", "67890", "-70", "v1.1", "连接器", "B型", "03 04 05", "2024/07/02 09:31:00"},
- {"3", "设备3", "54321", "-60", "v1.0", "路由器", "A型", "06 07 08", "2024/07/02 09:32:15"},
- {"4", "设备4", "09876", "-75", "v1.1", "连接器", "C型", "09 0A 0B", "2024/07/02 09:33:30"},
- {"5", "设备5", "13579", "-68", "v1.0", "路由器", "B型", "0C 0D 0E", "2024/07/02 09:34:45"},
- {"6", "设备6", "24680", "-72", "v1.1", "连接器", "A型", "0F 10 11", "2024/07/02 09:35:00"},
- {"7", "设备7", "97531", "-63", "v1.0", "路由器", "C型", "12 13 14", "2024/07/02 09:36:15"},
- {"8", "设备8", "86420", "-69", "v1.1", "连接器", "B型", "15 16 17", "2024/07/02 09:37:30"},
- {"9", "设备9", "12457", "-66", "v1.0", "路由器", "A型", "18 19 1A", "2024/07/02 09:38:45"},
- {"10", "设备10", "36925", "-71", "v1.1", "连接器", "C型", "1B 1C 1D", "2024/07/02 09:39:00"},
- }
- -- 填充表格数据
- for i, data in ipairs(lora_data) do
- for j, value in ipairs(data) do
- lora_table:set_cell_text(i, j-1, value)
- end
- end
- ---------------------------------------------------
- -- 底部信息
- --common_ui.create_status_bar(main_container)
- end
- -- 初始化页面
- function tsb_lora_page.init(params)
- tsb_lora_page.create_ui()
- end
- -- 清理页面
- function tsb_lora_page.cleanup()
- -- 停止定时器
- common_ui.cleanup()
- if main_container then
- main_container:destroy()
- main_container = nil
- end
- end
- return tsb_lora_page
|