hmi.lua 26 KB

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