广州大彩串口屏论坛_大彩开发者交流论坛

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 7538|回复: 4

大神帮忙注解一下吧!我就想让屏上有个类似手机WIFI的图标

[复制链接]

30

主题

71

帖子

654

积分

高级会员

Rank: 4

积分
654
发表于 2020-7-3 22:35:02 | 显示全部楼层 |阅读模式
-下面列出了常用的回调函数
--更多功能请阅读<<物联型LUA脚本API.pdf>>
local cjson = require "cjson"
local sc_home       = 0
local sc_wifiset    = 1
local sc_scanwifi   = 2
local sc_wificonnet = 3
local sc_dhcpset    = 4
local sc_test       = 5

local select_ssid = ""
local select_psw  = ""
local down_test_testinfo  = ""
local down_test_task_id_1 = 1
local down_test_task_id_2 = 2
local public_net_task_id_1 = 1000
local down_test_url_1     = 'http://video.gz-dc.com/59a4d2393ff77.jpg'
local down_test_url_2     = 'http://video.gz-dc.com/qj7118866528.jpg'
local public_net_url      = 'http://pv.sohu.com/cityjson?ie=utf-8'
local server_url = "http://106.12.59.66/api/qrcode/index"  
local surface  = 0
local down_dir = "b:/"
function my_test_network()

local show_x = 30
local show_y = 118
local show_w = 420
local show_h = 40
local font_size  = 6
local draw_text_color = 0xF800
local align_mode = (0x01 << 2) | (0x00)

local draw_pic_x = 30
local draw_pic_y = 168
local draw_pic_w = 420
local draw_pic_h = 300

draw_text(down_test_testinfo, show_x,  show_y, show_w , show_h, font_size, draw_text_color, align_mode)
draw_surface(surface, draw_pic_x, draw_pic_y, draw_pic_w, draw_pic_h)
end
--扫描wifi与显示
function scan_ap_fill_list()
local ap_cnt = scan_ap()
for i = 1, ap_cnt
do
  local ssid, security, quality = get_ap_info(i - 1)
  record_add(sc_scanwifi, 1, ssid..";"..quality..";")
end
end
--初始化函数
function on_init()
set_text(sc_wifiset, 2, "--")
set_text(sc_wifiset, 5, "xxx.xxx.xxx.xxx")
set_text(sc_wifiset, 7, "xxxxxxxxxxxx")
end
function on_systick()
    local wifi_connect = get_network_state()
local wifimode, secumode, ssid, password  = get_wifi_cfg()
local dhcp, ipaddr, netmask, gateway, dns = get_network_cfg()

set_text(sc_wifiset, 7, get_wifi_mac())

local text_secumode = ""

if string.len(ssid) > 0
then
      if wifi_connect ~= 0
   then
  
  if secumode == 0
  then
   text_secumode = "(WEP)"
  elseif secumode == 1
  then
   text_secumode = "(WPA-PSK/WPA2-PSK)"
  elseif secumode == 2
  then
   text_secumode = "(WPA/WPA2)"
  end
  set_text(sc_wifiset, 2, ssid .. text_secumode)
  set_text(sc_wifiset, 5, ipaddr)
  
  set_text(sc_home, 4, ssid .. text_secumode)
  
  set_visiable(sc_home, 2, 0)
  set_visiable(sc_home, 3, 1)
  
  set_text(sc_dhcpset, 4, ipaddr)
  
      else   
  set_text(sc_wifiset, 2, "连接“" .. ssid .. "”中...")
  set_text(sc_wifiset, 5, "xxx.xxx.xxx.xxx")
  set_text(sc_home, 4, "连接“" .. ssid .. "”中...")
  set_visiable(sc_home, 2, 1)
  set_visiable(sc_home, 3, 0)
  
  
  set_text(sc_dhcpset, 4, "xxx.xxx.xxx.xxx")
   end

    else
  set_text(sc_wifiset, 2, '未连接')
  set_text(sc_wifiset, 5, "xxx.xxx.xxx.xxx")
  set_text(sc_home, 4, '未连接')
  set_visiable(sc_home, 2, 1)
  set_visiable(sc_home, 3, 0)
  
  
  set_text(sc_dhcpset, 4, "xxx.xxx.xxx.xxx")
