hmi.lua 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725
  1. --- 模块功能 HMI
  2. -- @module
  3. -- @author lcg
  4. -- @license MIT
  5. -- @copyright yf
  6. -- @release 2019.08.01
  7. require 'ril'
  8. require "misc"
  9. require "AM2320"
  10. require "audio"
  11. require "ykm_rtu"
  12. module(..., package.seeall)
  13. local uart_id
  14. local hmi_task
  15. HMI_FILE = "/hmi.info"
  16. -- {
  17. -- "cmd": "paramconf",
  18. -- "ext": {
  19. -- "wind_sw": 0,
  20. -- "coll_time": ["7-9", "10-11"],
  21. -- "set_temp": 25,
  22. -- "imgres": 0,
  23. -- "datt": 0,
  24. -- "drop_time": 0,
  25. -- "cul_time": 24
  26. -- }
  27. -- }
  28. hmiconf = {
  29. passWord = 8888, --设置初始化密码
  30. thsp = 300, --默认熄屏时间5分钟
  31. vol = 7, -- 默认音量
  32. datt = 20, -- 数据上传时间间隔 分钟
  33. wind_sw = 0,
  34. on_off = 1,-- 设备开关:注意:1为开;0为关
  35. -- coll_time = '["9-10","14-15"]',
  36. -- coll_time = '[ " 6- 7", "8 - 10","12 -15","1 6 -2 0","21 -2 1"]',
  37. -- coll_time = '[ "8 - 10", "1 6 -2 0"," 6- 7", "12 -15","21 -2 1"]',
  38. -- coll_time = '[ "8 - 8", "1 6 -2 0"," 6- 7", "12 -15","21 -2 1","9 - 10"]',
  39. -- coll_time = '[ "8 - 8"," 6- 7", "12 -15","9 - 10"]',
  40. -- coll_time = ["7-9","10-11"],
  41. -- coll_time = {"8 - 8"," 6- 7", "12 -15","9 - 10"},
  42. -- coll_time = {"8 - 9"," 4- 5", "14 -19","10 - 11"},
  43. -- coll_time = {"8 - 9"," 4- 5", "14 -20","10 - 11"},
  44. -- coll_time = {"8-9","4-5","10-20"},
  45. coll_time = {"8-10","14-16"},
  46. cold_sw = 0,--制冷开关
  47. set_temp = 25, -- 保温仓设定温度
  48. imgres = 0,-- 分辨率
  49. drop_time = 1,-- 滴液秒数/10
  50. cul_time = 1, -- 设定培养时间
  51. }
  52. hmista = {
  53. work_sta = 0,-- 工作状态:0待机;1收集;2培养;3拍照;
  54. collect_fan = 0,--收集风扇:0停;1转
  55. cool_fan = 0,--散热风机:0停;1转
  56. heat_sta = 0,--加热状态:0停止;1加热
  57. cold_sta = 0,--制冷状态:0停止;1加热
  58. -- 机器内部温度:
  59. box_tem = 25,
  60. -- 环境温湿度:
  61. envTem = 25, -- 环境温度
  62. envHum = 30, -- 环境湿度
  63. heatTem = 25, --保温仓实时温度
  64. vbat = "",--电池电压
  65. bat_sta = 0,--电池低压保护状态
  66. staytime = 0,--已经培养的时间(小时)
  67. pre_temp = 30,-- 保温仓当前温度
  68. usb_sta = 0,--相机状态
  69. imgres = 0,--分辨率
  70. wind_sw = 0,--风机状态
  71. at = 0,--温度
  72. ah = 0,--湿度
  73. rainStatus = 0,--雨控
  74. stm8_v = '',--stm8代码版本
  75. }
  76. local function read_line()
  77. while true do
  78. local s = uart.read(uart_id, '*l')
  79. if s ~= '' then return s end
  80. coroutine.yield()
  81. end
  82. end
  83. function write(s)
  84. uart.write(uart_id, s .. string.fromhex("FFFFFF"))
  85. end
  86. local function on_wait_event_timeout()
  87. coroutine.resume(hmi_task, 'TIEMOUT')
  88. end
  89. local function wait_event(event, timeout)
  90. if timeout then
  91. sys.timer_start(on_wait_event_timeout, timeout)
  92. end
  93. while true do
  94. local receive_event = coroutine.yield()
  95. if receive_event == event then
  96. sys.timer_stop(on_wait_event_timeout)
  97. return
  98. elseif receive_event == 'TIMEOUT' then
  99. write('WAIT EVENT ' .. event .. 'TIMEOUT\r\n')
  100. return
  101. end
  102. end
  103. end
  104. local function main_loop()
  105. local cache_data = ''
  106. local wait_event_flag
  107. while true do
  108. -- 读取输入
  109. local new_data = read_line('*l')
  110. -- 输出回显
  111. -- write(new_data)
  112. -- 拼接之前未成行的剩余数据
  113. cache_data = cache_data .. new_data
  114. -- 去掉回车换行
  115. local line = cache_data:match('(.+)\r\n')
  116. if line then
  117. -- 收到一整行的数据 清除缓冲数据
  118. cache_data = ''
  119. -- 用xpcall执行用户输入的脚本,可以捕捉脚本的错误
  120. xpcall(function()
  121. if line == 'button' then
  122. audio.play('/ldata/button.mp3')
  123. elseif line == 'cancel' then
  124. audio.play("/ldata/button.mp3")
  125. elseif line == 'getFullData' then
  126. getFullData()
  127. elseif line:find("saveClockSet") then
  128. saveClockSet(line:match("=(.+)"))
  129. elseif line:find("saveUploadSet") then
  130. saveUploadSet(line:match("=(.+)"))
  131. elseif line:find('saveSystemSet') then
  132. saveSystemSet(line:match("=(.+)"))
  133. elseif line == "turn" then
  134. turn()
  135. elseif line == "turn_init" then
  136. turn_init()
  137. elseif line:find("putTest") then
  138. putTest(line:match("%.(.+)=(.+)"))
  139. elseif line:find("resetDefault") then
  140. resetDefault()
  141. end
  142. end, function()log.info(debug.traceback()) end)
  143. if wait_event_flag then
  144. wait_event(wait_event_flag, 3000)
  145. wait_event_flag = nil
  146. end
  147. end
  148. end
  149. end
  150. --- console.setup
  151. -- @param id 串口id
  152. -- @param baudrate 串口波特率
  153. -- @return 无
  154. -- @usage console.setup(1, 115200)
  155. function setup(id, baudrate)
  156. -- 默认串口1
  157. uart_id = id or 1
  158. -- 默认波特率115200
  159. baudrate = baudrate or 115200
  160. -- 创建console处理的协程
  161. hmi_task = coroutine.create(main_loop)
  162. -- 初始化串口
  163. uart.setup(uart_id, baudrate, 8, uart.PAR_NONE, uart.STOP_1)
  164. -- 串口收到数据时唤醒console协程
  165. uart.on(uart_id, 'receive', function()coroutine.resume(hmi_task) end)
  166. coroutine.resume(hmi_task)
  167. end
  168. function getFullData()
  169. -- workstatus page
  170. local c = misc.getClock()
  171. local date = string.format('"%00004d-%02d-%02d %02d:%02d:%02d"', c.year, c.month, c.day, c.hour, c.min, c.sec)
  172. -- 注意:防止imei的后八位的前几位连续位0:要进行8位格式化:
  173. write("workSta.equipid.txt=" .. string.format('"%06d"',string.sub(misc.getimei(), -6, -1)))
  174. write("workSta.rtc.txt=" .. date)
  175. write("workSta.csq.txt=" .. string.format('"%02d"',net.getRssi()))-- 信号强度)
  176. write("workSta.vbat.txt=" .. hmista.vbat)
  177. write("workSta.bat_sta.val=" .. hmista.bat_sta)
  178. write("workSta.on_off.val=" .. hmiconf.on_off)
  179. write("workSta.work_sta.val=" .. hmista.work_sta)
  180. write("workSta.collect_fan.val=" .. hmista.collect_fan)
  181. write("workSta.cool_fan.val=" .. hmista.cool_fan)
  182. write("workSta.box_tmp.txt=" .. hmista.box_tem)
  183. write("workSta.env_tem.val=" .. (hmista.envTem + 5) / 10)
  184. write("workSta.env_hum.val=" .. (hmista.envHum + 5) / 10)
  185. write("workSta.heat_sta.val=" .. hmista.heat_sta)
  186. write("workSta.cold_sw.val=" .. hmiconf.cold_sw)
  187. write("workSta.cold_sta.val=" .. hmista.cold_sta)
  188. write("workSta.set_temp.val=" .. hmiconf.set_temp)
  189. write("workSta.pre_temp.val=" .. hmista.pre_temp)
  190. write("workSta.cul_time.val=" .. hmiconf.cul_time)
  191. write("workSta.staytime.val=" .. hmista.staytime)
  192. -- 温湿度 page
  193. write("temHum.box_tmp.txt=" .. hmista.box_tem)
  194. -- write("temHum.box_hum.val=" .. (hmista.box_hum + 5) / 10)
  195. write("temHum.env_tem.val=" .. (hmista.envTem + 5) / 10)
  196. write("temHum.env_hum.val=" .. (hmista.envHum + 5) / 10)
  197. write("temHum.cool_fan.val=" .. hmista.cool_fan)
  198. -- timer page
  199. -- local table_tim1 = control.lua_string_split(hmiconf.coll_time[1], "-")
  200. -- local table_tim2 = control.lua_string_split(hmiconf.coll_time[2], "-")
  201. local table_tim1 = control.lua_string_split(string.gsub(hmiconf.coll_time[1], '[ "]', ''), "-")
  202. local table_tim2 = control.lua_string_split(string.gsub(hmiconf.coll_time[2], '[ "]', ''), "-")
  203. -- log.info("clockSet.start1.val=" .. table_tim1[1])
  204. -- log.info("clockSet.end1.val=" .. table_tim1[2])
  205. -- log.info("clockSet.start2.val=" .. table_tim2[1])
  206. -- log.info("clockSet.end2.val=" .. table_tim2[2])
  207. write("clockSet.start1.val=" .. table_tim1[1])
  208. write("clockSet.end1.val=" .. table_tim1[2])
  209. write("clockSet.start2.val=" .. table_tim2[1])
  210. write("clockSet.end2.val=" .. table_tim2[2])
  211. write("clockSet.drop.val=" .. hmiconf.drop_time)
  212. write("clockSet.stay.val=" .. hmiconf.cul_time)
  213. -- -- upload page
  214. -- write("uploadSet.imgres.val=" .. hmiconf.imgres)
  215. -- write("uploadSet.imgupl.val=" .. hmiconf.imgupl)
  216. -- write("uploadSet.datt.val=" .. hmiconf.datt)
  217. -- system page
  218. -- write("sysSet.thsp=" .. hmiconf.thsp)
  219. write("sysSet.vol.val=" .. hmiconf.vol or 7)
  220. write("sysSet.keep.val=" .. hmiconf.set_temp)
  221. write("sysSet.cold_sw.val=" .. hmiconf.cold_sw)
  222. write("sysSet.datt.val=" .. hmiconf.datt)
  223. -- log.info("sysSet.keep.val=" .. hmiconf.set_temp)
  224. -- log.info("sysSet.datt.val=" .. hmiconf.datt)
  225. -- -- password page
  226. -- write("inputPasswd.pwdData.txt=" .. hmiconf.passWord)
  227. end
  228. -- 定时模式设置保存
  229. function saveClockSet(dat)
  230. local idx,coll_time = 1,{}
  231. local start1,end1,start2,end2
  232. idx, start1 = pack.unpack(dat, "<I", idx)
  233. idx, end1 = pack.unpack(dat, "<I", idx)
  234. idx, start2 = pack.unpack(dat, "<I", idx)
  235. idx, end2 = pack.unpack(dat, "<I", idx)
  236. table.insert(coll_time,start1 .. '-' .. end1)
  237. table.insert(coll_time,start2 .. '-' .. end2)
  238. log.info("00000000000000000",coll_time[1],coll_time[2])
  239. hmiconf.coll_time = coll_time
  240. idx, hmiconf.drop_time = pack.unpack(dat, "<I", idx)
  241. idx, hmiconf.cul_time = pack.unpack(dat, "<I", idx)
  242. local str = json.encode(hmiconf)
  243. io.writefile(HMI_FILE, str)
  244. log.info("saveClockSet data value: ", str)
  245. audio.play('/ldata/save.mp3')
  246. end
  247. function saveUploadSet(dat)
  248. local idx = 1
  249. idx, hmiconf.datt = pack.unpack(dat, "<I", idx)
  250. local str = json.encode(hmiconf)
  251. io.writefile(HMI_FILE, str)
  252. log.info("saveUploadSet data value: ", str)
  253. audio.play('/ldata/save.mp3')
  254. end
  255. function saveSystemSet(dat)
  256. local idx = 1
  257. idx, hmiconf.cold_sw = pack.unpack(dat, "<I", idx)
  258. idx, hmiconf.vol = pack.unpack(dat, "<I", idx)
  259. idx, hmiconf.set_temp = pack.unpack(dat, "<I", idx)
  260. idx, hmiconf.datt = pack.unpack(dat, "<I", idx)
  261. idx, hmiconf.thsp = pack.unpack(dat, "<I", idx)
  262. local str = json.encode(hmiconf)
  263. io.writefile(HMI_FILE, str)
  264. log.info("saveSystemSet data value: ", str)
  265. audio.setVolume(hmiconf.vol)
  266. audio.play('/ldata/save.mp3')
  267. end
  268. -- 转盘转动
  269. function turn()
  270. log.info("~~~~~~~~~~turn",dat)
  271. -- sys.taskInit(control.turn(1,5))
  272. sys.taskInit(control.turn)
  273. end
  274. -- 转盘复位
  275. function turn_init()
  276. log.info("~~~~~~~~~~turn_init",dat)
  277. sys.taskInit(control.turn_init)
  278. end
  279. -- 一键测试标志位;
  280. local auto_test_flag = 0
  281. -- 自动对焦拍照标志位;
  282. local auto_pic_flag = 0
  283. -- 测试模式
  284. function putTest(cmd, dat)
  285. -- 一键测试
  286. if cmd == "switchAutotest" then
  287. log.info("~~~~~~~~~~switchAutotest",dat)
  288. if dat == 1 or dat == '1' then
  289. if auto_test_flag == 1 then
  290. log.error("----- auto_test_flag = 1,auto_test is running!!!")
  291. return
  292. end
  293. sys.taskInit(function()
  294. -- 一键测试标志位置 1
  295. auto_test_flag = 1
  296. sys.wait(2000)
  297. -- write("sysTest.result.txt=" .. "一键测试正在启动...")
  298. -- write("sysTest.auto_flag.txt=" .. "auto1")
  299. write('sysTest.auto_flag.txt="auto1"')
  300. sys.wait(2000)
  301. -- 复位:
  302. write('sysTest.auto_flag.txt="turn0"')
  303. sys.wait(2000)
  304. control.turn_init()
  305. -- 转
  306. write('sysTest.auto_flag.txt="turn"')
  307. control.turn()
  308. -- 推杆电机:测试粘附:
  309. write('sysTest.auto_flag.txt="add_fsl"')
  310. control.add_fsl()
  311. sys.wait(10000)
  312. -- write("sysTest.result.txt=" .. "更换载玻片,转盘启动...")
  313. -- write("sysTest.auto_flag.txt=" .. "turn")
  314. write('sysTest.auto_flag.txt="turn"')
  315. control.turn()
  316. -- sys.wait(10000)
  317. -- write("sysTest.result.txt=" .. "正在开启采集风机...")
  318. -- write("sysTest.auto_flag.txt=" .. "collect1")
  319. write('sysTest.auto_flag.txt="collect1"')
  320. sys.wait(2000)
  321. control.collect_fan(1)
  322. sys.wait(5000)
  323. -- write("sysTest.result.txt=" .. "即将关闭采集风机...")
  324. -- write("sysTest.auto_flag.txt=" .. "collect0")
  325. write('sysTest.auto_flag.txt="collect0"')
  326. sys.wait(2000)
  327. control.collect_fan(0)
  328. -- write("sysTest.result.txt=" .. "正在开启散热风机...")
  329. -- write("sysTest.auto_flag.txt=" .. "cool1")
  330. write('sysTest.auto_flag.txt="cool1"')
  331. sys.wait(2000)
  332. control.cool(1)
  333. sys.wait(5000)
  334. -- write("sysTest.result.txt=" .. "即将关闭散热风机...")
  335. -- write("sysTest.auto_flag.txt=" .. "cool0")
  336. write('sysTest.auto_flag.txt="cool0"')
  337. sys.wait(2000)
  338. control.cool(0)
  339. -- 转
  340. write('sysTest.auto_flag.txt="turn"')
  341. control.turn()
  342. sys.wait(5000)
  343. -- write("sysTest.result.txt=" .. "正在开启滴液测试...")
  344. -- write("sysTest.auto_flag.txt=" .. "drop1")
  345. write('sysTest.auto_flag.txt="drop1"')
  346. sys.wait(2000)
  347. control.drop(1)
  348. sys.wait(5000)
  349. -- write("sysTest.result.txt=" .. "滴液测试结束...")
  350. -- write("sysTest.auto_flag.txt=" .. "drop0")
  351. write('sysTest.auto_flag.txt="drop0"')
  352. sys.wait(2000)
  353. -- write("sysTest.result.txt=" .. "正在启动加热...")
  354. -- write("sysTest.auto_flag.txt=" .. "heat1")
  355. write('sysTest.auto_flag.txt="heat1"')
  356. sys.wait(2000)
  357. control.heat(1)
  358. sys.wait(5000)
  359. -- write("sysTest.result.txt=" .. "加热测试完毕...")
  360. -- write("sysTest.auto_flag.txt=" .. "heat0")
  361. write('sysTest.auto_flag.txt="heat0"')
  362. sys.wait(2000)
  363. control.heat(0)
  364. -- write("sysTest.result.txt=" .. "正在启动制冷...")
  365. -- write("sysTest.auto_flag.txt=" .. "cold1")
  366. write('sysTest.auto_flag.txt="cold1"')
  367. sys.wait(2000)
  368. control.cold(1)
  369. sys.wait(5000)
  370. -- write("sysTest.result.txt=" .. "制冷测试完毕...")
  371. -- write("sysTest.auto_flag.txt=" .. "cold0")
  372. write('sysTest.auto_flag.txt="cold0"')
  373. sys.wait(2000)
  374. control.cold(0)
  375. -- 转
  376. write('sysTest.auto_flag.txt="turn"')
  377. control.turn()
  378. -- write("sysTest.result.txt=" .. "正在启动补光灯...")
  379. -- write("sysTest.auto_flag.txt=" .. "led1")
  380. write('sysTest.auto_flag.txt="led1"')
  381. sys.wait(2000)
  382. haikang.light_led(1)
  383. sys.wait(2000)
  384. -- write("sysTest.result.txt=" .. "步进电机上行...")
  385. -- write("sysTest.auto_flag.txt=" .. "up1")
  386. write('sysTest.auto_flag.txt="up1"')
  387. haikang.motor_reset()
  388. sys.wait(2000)
  389. -- write("sysTest.result.txt=" .. "步进电机下行...")
  390. -- write("sysTest.auto_flag.txt=" .. "down1")
  391. write('sysTest.auto_flag.txt="down1"')
  392. haikang.motor_down()
  393. -- write("sysTest.result.txt=" .. "正在拍照...")
  394. -- write("sysTest.auto_flag.txt=" .. "photo1")
  395. write('sysTest.auto_flag.txt="photo1"')
  396. sys.wait(2000)
  397. audio.play('/ldata/takephoto.mp3')
  398. haikang.hk_takephoto()
  399. sys.wait(5000)
  400. -- write("sysTest.result.txt=" .. "拍照完毕...")
  401. -- write("sysTest.auto_flag.txt=" .. "photo0")
  402. write('sysTest.auto_flag.txt="photo0"')
  403. sys.wait(3000)
  404. -- write("sysTest.result.txt=" .. "即将关闭补光灯...")
  405. -- write("sysTest.auto_flag.txt=" .. "led0")
  406. write('sysTest.auto_flag.txt="led0"')
  407. haikang.light_led(0)
  408. -- haikang.photo_flag = 1
  409. haikang.http_chose_photo_task()
  410. sys.wait(2000)
  411. -- write("sysTest.result.txt=" .. "一键测试结束...")
  412. -- write("sysTest.auto_flag.txt=" .. "auto0")
  413. -- 转一次:表一键测试结束;
  414. -- control.turn_init()
  415. -- write('sysTest.auto_flag.txt="turn"')
  416. -- control.turn()
  417. -- 复位:
  418. write('sysTest.auto_flag.txt="turn0"')
  419. sys.wait(2000)
  420. control.turn_init()
  421. write('sysTest.auto_flag.txt="auto0"')
  422. write('sysTest.switchAutotest.val=0')
  423. -- 一键测试标志位清零
  424. auto_test_flag = 0
  425. end)
  426. end
  427. -- 采集风机测试:
  428. elseif cmd == "switchCollect" then
  429. log.info("~~~~~~~~~~switchCollect",dat)
  430. sys.taskInit(function()
  431. log.info('<----- switchCollect! ----->')
  432. control.collect_fan(1)
  433. sys.wait(10000)
  434. control.collect_fan(0)
  435. write("sysTest.switchCollect.val=0")
  436. write('sysTest.auto_flag.txt="collect0"')
  437. end)
  438. -- 散热风机测试:
  439. elseif cmd == "switchCool" then
  440. log.info("~~~~~~~~~~switchCool",dat)
  441. sys.taskInit(function()
  442. log.info('<----- switchCool! ----->')
  443. control.cool(1)
  444. -- hmi.hmista.cool_fan = 1
  445. -- log.warn("hmi.hmista.cool_fan:",hmi.hmista.cool_fan)
  446. sys.wait(10000)
  447. control.cool(0)
  448. write("sysTest.switchCool.val=0")
  449. write('sysTest.auto_flag.txt="cool0"')
  450. -- hmi.hmista.cool_fan = 0
  451. -- log.warn("hmi.hmista.cool_fan:",hmi.hmista.cool_fan)
  452. -- write("sysTest.switchCool.val=0")
  453. -- write("temHum.cool_fan.val=0")
  454. end)
  455. --[[
  456. -- 步进电机脱机测试:
  457. elseif cmd == "switchMoff" then
  458. log.info("~~~~~~~~~~switchMoff",dat)
  459. -- 1为使能;非脱机;0为脱机;
  460. if dat == 0 or dat == '0' then
  461. if haikang.up_step == 1 or haikang.down_step == 1 then
  462. haikang.stop_step = 1
  463. end
  464. -- haikang.up_step = 0
  465. -- haikang.down_step = 0
  466. end
  467. haikang.motor_en(dat)
  468. -- control.ctrl_12v(dat)
  469. --]]
  470. -- 粘附电机测试:
  471. elseif cmd == "switchFsl" then
  472. log.info("~~~~~~~~~~switchFsl",dat)
  473. sys.taskInit(function()
  474. control.add_fsl(dat,5)
  475. sys.wait(10*1000)
  476. write('sysTest.switchFsl.val=0')
  477. end)
  478. -- 对焦拍照测试:
  479. elseif cmd == "switchAutopic" then
  480. log.info("~~~~~~~~~~switchAutopic",dat)
  481. if dat == 1 or dat == '1' then
  482. if auto_pic_flag == 1 then
  483. log.error("hmi auto_pic_flag = 1,auto_takepic is running!!!")
  484. return
  485. end
  486. sys.taskInit(function()
  487. -- 对焦拍照测试标志位置 1
  488. auto_pic_flag = 1
  489. log.info('<----- switchPic! ----->')
  490. -- haikang.hk_takephoto()
  491. audio.play('/ldata/takephoto.mp3')
  492. haikang.autotakepic2()
  493. -- 对焦拍照测试标志位 清零
  494. auto_pic_flag = 0
  495. write('sysTest.switchAutopic.val=0')
  496. write('sysTest.auto_flag.txt="auto_photo0"')
  497. end)
  498. end
  499. -- 立即拍照测试:
  500. elseif cmd == "switchPic" then
  501. log.info("~~~~~~~~~~switchPic",dat)
  502. if dat == 1 or dat == '1' then
  503. sys.taskInit(function()
  504. log.info('<----- switchPic! ----->')
  505. audio.play('/ldata/takephoto.mp3')
  506. -- haikang.hk_takephoto()
  507. haikang.test_takephoto()
  508. sys.wait(10000)
  509. -- haikang.photo_flag = 1
  510. haikang.http_chose_photo_task()
  511. write('sysTest.switchPic.val=0')
  512. write('sysTest.auto_flag.txt="photo0"')
  513. end)
  514. end
  515. -- 步进电机上行测试:
  516. elseif cmd == "switchUp" then
  517. log.info("~~~~~~~~~~switchUp",dat)
  518. if dat == 1 or dat == '1' then
  519. sys.taskInit(haikang.motor_reset)
  520. elseif dat == 0 or dat == '0' then
  521. -- if haikang.up_step == 1 or haikang.down_step == 1 then
  522. if haikang.up_step_flag == 1 then
  523. haikang.stop_step = 1
  524. end
  525. end
  526. -- 步进电机下行测试:
  527. elseif cmd == "switchDown" then
  528. log.info("~~~~~~~~~~switchDown",dat)
  529. if dat == 1 or dat == '1' then
  530. sys.taskInit(haikang.motor_down)
  531. elseif dat == 0 or dat == '0' then
  532. -- if haikang.up_step == 1 or haikang.down_step == 1 then
  533. if haikang.down_step_flag == 1 then
  534. haikang.stop_step = 1
  535. end
  536. end
  537. -- 滴液测试:
  538. elseif cmd == "switchDrop" then
  539. log.info("~~~~~~~~~~switchDrop",dat)
  540. if dat == 1 or dat == '1' then
  541. sys.taskInit(control.drop)
  542. -- sys.taskInit(function()
  543. -- print("----------drop time is ...",t)
  544. -- for i=1,3,1 do
  545. -- print("----------droping...",i)
  546. -- pins.setup(pio.P1_1,1)
  547. -- sys.wait(5000)
  548. -- pins.setup(pio.P1_1,0)
  549. -- sys.wait(5000)
  550. -- end
  551. -- write("sysTest.switchDrop.val=0")
  552. -- end)
  553. end
  554. -- 补光灯测试:
  555. elseif cmd == "switchLed" then
  556. log.info("~~~~~~~~~~switchLed",dat)
  557. haikang.light_led(dat)
  558. -- sys.taskInit(haikang.http_chose_photo)
  559. -- haikang.http_chose_photo_task()
  560. -- control.ctrl_12v(dat)
  561. -- 加热测试:
  562. elseif cmd == "switchHeat" then
  563. log.info("~~~~~~~~~~switchHeat",dat)
  564. if dat == 1 or dat == '1' then
  565. sys.taskInit(function()
  566. log.info('<----- switchHeat! ----->')
  567. control.heat(1)
  568. sys.wait(20000)
  569. control.heat(0)
  570. write("sysTest.switchHeat.val=0")
  571. write('sysTest.auto_flag.txt="heat0"')
  572. end)
  573. end
  574. -- 制冷测试:
  575. elseif cmd == "switchCold" then
  576. log.info("~~~~~~~~~~switchCold",dat)
  577. if dat == 1 or dat == '1' then
  578. sys.taskInit(function()
  579. log.info('<----- switchCold! ----->')
  580. control.cold(1)
  581. sys.wait(20000)
  582. control.cold(0)
  583. write("sysTest.switchCold.val=0")
  584. write('sysTest.auto_flag.txt="cold0"')
  585. end)
  586. end
  587. end
  588. end
  589. function resetDefault()
  590. audio.play('/ldata/save.mp3')
  591. -- 恢复参数为默认值
  592. hmiconf.passWord = 8888 --设置初始化密码
  593. hmiconf.thsp = 300 --默认熄屏时间5分钟
  594. hmiconf.vol = 7 -- 默认音量
  595. hmiconf.datt = 20 -- 数据上传时间间隔 分钟
  596. hmiconf.wind_sw = 0
  597. hmiconf.coll_time = {"8-10","14-16"}
  598. hmiconf.cold_sw = 0 --制冷开关
  599. hmiconf.set_temp = 25 -- 保温仓设定温度
  600. hmiconf.imgres = 0 -- 分辨率
  601. hmiconf.drop_time = 1 -- 滴液秒数
  602. hmiconf.cul_time = 1 -- 设定培养时间
  603. audio.setVolume(hmiconf.vol)
  604. -- 将参数保存
  605. local str = json.encode(hmiconf)
  606. io.writefile(HMI_FILE, str)
  607. log.info("resetDefault is Action!", str)
  608. end
  609. -- 保存参数到flash中
  610. sys.taskInit(function()
  611. local str = io.readfile(HMI_FILE)
  612. log.info("paramconf default value: ", str)
  613. if str then
  614. local cnf, result, err = json.decode(str)
  615. -- local str = json.encode(cnf)
  616. -- log.warn("read paramconf is:-----------------:",str)
  617. log.info("==========cnf",cnf)
  618. log.info("==========result",result)
  619. log.info("==========err",err)
  620. if result then hmiconf = cnf end
  621. log.info("==========hmi.hmiconf.wind_sw",hmi.hmiconf.wind_sw)
  622. log.info("==========hmi.hmiconf.coll_time",hmi.hmiconf.coll_time)
  623. log.info("==========hmi.hmiconf.set_temp",hmi.hmiconf.set_temp)
  624. log.info("==========hmi.hmiconf.imgres",hmi.hmiconf.imgres)
  625. log.info("==========hmi.hmiconf.datt",hmi.hmiconf.datt)
  626. log.info("==========hmi.hmiconf.drop_time",hmi.hmiconf.drop_time)
  627. log.info("==========hmi.hmiconf.cul_time",hmi.hmiconf.cul_time)
  628. end
  629. audio.setVolume(hmiconf.vol)
  630. -- audio.play_utf8_tts("欢迎使用物联网孢子捕捉仪")
  631. audio.play('/ldata/pwron.mp3')
  632. end)
  633. function remote_auto_pic()
  634. if auto_pic_flag == 1 then
  635. log.error("remote_auto_pic auto_pic_flag = 1,auto_takepic is running!!!")
  636. return
  637. end
  638. sys.taskInit(function()
  639. -- 对焦拍照测试标志位置 1
  640. auto_pic_flag = 1
  641. log.info('<----- switchPic! ----->')
  642. -- haikang.hk_takephoto()
  643. audio.play('/ldata/takephoto.mp3')
  644. haikang.autotakepic2()
  645. -- 对焦拍照测试标志位 清零
  646. auto_pic_flag = 0
  647. write('sysTest.switchAutopic.val=0')
  648. write('sysTest.auto_flag.txt="auto_photo0"')
  649. end)
  650. end