| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724 |
- --- 模块功能 HMI
- -- @module
- -- @author lcg
- -- @license MIT
- -- @copyright yf
- -- @release 2019.08.01
- require 'ril'
- require "misc"
- require "AM2320"
- require "audio"
- module(..., package.seeall)
- local uart_id
- local hmi_task
- HMI_FILE = "/hmi.info"
- -- {
- -- "cmd": "paramconf",
- -- "ext": {
- -- "wind_sw": 0,
- -- "coll_time": ["7-9", "10-11"],
- -- "set_temp": 25,
- -- "imgres": 0,
- -- "datt": 0,
- -- "drop_time": 0,
- -- "cul_time": 24
- -- }
- -- }
- hmiconf = {
- passWord = 8888, --设置初始化密码
- thsp = 300, --默认熄屏时间5分钟
- vol = 7, -- 默认音量
- datt = 20, -- 数据上传时间间隔 分钟
- wind_sw = 0,
- on_off = 1,-- 设备开关:注意:1为开;0为关
- -- coll_time = '["9-10","14-15"]',
- -- coll_time = '[ " 6- 7", "8 - 10","12 -15","1 6 -2 0","21 -2 1"]',
- -- coll_time = '[ "8 - 10", "1 6 -2 0"," 6- 7", "12 -15","21 -2 1"]',
- -- coll_time = '[ "8 - 8", "1 6 -2 0"," 6- 7", "12 -15","21 -2 1","9 - 10"]',
- -- coll_time = '[ "8 - 8"," 6- 7", "12 -15","9 - 10"]',
- -- coll_time = ["7-9","10-11"],
- -- coll_time = {"8 - 8"," 6- 7", "12 -15","9 - 10"},
- -- coll_time = {"8 - 9"," 4- 5", "14 -19","10 - 11"},
- -- coll_time = {"8 - 9"," 4- 5", "14 -20","10 - 11"},
- -- coll_time = {"8-9","4-5","10-20"},
- coll_time = {"8-10","14-16"},
- cold_sw = 0,--制冷开关
- set_temp = 25, -- 保温仓设定温度
- imgres = 0,-- 分辨率
- drop_time = 1,-- 滴液秒数/10
- cul_time = 1, -- 设定培养时间
- }
- hmista = {
- work_sta = 0,-- 工作状态:0待机;1收集;2培养;3拍照;
- collect_fan = 0,--收集风扇:0停;1转
- cool_fan = 0,--散热风机:0停;1转
- heat_sta = 0,--加热状态:0停止;1加热
- cold_sta = 0,--制冷状态:0停止;1加热
- -- 机器内部温度:
- box_tem = 25,
- -- 环境温湿度:
- envTem = 25, -- 环境温度
- envHum = 30, -- 环境湿度
- heatTem = 25, --保温仓实时温度
- vbat = "",--电池电压
- bat_sta = 0,--电池低压保护状态
- staytime = 0,--已经培养的时间(小时)
- pre_temp = 30,-- 保温仓当前温度
- usb_sta = 0,--相机状态
- imgres = 0,--分辨率
- wind_sw = 0,--风机状态
- at = 0,--温度
- ah = 0,--湿度
- rainStatus = 0,--雨控
- stm8_v = '',--stm8代码版本
- }
- local function read_line()
- while true do
- local s = uart.read(uart_id, '*l')
- if s ~= '' then return s end
- coroutine.yield()
- end
- end
- function write(s)
- uart.write(uart_id, s .. string.fromhex("FFFFFF"))
- end
- local function on_wait_event_timeout()
- coroutine.resume(hmi_task, 'TIEMOUT')
- end
- local function wait_event(event, timeout)
- if timeout then
- sys.timer_start(on_wait_event_timeout, timeout)
- end
-
- while true do
- local receive_event = coroutine.yield()
- if receive_event == event then
- sys.timer_stop(on_wait_event_timeout)
- return
- elseif receive_event == 'TIMEOUT' then
- write('WAIT EVENT ' .. event .. 'TIMEOUT\r\n')
- return
- end
- end
- end
- local function main_loop()
- local cache_data = ''
- local wait_event_flag
-
- while true do
- -- 读取输入
- local new_data = read_line('*l')
- -- 输出回显
- -- write(new_data)
- -- 拼接之前未成行的剩余数据
- cache_data = cache_data .. new_data
- -- 去掉回车换行
- local line = cache_data:match('(.+)\r\n')
- if line then
- -- 收到一整行的数据 清除缓冲数据
- cache_data = ''
- -- 用xpcall执行用户输入的脚本,可以捕捉脚本的错误
- xpcall(function()
- if line == 'button' then
- audio.play('/ldata/button.mp3')
- elseif line == 'cancel' then
- audio.play("/ldata/button.mp3")
- elseif line == 'getFullData' then
- getFullData()
- elseif line:find("saveClockSet") then
- saveClockSet(line:match("=(.+)"))
- elseif line:find("saveUploadSet") then
- saveUploadSet(line:match("=(.+)"))
- elseif line:find('saveSystemSet') then
- saveSystemSet(line:match("=(.+)"))
- elseif line == "turn" then
- turn()
- elseif line == "turn_init" then
- turn_init()
- elseif line:find("putTest") then
- putTest(line:match("%.(.+)=(.+)"))
- elseif line:find("resetDefault") then
- resetDefault()
- end
- end, function()log.info(debug.traceback()) end)
- if wait_event_flag then
- wait_event(wait_event_flag, 3000)
- wait_event_flag = nil
- end
- end
- end
- end
- --- console.setup
- -- @param id 串口id
- -- @param baudrate 串口波特率
- -- @return 无
- -- @usage console.setup(1, 115200)
- function setup(id, baudrate)
- -- 默认串口1
- uart_id = id or 1
- -- 默认波特率115200
- baudrate = baudrate or 115200
- -- 创建console处理的协程
- hmi_task = coroutine.create(main_loop)
- -- 初始化串口
- uart.setup(uart_id, baudrate, 8, uart.PAR_NONE, uart.STOP_1)
- -- 串口收到数据时唤醒console协程
- uart.on(uart_id, 'receive', function()coroutine.resume(hmi_task) end)
- coroutine.resume(hmi_task)
- end
- function getFullData()
- -- workstatus page
- local c = misc.getClock()
- local date = string.format('"%00004d-%02d-%02d %02d:%02d:%02d"', c.year, c.month, c.day, c.hour, c.min, c.sec)
- -- 注意:防止imei的后八位的前几位连续位0:要进行8位格式化:
- write("workSta.equipid.txt=" .. string.format('"%06d"',string.sub(misc.getimei(), -6, -1)))
- write("workSta.rtc.txt=" .. date)
- write("workSta.csq.txt=" .. string.format('"%02d"',net.getRssi()))-- 信号强度)
- write("workSta.vbat.txt=" .. hmista.vbat)
- write("workSta.bat_sta.val=" .. hmista.bat_sta)
- write("workSta.on_off.val=" .. hmiconf.on_off)
- write("workSta.work_sta.val=" .. hmista.work_sta)
- write("workSta.collect_fan.val=" .. hmista.collect_fan)
- write("workSta.cool_fan.val=" .. hmista.cool_fan)
- write("workSta.box_tmp.txt=" .. hmista.box_tem)
- write("workSta.env_tem.val=" .. (hmista.envTem + 5) / 10)
- write("workSta.env_hum.val=" .. (hmista.envHum + 5) / 10)
-
- write("workSta.heat_sta.val=" .. hmista.heat_sta)
- write("workSta.cold_sw.val=" .. hmiconf.cold_sw)
- write("workSta.cold_sta.val=" .. hmista.cold_sta)
- write("workSta.set_temp.val=" .. hmiconf.set_temp)
- write("workSta.pre_temp.val=" .. hmista.pre_temp)
- write("workSta.cul_time.val=" .. hmiconf.cul_time)
- write("workSta.staytime.val=" .. hmista.staytime)
-
- -- 温湿度 page
- write("temHum.box_tmp.txt=" .. hmista.box_tem)
- -- write("temHum.box_hum.val=" .. (hmista.box_hum + 5) / 10)
- write("temHum.env_tem.val=" .. (hmista.envTem + 5) / 10)
- write("temHum.env_hum.val=" .. (hmista.envHum + 5) / 10)
- write("temHum.cool_fan.val=" .. hmista.cool_fan)
- -- timer page
-
- -- local table_tim1 = control.lua_string_split(hmiconf.coll_time[1], "-")
- -- local table_tim2 = control.lua_string_split(hmiconf.coll_time[2], "-")
- local table_tim1 = control.lua_string_split(string.gsub(hmiconf.coll_time[1], '[ "]', ''), "-")
- local table_tim2 = control.lua_string_split(string.gsub(hmiconf.coll_time[2], '[ "]', ''), "-")
- -- log.info("clockSet.start1.val=" .. table_tim1[1])
- -- log.info("clockSet.end1.val=" .. table_tim1[2])
- -- log.info("clockSet.start2.val=" .. table_tim2[1])
- -- log.info("clockSet.end2.val=" .. table_tim2[2])
- write("clockSet.start1.val=" .. table_tim1[1])
- write("clockSet.end1.val=" .. table_tim1[2])
- write("clockSet.start2.val=" .. table_tim2[1])
- write("clockSet.end2.val=" .. table_tim2[2])
- write("clockSet.drop.val=" .. hmiconf.drop_time)
- write("clockSet.stay.val=" .. hmiconf.cul_time)
-
- -- -- upload page
- -- write("uploadSet.imgres.val=" .. hmiconf.imgres)
- -- write("uploadSet.imgupl.val=" .. hmiconf.imgupl)
- -- write("uploadSet.datt.val=" .. hmiconf.datt)
- -- system page
- -- write("sysSet.thsp=" .. hmiconf.thsp)
- write("sysSet.vol.val=" .. hmiconf.vol or 7)
- write("sysSet.keep.val=" .. hmiconf.set_temp)
- write("sysSet.cold_sw.val=" .. hmiconf.cold_sw)
- write("sysSet.datt.val=" .. hmiconf.datt)
- -- log.info("sysSet.keep.val=" .. hmiconf.set_temp)
- -- log.info("sysSet.datt.val=" .. hmiconf.datt)
- -- -- password page
- -- write("inputPasswd.pwdData.txt=" .. hmiconf.passWord)
- end
- -- 定时模式设置保存
- function saveClockSet(dat)
- local idx,coll_time = 1,{}
- local start1,end1,start2,end2
- idx, start1 = pack.unpack(dat, "<I", idx)
- idx, end1 = pack.unpack(dat, "<I", idx)
- idx, start2 = pack.unpack(dat, "<I", idx)
- idx, end2 = pack.unpack(dat, "<I", idx)
- table.insert(coll_time,start1 .. '-' .. end1)
- table.insert(coll_time,start2 .. '-' .. end2)
- log.info("00000000000000000",coll_time[1],coll_time[2])
- hmiconf.coll_time = coll_time
- idx, hmiconf.drop_time = pack.unpack(dat, "<I", idx)
- idx, hmiconf.cul_time = pack.unpack(dat, "<I", idx)
- local str = json.encode(hmiconf)
- io.writefile(HMI_FILE, str)
- log.info("saveClockSet data value: ", str)
- audio.play('/ldata/save.mp3')
- end
- function saveUploadSet(dat)
- local idx = 1
- idx, hmiconf.datt = pack.unpack(dat, "<I", idx)
- local str = json.encode(hmiconf)
- io.writefile(HMI_FILE, str)
- log.info("saveUploadSet data value: ", str)
- audio.play('/ldata/save.mp3')
- end
- function saveSystemSet(dat)
- local idx = 1
- idx, hmiconf.cold_sw = pack.unpack(dat, "<I", idx)
- idx, hmiconf.vol = pack.unpack(dat, "<I", idx)
- idx, hmiconf.set_temp = pack.unpack(dat, "<I", idx)
- idx, hmiconf.datt = pack.unpack(dat, "<I", idx)
- idx, hmiconf.thsp = pack.unpack(dat, "<I", idx)
- local str = json.encode(hmiconf)
- io.writefile(HMI_FILE, str)
- log.info("saveSystemSet data value: ", str)
- audio.setVolume(hmiconf.vol)
- audio.play('/ldata/save.mp3')
- end
- -- 转盘转动
- function turn()
- log.info("~~~~~~~~~~turn",dat)
- -- sys.taskInit(control.turn(1,5))
- sys.taskInit(control.turn)
- end
- -- 转盘复位
- function turn_init()
- log.info("~~~~~~~~~~turn_init",dat)
- sys.taskInit(control.turn_init)
- end
- -- 一键测试标志位;
- local auto_test_flag = 0
- -- 自动对焦拍照标志位;
- local auto_pic_flag = 0
- -- 测试模式
- function putTest(cmd, dat)
- -- 一键测试
- if cmd == "switchAutotest" then
- log.info("~~~~~~~~~~switchAutotest",dat)
-
- if dat == 1 or dat == '1' then
- if auto_test_flag == 1 then
- log.error("----- auto_test_flag = 1,auto_test is running!!!")
- return
- end
- sys.taskInit(function()
- -- 一键测试标志位置 1
- auto_test_flag = 1
- sys.wait(2000)
- -- write("sysTest.result.txt=" .. "一键测试正在启动...")
- -- write("sysTest.auto_flag.txt=" .. "auto1")
- write('sysTest.auto_flag.txt="auto1"')
- sys.wait(2000)
- -- 复位:
- write('sysTest.auto_flag.txt="turn0"')
- sys.wait(2000)
- control.turn_init()
- -- 转
- write('sysTest.auto_flag.txt="turn"')
- control.turn()
- -- 推杆电机:测试粘附:
- write('sysTest.auto_flag.txt="add_fsl"')
- control.add_fsl()
- sys.wait(10000)
- -- write("sysTest.result.txt=" .. "更换载玻片,转盘启动...")
- -- write("sysTest.auto_flag.txt=" .. "turn")
- write('sysTest.auto_flag.txt="turn"')
- control.turn()
- -- sys.wait(10000)
- -- write("sysTest.result.txt=" .. "正在开启采集风机...")
- -- write("sysTest.auto_flag.txt=" .. "collect1")
- write('sysTest.auto_flag.txt="collect1"')
- sys.wait(2000)
- control.collect_fan(1)
- sys.wait(5000)
- -- write("sysTest.result.txt=" .. "即将关闭采集风机...")
- -- write("sysTest.auto_flag.txt=" .. "collect0")
- write('sysTest.auto_flag.txt="collect0"')
- sys.wait(2000)
- control.collect_fan(0)
- -- write("sysTest.result.txt=" .. "正在开启散热风机...")
- -- write("sysTest.auto_flag.txt=" .. "cool1")
- write('sysTest.auto_flag.txt="cool1"')
- sys.wait(2000)
- control.cool(1)
- sys.wait(5000)
- -- write("sysTest.result.txt=" .. "即将关闭散热风机...")
- -- write("sysTest.auto_flag.txt=" .. "cool0")
- write('sysTest.auto_flag.txt="cool0"')
- sys.wait(2000)
- control.cool(0)
- -- 转
- write('sysTest.auto_flag.txt="turn"')
- control.turn()
- sys.wait(5000)
- -- write("sysTest.result.txt=" .. "正在开启滴液测试...")
- -- write("sysTest.auto_flag.txt=" .. "drop1")
- write('sysTest.auto_flag.txt="drop1"')
- sys.wait(2000)
- control.drop(1)
- sys.wait(5000)
- -- write("sysTest.result.txt=" .. "滴液测试结束...")
- -- write("sysTest.auto_flag.txt=" .. "drop0")
- write('sysTest.auto_flag.txt="drop0"')
- sys.wait(2000)
- -- write("sysTest.result.txt=" .. "正在启动加热...")
- -- write("sysTest.auto_flag.txt=" .. "heat1")
- write('sysTest.auto_flag.txt="heat1"')
- sys.wait(2000)
- control.heat(1)
- sys.wait(5000)
- -- write("sysTest.result.txt=" .. "加热测试完毕...")
- -- write("sysTest.auto_flag.txt=" .. "heat0")
- write('sysTest.auto_flag.txt="heat0"')
- sys.wait(2000)
- control.heat(0)
- -- write("sysTest.result.txt=" .. "正在启动制冷...")
- -- write("sysTest.auto_flag.txt=" .. "cold1")
- write('sysTest.auto_flag.txt="cold1"')
- sys.wait(2000)
- control.cold(1)
- sys.wait(5000)
- -- write("sysTest.result.txt=" .. "制冷测试完毕...")
- -- write("sysTest.auto_flag.txt=" .. "cold0")
- write('sysTest.auto_flag.txt="cold0"')
- sys.wait(2000)
- control.cold(0)
- -- 转
- write('sysTest.auto_flag.txt="turn"')
- control.turn()
- -- write("sysTest.result.txt=" .. "正在启动补光灯...")
- -- write("sysTest.auto_flag.txt=" .. "led1")
- write('sysTest.auto_flag.txt="led1"')
- sys.wait(2000)
- haikang.light_led(1)
- sys.wait(2000)
- -- write("sysTest.result.txt=" .. "步进电机上行...")
- -- write("sysTest.auto_flag.txt=" .. "up1")
- write('sysTest.auto_flag.txt="up1"')
- haikang.motor_reset()
- sys.wait(2000)
- -- write("sysTest.result.txt=" .. "步进电机下行...")
- -- write("sysTest.auto_flag.txt=" .. "down1")
- write('sysTest.auto_flag.txt="down1"')
- haikang.motor_down()
- -- write("sysTest.result.txt=" .. "正在拍照...")
- -- write("sysTest.auto_flag.txt=" .. "photo1")
- write('sysTest.auto_flag.txt="photo1"')
- sys.wait(2000)
- audio.play('/ldata/takephoto.mp3')
- haikang.hk_takephoto()
- sys.wait(5000)
- -- write("sysTest.result.txt=" .. "拍照完毕...")
- -- write("sysTest.auto_flag.txt=" .. "photo0")
- write('sysTest.auto_flag.txt="photo0"')
- sys.wait(3000)
- -- write("sysTest.result.txt=" .. "即将关闭补光灯...")
- -- write("sysTest.auto_flag.txt=" .. "led0")
- write('sysTest.auto_flag.txt="led0"')
- haikang.light_led(0)
- -- haikang.photo_flag = 1
- haikang.http_chose_photo_task()
- sys.wait(2000)
- -- write("sysTest.result.txt=" .. "一键测试结束...")
- -- write("sysTest.auto_flag.txt=" .. "auto0")
- -- 转一次:表一键测试结束;
- -- control.turn_init()
- -- write('sysTest.auto_flag.txt="turn"')
- -- control.turn()
- -- 复位:
- write('sysTest.auto_flag.txt="turn0"')
- sys.wait(2000)
- control.turn_init()
- write('sysTest.auto_flag.txt="auto0"')
- write('sysTest.switchAutotest.val=0')
- -- 一键测试标志位清零
- auto_test_flag = 0
- end)
- end
-
- -- 采集风机测试:
- elseif cmd == "switchCollect" then
- log.info("~~~~~~~~~~switchCollect",dat)
- sys.taskInit(function()
- log.info('<----- switchCollect! ----->')
- control.collect_fan(1)
- sys.wait(10000)
- control.collect_fan(0)
- write("sysTest.switchCollect.val=0")
- write('sysTest.auto_flag.txt="collect0"')
- end)
- -- 散热风机测试:
- elseif cmd == "switchCool" then
- log.info("~~~~~~~~~~switchCool",dat)
- sys.taskInit(function()
- log.info('<----- switchCool! ----->')
- control.cool(1)
- -- hmi.hmista.cool_fan = 1
- -- log.warn("hmi.hmista.cool_fan:",hmi.hmista.cool_fan)
- sys.wait(10000)
- control.cool(0)
- write("sysTest.switchCool.val=0")
- write('sysTest.auto_flag.txt="cool0"')
- -- hmi.hmista.cool_fan = 0
- -- log.warn("hmi.hmista.cool_fan:",hmi.hmista.cool_fan)
- -- write("sysTest.switchCool.val=0")
- -- write("temHum.cool_fan.val=0")
- end)
- --[[
- -- 步进电机脱机测试:
- elseif cmd == "switchMoff" then
- log.info("~~~~~~~~~~switchMoff",dat)
- -- 1为使能;非脱机;0为脱机;
- if dat == 0 or dat == '0' then
- if haikang.up_step == 1 or haikang.down_step == 1 then
- haikang.stop_step = 1
- end
- -- haikang.up_step = 0
- -- haikang.down_step = 0
- end
- haikang.motor_en(dat)
- -- control.ctrl_12v(dat)
- --]]
-
- -- 粘附电机测试:
- elseif cmd == "switchFsl" then
- log.info("~~~~~~~~~~switchFsl",dat)
- sys.taskInit(function()
- control.add_fsl(dat,5)
- sys.wait(10*1000)
- write('sysTest.switchFsl.val=0')
- end)
-
- -- 对焦拍照测试:
- elseif cmd == "switchAutopic" then
- log.info("~~~~~~~~~~switchAutopic",dat)
- if dat == 1 or dat == '1' then
- if auto_pic_flag == 1 then
- log.error("hmi auto_pic_flag = 1,auto_takepic is running!!!")
- return
- end
- sys.taskInit(function()
- -- 对焦拍照测试标志位置 1
- auto_pic_flag = 1
- log.info('<----- switchPic! ----->')
- -- haikang.hk_takephoto()
- audio.play('/ldata/takephoto.mp3')
- haikang.autotakepic2()
- -- 对焦拍照测试标志位 清零
- auto_pic_flag = 0
- write('sysTest.switchAutopic.val=0')
- write('sysTest.auto_flag.txt="auto_photo0"')
- end)
- end
- -- 立即拍照测试:
- elseif cmd == "switchPic" then
- log.info("~~~~~~~~~~switchPic",dat)
- if dat == 1 or dat == '1' then
- sys.taskInit(function()
- log.info('<----- switchPic! ----->')
- audio.play('/ldata/takephoto.mp3')
- -- haikang.hk_takephoto()
- haikang.test_takephoto()
- sys.wait(10000)
- -- haikang.photo_flag = 1
- haikang.http_chose_photo_task()
- write('sysTest.switchPic.val=0')
- write('sysTest.auto_flag.txt="photo0"')
- end)
- end
- -- 步进电机上行测试:
- elseif cmd == "switchUp" then
- log.info("~~~~~~~~~~switchUp",dat)
- if dat == 1 or dat == '1' then
- sys.taskInit(haikang.motor_reset)
- elseif dat == 0 or dat == '0' then
- -- if haikang.up_step == 1 or haikang.down_step == 1 then
- if haikang.up_step_flag == 1 then
- haikang.stop_step = 1
- end
- end
- -- 步进电机下行测试:
- elseif cmd == "switchDown" then
- log.info("~~~~~~~~~~switchDown",dat)
- if dat == 1 or dat == '1' then
- sys.taskInit(haikang.motor_down)
- elseif dat == 0 or dat == '0' then
- -- if haikang.up_step == 1 or haikang.down_step == 1 then
- if haikang.down_step_flag == 1 then
- haikang.stop_step = 1
- end
- end
- -- 滴液测试:
- elseif cmd == "switchDrop" then
- log.info("~~~~~~~~~~switchDrop",dat)
- if dat == 1 or dat == '1' then
- sys.taskInit(control.drop)
- -- sys.taskInit(function()
- -- print("----------drop time is ...",t)
- -- for i=1,3,1 do
- -- print("----------droping...",i)
- -- pins.setup(pio.P1_1,1)
- -- sys.wait(5000)
- -- pins.setup(pio.P1_1,0)
- -- sys.wait(5000)
- -- end
- -- write("sysTest.switchDrop.val=0")
- -- end)
- end
- -- 补光灯测试:
- elseif cmd == "switchLed" then
- log.info("~~~~~~~~~~switchLed",dat)
- haikang.light_led(dat)
- -- sys.taskInit(haikang.http_chose_photo)
- -- haikang.http_chose_photo_task()
- -- control.ctrl_12v(dat)
- -- 加热测试:
- elseif cmd == "switchHeat" then
- log.info("~~~~~~~~~~switchHeat",dat)
- if dat == 1 or dat == '1' then
- sys.taskInit(function()
- log.info('<----- switchHeat! ----->')
- control.heat(1)
- sys.wait(20000)
- control.heat(0)
- write("sysTest.switchHeat.val=0")
- write('sysTest.auto_flag.txt="heat0"')
- end)
- end
- -- 制冷测试:
- elseif cmd == "switchCold" then
- log.info("~~~~~~~~~~switchCold",dat)
- if dat == 1 or dat == '1' then
- sys.taskInit(function()
- log.info('<----- switchCold! ----->')
- control.cold(1)
- sys.wait(20000)
- control.cold(0)
- write("sysTest.switchCold.val=0")
- write('sysTest.auto_flag.txt="cold0"')
- end)
- end
- end
- end
- function resetDefault()
- audio.play('/ldata/save.mp3')
- -- 恢复参数为默认值
- hmiconf.passWord = 8888 --设置初始化密码
- hmiconf.thsp = 300 --默认熄屏时间5分钟
- hmiconf.vol = 7 -- 默认音量
- hmiconf.datt = 20 -- 数据上传时间间隔 分钟
- hmiconf.wind_sw = 0
- hmiconf.coll_time = {"8-10","14-16"}
- hmiconf.cold_sw = 0 --制冷开关
- hmiconf.set_temp = 25 -- 保温仓设定温度
- hmiconf.imgres = 0 -- 分辨率
- hmiconf.drop_time = 1 -- 滴液秒数
- hmiconf.cul_time = 1 -- 设定培养时间
- audio.setVolume(hmiconf.vol)
- -- 将参数保存
- local str = json.encode(hmiconf)
- io.writefile(HMI_FILE, str)
- log.info("resetDefault is Action!", str)
- end
- -- 保存参数到flash中
- sys.taskInit(function()
- local str = io.readfile(HMI_FILE)
- log.info("paramconf default value: ", str)
- if str then
- local cnf, result, err = json.decode(str)
- -- local str = json.encode(cnf)
- -- log.warn("read paramconf is:-----------------:",str)
- log.info("==========cnf",cnf)
- log.info("==========result",result)
- log.info("==========err",err)
- if result then hmiconf = cnf end
- log.info("==========hmi.hmiconf.wind_sw",hmi.hmiconf.wind_sw)
- log.info("==========hmi.hmiconf.coll_time",hmi.hmiconf.coll_time)
- log.info("==========hmi.hmiconf.set_temp",hmi.hmiconf.set_temp)
- log.info("==========hmi.hmiconf.imgres",hmi.hmiconf.imgres)
- log.info("==========hmi.hmiconf.datt",hmi.hmiconf.datt)
- log.info("==========hmi.hmiconf.drop_time",hmi.hmiconf.drop_time)
- log.info("==========hmi.hmiconf.cul_time",hmi.hmiconf.cul_time)
- end
- audio.setVolume(hmiconf.vol)
- -- audio.play_utf8_tts("欢迎使用物联网孢子捕捉仪")
- audio.play('/ldata/pwron.mp3')
- end)
- function remote_auto_pic()
- if auto_pic_flag == 1 then
- log.error("remote_auto_pic auto_pic_flag = 1,auto_takepic is running!!!")
- return
- end
- sys.taskInit(function()
- -- 对焦拍照测试标志位置 1
- auto_pic_flag = 1
- log.info('<----- switchPic! ----->')
- -- haikang.hk_takephoto()
- audio.play('/ldata/takephoto.mp3')
- haikang.autotakepic2()
- -- 对焦拍照测试标志位 清零
- auto_pic_flag = 0
- write('sysTest.switchAutopic.val=0')
- write('sysTest.auto_flag.txt="auto_photo0"')
- end)
- end
|