end  
end
--用户通过触摸修改控件后,执行此回调函数。
--点击按钮控件,修改文本控件、修改滑动条都会触发此事件。
function on_control_notify(screen,control,value)

if screen == sc_wifiset
then
  if control == 3 and value == 1
  then
   record_clear(sc_scanwifi, 1)
   scan_ap_fill_list()
  end
elseif screen == sc_scanwifi
then
  if control == 1
  then
   
   local token = 0x3B
   local get_wifi_info = record_read(sc_scanwifi, control, value)
   
   local path_len = string.len(get_wifi_info)
   for char_index = 1, path_len
   do
    if  token == tonumber(string.byte(get_wifi_info, char_index, char_index))
    then
     select_ssid = string.sub(get_wifi_info, 1, (char_index - 1))
     set_text(sc_wificonnet, 3, "请输入“"..select_ssid.."”的密码")
     set_text(sc_wificonnet, 4, "")
     break;
    end
   end
   
   change_child_screen(sc_wificonnet)
   
  elseif control == 2 and value == 1
  then
   record_clear(sc_scanwifi, 1)
   scan_ap_fill_list()
  end


elseif screen == sc_wificonnet
then
  if control == 2
  then
   select_psw = get_text(sc_wificonnet, 4)
   set_wifi_cfg(1, 0, select_ssid, select_psw)
   save_network_cfg()                                                     --保存网络配置                  
   change_screen(sc_wifiset)
  end
elseif screen == sc_dhcpset
then                                                      
  if control == 2
  then
   local dhcp, ipaddr, netmask, gateway, dns = get_network_cfg()
   if value == 1     
   then
    set_text(sc_dhcpset, 4, ipaddr)  
    set_visiable(sc_dhcpset, 5, 1)
   
    set_network_cfg(1, ipaddr, netmask, gateway, dns)
    save_network_cfg()
   else
    set_text(sc_dhcpset, 4, "xxx.xxx.xxx.xxx")
    set_text(sc_wifiset, 5, "xxx.xxx.xxx.xxx")
    set_visiable(sc_dhcpset, 5, 0)  
   end
   
  elseif control == 5
  then
   return 1
  
  elseif control == 14  and value == 1                                        -- 保存配置                                    
  then
   local dhcp    = 0
   local ipaddr  = get_text(sc_dhcpset, 7)
   local netmask = get_text(sc_dhcpset, 9)
   local gateway = get_text(sc_dhcpset, 11)
   local dns     = get_text(sc_dhcpset, 13)
   
   set_network_cfg(dhcp, ipaddr, netmask, gateway, dns)
   save_network_cfg()
  end

elseif screen == sc_test
then
  if control == 1 and value == 1
  then
   http_download(down_test_task_id_1, down_test_url_1, down_dir.."down1.jpg")
   down_test_testinfo = "Http download1, waiting!!!"
   if surface ~= 0
   then
    destroy_surface(surface)
    surface = 0
   end
  elseif control == 2 and value == 1
  then
   http_download(down_test_task_id_2, down_test_url_2, down_dir.."down2.jpg")
   down_test_testinfo = "Http download2, waiting!!!"
    if surface ~= 0 then
       destroy_surface(surface)
    surface = 0
   end
   
  elseif control == 3 and value == 0
  then
   public_net_url = server_url.."?qid="..read_flash_string(200)..'&time='..os.time()
   http_request(public_net_task_id_1, public_net_url, 0)
   
   set_text(sc_test,  4, 'waitting ...')
   set_text(sc_test, 10, 'waitting ...')
  end
