--[[**********************
--功能: 发送键盘输入的内容
--调用函数1: uart_send_data(packet)
--函数功能: 通过串口发送数据
--参数: packet 数据,类型:表
--调用函数2: get_text(screen,control)
--函数功能: 获取控件字符串内容(字符串)
--参数: screen: 被触发控件的页码
-- control: 控件的编号
--返回: 字符串
--调用函数3: string.len(arg)
--函数功能: 计算字符串长度
--参数: arg: 字符串
--返回: 整数值
--调用函数4: string.byte(arg[,int])
--函数功能: 转换字符为整数值(可以指定某个字符,默认第一个字符)
--参数: arg: 字符串
-- [,int]: 索引
--返回: 整数值
--********************--]]
local send_table2={}
local send_table3={}
if screen==0 and control==5
then
send_table2={} --表2初始化
send_table3={} --表3初始化
send_table2[0]=0xA1 --设置指令头,0xA1
send_table2[1]=0x05 --设置键盘指令
send_table3=get_value(0,5) --获取文本的内容
for i=1,4 do
send_table2[i+1]=send_table3
end
send_table2[6]=0x1A --设置指令未,0x1A
uart_send_data(send_table2) --发送指令
end
1.创建一个配置表 key对应的是table3的数据 值是table2每个索引需要自动赋值的数据
local tmp_tbl = {
[06] = {nil, 00, 00, 00, 06},
[07] = {nil, 00, 00, 00, 07},
.....
}
2.根据table3的数据如06在映射表找到对应数据 赋值给table2
local k = 06
if tmp_tbl[key] then
for i = 1, 4 do
table[i+1] = tmp_tbl[key][i+1]
end
end