--[[ @module tsb_bmq_page @summary 编码器演示页面 @version 1.0 @date 2026.03.04 @author 李一玮 @usage 本文件是编码器演示页面,展示编码器的各种用法。 ]] local tsb_bmq_page = {} -- 页面UI元素 local main_container = nil local common_ui = require("tsb_common_page") -- 创建UI function tsb_bmq_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 = 0xFF9800, }) airui.label({ parent = title_bar, text = "编码器", x = 210, y = 8, w = 80, h = 20, font_size = 16, color = 0xFFFFFF, }) -- 标题栏公共信息展示 common_ui.add_battery_display(title_bar) common_ui.create_back_button(title_bar, tsb_bmq_page.cleanup) --------------------------------------------------- -- 滚动容器 local scroll_container = airui.container({ parent = main_container, x = 0, y = 30, w = 480, h = 270, color = 0xF5F5F5, }) 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 }) ------------------- 模拟编码器输入 ------------------ local bmq_input_container = airui.container({ parent = scroll_container, x = 10, y = 5, w = 200, h = 260, color = 0xFFFFFF, radius = 5, }) airui.label({ parent = bmq_input_container, text = "编码器信号输入", x = 35, y = 10, w = 140, h = 30, font_size = 18, }) airui.label({ parent = bmq_input_container, text = "实时电平:", x = 20, y = 80, w = 80, h = 30, font_size = 16, }) local label_cur_vol = airui.label({ parent = bmq_input_container, text = "高", x = 100, y = 80, w = 80, h = 30, font_size = 16, }) airui.label({ parent = bmq_input_container, text = "检测脉冲数:", x = 20, y = 140, w = 100, h = 30, font_size = 16, }) local label_pulse_count = airui.label({ parent = bmq_input_container, text = "12345", x = 120, y = 140, w = 70, h = 30, font_size = 16, }) local tax_serial_btn = airui.button({ parent = bmq_input_container, x = 65, y = 215, w = 80, h = 35, text = "清零", on_click = function(self) log.info("button", "基本按钮被点击") label_pulse_count:set_text("0") end }) ---------------------------------------------------- ------------------- 模拟编码器输出 ------------------ local bmq_output_container = airui.container({ parent = scroll_container, x = 220, y = 5, w = 250, h = 260, color = 0xFFFFFF, radius = 5, }) airui.label({ parent = bmq_output_container, text = "编码器信号输出", x = 60, y = 10, w = 140, h = 30, font_size = 18, }) -- 脉冲周期 airui.label({ parent = bmq_output_container, text = "脉冲周期:", x = 20, y = 50, w = 80, h = 30, font_size = 16, }) local cycle_input = airui.textarea({ parent = bmq_output_container, x = 100, y = 40, w = 60, h = 35, text = "5", max_len = 5, keyboard = keyboard1 }) airui.label({ parent = bmq_output_container, text = "ms", x = 165, y = 50, w = 30, h = 30, font_size = 16, }) -- 电压幅度 airui.label({ parent = bmq_output_container, text = "电压幅度:", x = 20, y = 90, w = 80, h = 30, font_size = 16, }) local voltage_input = airui.textarea({ parent = bmq_output_container, x = 100, y = 80, w = 60, h = 35, text = "5", max_len = 2, keyboard = keyboard1 }) airui.label({ parent = bmq_output_container, text = "V", x = 170, y = 90, w = 30, h = 30, font_size = 16, }) -- 当前电平 airui.label({ parent = bmq_output_container, text = "当前电平:", x = 20, y = 130, w = 80, h = 30, font_size = 16, }) local label_output_level = airui.label({ parent = bmq_output_container, text = "高", x = 100, y = 130, w = 80, h = 30, font_size = 16, }) -- 输出脉冲数 airui.label({ parent = bmq_output_container, text = "输出脉冲数:", x = 20, y = 170, w = 100, h = 30, font_size = 16, }) local label_output_pulse = airui.label({ parent = bmq_output_container, text = "0", x = 120, y = 170, w = 80, h = 30, font_size = 16, }) -- 按钮 local start_btn = airui.button({ parent = bmq_output_container, x = 40, y = 215, w = 80, h = 35, text = "开始", stype = { bg_color = 0x2B6FF1,border_color = 0x2B6FF1, text_color = 0xFFFFFF, radius = 8 }, on_click = function(self) log.info("button", "开始按钮被点击") end }) local clear_btn = airui.button({ parent = bmq_output_container, x = 130, y = 215, w = 80, h = 35, text = "清零", on_click = function(self) log.info("button", "清零按钮被点击") end }) ---------------------------------------------------- -- 底部信息 common_ui.create_status_bar(main_container) end -- 初始化页面 function tsb_bmq_page.init(params) tsb_bmq_page.create_ui() end -- 清理页面 function tsb_bmq_page.cleanup() if main_container then main_container:destroy() main_container = nil end end return tsb_bmq_page