end
end
function on_http_download (taskid, status)
if taskid == down_test_task_id_1
then
  if status == 0
  then
   down_test_testinfo = "Download1 Msg:download failed !!!"
  elseif status == 1
  then
   down_test_testinfo = "Download1 Msg:download success, but save error !!!"
  elseif status == 2
  then
   down_test_testinfo = "Download1 Msg:download and save success"
   surface = load_surface(down_dir.."down1.jpg")
   redraw()
  end
elseif taskid == down_test_task_id_2
then
  if status == 0
  then
   down_test_testinfo = "Download2 Msg:download failed !!!"
  elseif status == 1
  then
   down_test_testinfo = "Download2 Msg:download success, but save error !!!"
  elseif status == 2
  then
   down_test_testinfo = "Download2 Msg:download and save success"
   surface = load_surface(down_dir.."down2.jpg")
   redraw()
  end
end
end
function on_http_response(taskid,response)

print("response ->"..response)
if public_net_task_id_1 == taskid and response ~= ""
then
  --[[local data_s =  string.find(response, "{", 1)
  local data_e =  string.find(response, "}", 1)
  local CityIpTb = cjson.decode(string.sub(response, data_s, data_e))
  
  print("cip ->"..CityIpTb['cip'])
  print("cname ->"..CityIpTb['cname'])
  
  local ip   = CityIpTb['cip']
  local city = CityIpTb['cname']
  set_text(sc_test, 4, city)
  set_text(sc_test, 10, ip)--]]
  set_text(sc_test,12,response)
  local response = cjson.decode(response) --解析JSON数据
  set_text(sc_test,11,response['data']['qrcode']..'&time='..os.time())
  
end
--返回-1时,响应数据会通过串口发送给用户MCU
--return -1
end
function on_draw(screen)
if screen == sc_test
then
  my_test_network()
end
end
function on_sd_inserted(dir)
down_dir = dir
end
function on_sd_removed()
down_dir = "b:/"
end
回复

使用道具 举报

30

主题

71

帖子

654

积分

高级会员

Rank: 4

积分
654
 楼主| 发表于 2020-7-3 22:38:21 | 显示全部楼层
版主。上传文件能不能调的大一些!传不上啊!
回复

使用道具 举报

0

主题

207

帖子

6873

积分

论坛元老

Rank: 8Rank: 8

积分
6873
发表于 2020-7-6 08:28:21 | 显示全部楼层
wifi图标参考图标教程,根据wifi状态指定显示第几帧图标显示http://www.gz-dc.com/uploads/fil ... %8E%A7%E4%BB%B6.rar
VisualHMI 人机界面 & VisualTFT 串口屏
回复

使用道具 举报

30

主题

71

帖子

654

积分

高级会员

Rank: 4

积分
654
 楼主| 发表于 2020-7-9 21:08:49 | 显示全部楼层
Cp`sir 发表于 2020-7-6 08:28
wifi图标参考图标教程,根据wifi状态指定显示第几帧图标显示http://www.gz-dc.com/uploads/file/%E6%95%99% ...

怎么把信号的强弱绑定到图标控件!LUA不知道哪一段是信号强弱的地方
回复

使用道具 举报

0

主题

207

帖子

6873

积分

论坛元老

Rank: 8Rank: 8

积分
6873
发表于 2020-7-23 09:04:20 | 显示全部楼层
天下为王 发表于 2020-7-9 21:08
怎么把信号的强弱绑定到图标控件!LUA不知道哪一段是信号强弱的地方

1.脚本如何绑定,请调用get_ap_info(index)检索wifi信息的时候, 将信息存在数组里面
2.当选择相应WIFI名称的时候,根据前面变量检索出来保存的WIFI名称去找到对应的信号值。
3.假设做的图标控件是4帧,信号值为0-显示第一帧无信号,1-33显示第二帧信号,34-66显示第3帧,67-100显示第4帧满格
VisualHMI 人机界面 & VisualTFT 串口屏
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|小黑屋|广州大彩串口屏论坛_大彩开发者交流论坛

GMT+8, 2024-4-30 13:25 , Processed in 0.051862 second(s), 18 queries .

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表