main.lua 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536
  1. PROJECT = "startupv13"
  2. VERSION = "1.0.0"
  3. log.info("main", PROJECT, VERSION)
  4. -- sys库是标配
  5. sys = require("sys")
  6. local airlcd = require "airlcd"
  7. local airgps = require "airgps"
  8. local airsta = require "airsta"
  9. local airmusic = require "airmusic"
  10. local airap = require "airap"
  11. local airtts = require "airtts"
  12. local airlan = require "airlan"
  13. local airwan = require "airwan"
  14. local airsms = require "airsms"
  15. local aircall = require "aircall"
  16. local airgsensor = require "airgsensor"
  17. local airpower = require "airpower"
  18. local airtf = require "airtf"
  19. local airaudio = require "airaudio"
  20. local aircamera = require "aircamera"
  21. local airrus = require "russia"
  22. local airstatus = require "statusbar"
  23. local airble = require "airble"
  24. local airtestwlan = require "test_wlan"
  25. local airbuzzer = require "airbuzzer"
  26. local multi_network = require "multi_network"
  27. local taskName = "MAIN"
  28. local sid = 0
  29. -- 按键事件类型:
  30. -- "switch": 短按开机键切换菜单;
  31. -- "enter": 长按开机键进入功能菜单或者退出功能菜单
  32. -- 当前功能界面
  33. -- "main": 九宫格主界面
  34. -----------页面1------------------
  35. -- "gps": gps定位
  36. -- "wifiap": wifiap,可实现4g转wifi 用作热点传出
  37. -- "wifista": 链接wifi路由器
  38. -- "camera": 摄像头预览
  39. -- "call": 拨打电话
  40. -- "bt": 蓝牙
  41. -- "sms": 短信
  42. -- "tts": 文字转语音
  43. ------------页面2------------------
  44. -- "record": 录音
  45. -- "music": 播放音乐
  46. -- "tf": 驱动TF卡
  47. -- "gsensor": 运动传感器
  48. -- "pm": 电源管理
  49. -- "lan": 以太网lan 通讯,通过air8000 给以太网设备上网
  50. -- "wan": 以太网wan 通讯,通过以太网给air8000 上网
  51. ---------页面3------------------
  52. -- "multi_network": 多网融合演示
  53. -- "485": 485 通讯
  54. -- "can": can 通讯
  55. -- "onewire": onewire 通讯
  56. -- "pwm": 输出PWM 波形
  57. -- "uart": 串口输出
  58. -- "232": 232
  59. local cur_fun = "main"
  60. -- local cur_sel = 0
  61. -- local funlist = {
  62. -- "gps", "wifiap","wifista","camera", "call","bt","sms","tts",
  63. -- "record","music","tf","gsensor","pm","lan","wan",
  64. -- "multi_network","485","can","onewire","pwm","uart","232"
  65. -- }
  66. _G.bkcolor = lcd.rgb565(99, 180, 245,false)
  67. local function wdtInit()
  68. -- 添加硬狗防止程序卡死
  69. if wdt then
  70. wdt.init(9000) -- 初始化watchdog设置为9s
  71. sys.timerLoopStart(wdt.feed, 3000) -- 3s喂一次狗
  72. end
  73. end
  74. local function update()
  75. if cur_fun == "russia" then
  76. airrus.updaterus()
  77. end
  78. if airstatus.data.bat_level == 0 then
  79. airstatus.get_bat_level()
  80. end
  81. end
  82. local lock_push = 1
  83. local function main_local(x,y)
  84. if x > 0 and x < 100 and y > 64 and y < 192 then
  85. return 1
  86. elseif x > 100 and x < 200 and y > 64 and y < 192 then
  87. return 2
  88. elseif x > 200 and x < 300 and y > 64 and y < 192 then
  89. return 3
  90. elseif x > 0 and x < 100 and y > 192 and y < 320 then
  91. return 4
  92. elseif x > 100 and x < 200 and y > 192 and y < 320 then
  93. return 5
  94. elseif x > 200 and x < 300 and y > 192 and y < 320 then
  95. return 6
  96. elseif x > 0 and x < 100 and y > 320 and y < 448 then
  97. return 7
  98. elseif x > 100 and x < 200 and y > 320 and y < 448 then
  99. return 8
  100. elseif x > 200 and x < 300 and y > 320 and y < 448 then
  101. return 9
  102. end
  103. end
  104. local function handal_main(x,y)
  105. key = main_local(x,y)
  106. log.info("tp_handal key",key)
  107. if key == 1 then
  108. cur_fun = "airgps"
  109. elseif key == 2 then
  110. cur_fun = "airap"
  111. elseif key == 3 then
  112. cur_fun = "airsta"
  113. elseif key == 4 then
  114. cur_fun = "aircamera"
  115. elseif key == 5 then
  116. cur_fun = "aircall"
  117. elseif key == 6 then
  118. cur_fun = "airble"
  119. elseif key == 7 then
  120. cur_fun = "airsms"
  121. elseif key == 8 then -- tts
  122. cur_fun = "airtts"
  123. elseif key == 9 then
  124. cur_fun = "main1"
  125. end
  126. end
  127. local function handal_main1(x,y)
  128. key = main_local(x,y)
  129. log.info("tp_handal key",key)
  130. if key == 1 then
  131. elseif key == 2 then
  132. elseif key == 3 then
  133. cur_fun = "airtf"
  134. elseif key == 4 then
  135. cur_fun = "airgsensor"
  136. elseif key == 5 then
  137. cur_fun = "airpower"
  138. elseif key == 6 then
  139. cur_fun = "airlan"
  140. elseif key == 7 then
  141. cur_fun = "main"
  142. elseif key == 8 then
  143. cur_fun = "airwan"
  144. elseif key == 9 then
  145. cur_fun = "main2"
  146. end
  147. end
  148. local function handal_main2(x,y)
  149. key = main_local(x,y)
  150. log.info("tp_handal key",key)
  151. if key == 1 then
  152. cur_fun = "multi_network"
  153. elseif key == 2 then
  154. elseif key == 3 then
  155. elseif key == 4 then
  156. elseif key == 5 then
  157. elseif key == 6 then
  158. elseif key == 7 then
  159. cur_fun = "main1"
  160. elseif key == 8 then
  161. elseif key == 9 then
  162. cur_fun = "main3"
  163. end
  164. end
  165. local function handal_main3(x,y)
  166. key = main_local(x,y)
  167. log.info("tp_handal key",key)
  168. if key == 1 then
  169. cur_fun = "multi_network"
  170. elseif key == 2 then
  171. elseif key == 3 then
  172. elseif key == 4 then
  173. elseif key == 5 then
  174. elseif key == 6 then
  175. elseif key == 7 then
  176. cur_fun = "main2"
  177. elseif key == 8 then
  178. elseif key == 9 then
  179. cur_fun = "main"
  180. end
  181. end
  182. local function tp_handal(tp_device,tp_data)
  183. -- log.info("tp_handal",tp_data[1].x,tp_data[1].y,tp_data[1].event)
  184. if tp_data[1].event == 1 then
  185. lock_push = 0
  186. end
  187. if tp_data[1].event == 2 and lock_push == 0 then
  188. if cur_fun == "main" then
  189. handal_main(tp_data[1].x,tp_data[1].y)
  190. elseif cur_fun == "main1" then
  191. handal_main1(tp_data[1].x,tp_data[1].y)
  192. elseif cur_fun == "main2" then
  193. handal_main2(tp_data[1].x,tp_data[1].y)
  194. elseif cur_fun == "main3" then
  195. handal_main3(tp_data[1].x,tp_data[1].y)
  196. elseif cur_fun == "airtts" then
  197. airtts.tp_handal(tp_data[1].x,tp_data[1].y,tp_data[1].event)
  198. elseif cur_fun == "aircamera" then
  199. aircamera.tp_handal(tp_data[1].x,tp_data[1].y,tp_data[1].event)
  200. elseif cur_fun == "airgps" then
  201. airgps.tp_handal(tp_data[1].x,tp_data[1].y,tp_data[1].event)
  202. elseif cur_fun == "airap" then
  203. airap.tp_handal(tp_data[1].x,tp_data[1].y,tp_data[1].event)
  204. elseif cur_fun == "airsta" then
  205. airsta.tp_handal(tp_data[1].x,tp_data[1].y,tp_data[1].event)
  206. elseif cur_fun == "multi_network" then
  207. multi_network.tp_handal(tp_data[1].x,tp_data[1].y,tp_data[1].event)
  208. elseif cur_fun == "airwan" then
  209. airwan.tp_handal(tp_data[1].x,tp_data[1].y,tp_data[1].event)
  210. elseif cur_fun == "airlan" then
  211. airlan.tp_handal(tp_data[1].x,tp_data[1].y,tp_data[1].event)
  212. elseif cur_fun == "airsms" then
  213. airsms.tp_handal(tp_data[1].x,tp_data[1].y,tp_data[1].event)
  214. elseif cur_fun == "aircall" then
  215. aircall.tp_handal(tp_data[1].x,tp_data[1].y,tp_data[1].event)
  216. elseif cur_fun == "airtf" then
  217. airtf.tp_handal(tp_data[1].x,tp_data[1].y,tp_data[1].event)
  218. elseif cur_fun == "airgsensor" then
  219. airgsensor.tp_handal(tp_data[1].x,tp_data[1].y,tp_data[1].event)
  220. elseif cur_fun == "airpower" then
  221. airpower.tp_handal(tp_data[1].x,tp_data[1].y,tp_data[1].event)
  222. elseif cur_fun == "airble" then
  223. airble.tp_handal(tp_data[1].x,tp_data[1].y,tp_data[1].event)
  224. end
  225. lock_push = 1
  226. end
  227. end
  228. -- 画状态栏
  229. local function draw_statusbar()
  230. lcd.showImage(0, 0, "/luadb/signal" .. airstatus.data.sig_stren .. ".jpg")
  231. lcd.showImage(64, 0, "/luadb/power" .. airstatus.data.bat_level .. ".jpg")
  232. lcd.showImage(128, 0, "/luadb/temp.jpg")
  233. lcd.showImage(192, 0, "/luadb/humidity.jpg")
  234. lcd.showImage(0, 448, "/luadb/Lbottom.jpg")
  235. if airstatus.data.weather.result then
  236. lcd.setFont(lcd.font_opposansm32_chinese)
  237. lcd.drawStr(172, 30, tostring(airstatus.data.weather.temp))
  238. lcd.drawStr(236, 30, tostring(airstatus.data.weather.humidity))
  239. lcd.showImage(256, 0, airstatus.data.weather.text)
  240. else
  241. lcd.showImage(256, 0, "/luadb/default.jpg")
  242. end
  243. end
  244. --画九宫格界面
  245. local function draw_main()
  246. local i = 0
  247. local j = 0
  248. local x,y
  249. local fname
  250. local sel = 0
  251. for i = 1,3 do
  252. for j = 1,3 do
  253. x = 64 + (i-1)*128 + 24
  254. y = (j-1)*106 + 13
  255. sel = j+(i-1)*3
  256. fname = "/luadb/" .. "A" .. sel .. ".jpg"
  257. -- log.info("fname:", fname, x,y,sel,cur_sel)
  258. lcd.showImage(y,x,fname)
  259. end
  260. end
  261. end
  262. local function draw_main1()
  263. local i = 0
  264. local j = 0
  265. local x,y
  266. local fname
  267. local sel = 0
  268. for i = 1,3 do
  269. for j = 1,3 do
  270. x = 64 + (i-1)*128 + 24
  271. y = (j-1)*106 + 13
  272. sel = j+(i-1)*3
  273. fname = "/luadb/" .. "B" .. sel .. ".jpg"
  274. -- log.info("fname:", fname, x,y,sel,cur_sel)
  275. lcd.showImage(y,x,fname)
  276. end
  277. end
  278. end
  279. local function draw_main2()
  280. local i = 0
  281. local j = 0
  282. local x,y
  283. local fname
  284. local sel = 0
  285. for i = 1,3 do
  286. for j = 1,3 do
  287. x = 64 + (i-1)*128 + 24
  288. y = (j-1)*106 + 13
  289. sel = j+(i-1)*3
  290. fname = "/luadb/" .. "C" .. sel .. ".jpg"
  291. -- log.info("fname:", fname, x,y,sel,cur_sel)
  292. lcd.showImage(y,x,fname)
  293. end
  294. end
  295. end
  296. local function draw_main3()
  297. local i = 0
  298. local j = 0
  299. local x,y
  300. local fname
  301. local sel = 0
  302. for i = 1,3 do
  303. for j = 1,3 do
  304. x = 64 + (i-1)*128 + 24
  305. y = (j-1)*106 + 13
  306. sel = j+(i-1)*3
  307. fname = "/luadb/" .. "D" .. sel .. ".jpg"
  308. -- log.info("fname:", fname, x,y,sel,cur_sel)
  309. lcd.showImage(y,x,fname)
  310. end
  311. end
  312. end
  313. local function draw_pic()
  314. lcd.showImage(0,64,"/luadb/P1.jpg")
  315. end
  316. local function draw_tts()
  317. if airtts.run() then
  318. cur_fun = "main"
  319. end
  320. end
  321. local function draw_camera()
  322. if aircamera.run() then
  323. cur_fun = "main"
  324. end
  325. end
  326. local function draw_gps()
  327. aircamera.close()
  328. if airgps.run() then
  329. cur_fun = "main"
  330. end
  331. end
  332. local function draw_ap()
  333. if airap.run() then
  334. cur_fun = "main"
  335. end
  336. end
  337. local function draw_sta()
  338. if airsta.run() then
  339. cur_fun = "main"
  340. end
  341. end
  342. local function draw_wan()
  343. if airwan.run() then
  344. cur_fun = "main"
  345. end
  346. end
  347. local function draw_lan()
  348. if airlan.run() then
  349. cur_fun = "main"
  350. end
  351. end
  352. local function draw_sms()
  353. if airsms.run() then
  354. cur_fun = "main"
  355. end
  356. end
  357. local function draw_call()
  358. if aircall.run() then
  359. cur_fun = "main"
  360. end
  361. end
  362. local function draw_tf()
  363. if airtf.run() then
  364. cur_fun = "main1"
  365. end
  366. end
  367. local function draw_gsensor()
  368. if airgsensor.run() then
  369. cur_fun = "main1"
  370. end
  371. end
  372. local function draw_power()
  373. if airpower.run() then
  374. cur_fun = "main1"
  375. end
  376. end
  377. local function draw_multi_network()
  378. if multi_network.run() then
  379. cur_fun = "main"
  380. end
  381. end
  382. local function draw_airble()
  383. if airble.run() then
  384. cur_fun = "main"
  385. end
  386. end
  387. local function draw()
  388. if cur_fun == "camshow" then
  389. return
  390. end
  391. lcd.clear(_G.bkcolor)
  392. draw_statusbar()
  393. if cur_fun == "main" then
  394. draw_main()
  395. elseif cur_fun == "main1" then
  396. draw_main1()
  397. elseif cur_fun == "main2" then
  398. draw_main2()
  399. elseif cur_fun == "main3" then
  400. draw_main3()
  401. elseif cur_fun == "airtts" then
  402. draw_tts()
  403. elseif cur_fun == "aircamera" then
  404. draw_camera()
  405. elseif cur_fun == "airgps" then
  406. draw_gps()
  407. elseif cur_fun == "airap" then
  408. draw_ap()
  409. elseif cur_fun == "airsta" then
  410. draw_sta()
  411. elseif cur_fun == "airwan" then
  412. draw_wan()
  413. elseif cur_fun == "airlan" then
  414. draw_lan()
  415. elseif cur_fun == "airsms" then
  416. draw_sms()
  417. elseif cur_fun == "aircall" then
  418. draw_call()
  419. elseif cur_fun == "airtf" then
  420. draw_tf()
  421. elseif cur_fun == "airgsensor" then
  422. draw_gsensor()
  423. elseif cur_fun == "airpower" then
  424. draw_power()
  425. elseif cur_fun == "multi_network" then
  426. draw_multi_network()
  427. elseif cur_fun == "multi_network" then
  428. draw_airble()
  429. end
  430. lcd.showImage(0,448,"/luadb/Lbottom.jpg")
  431. lcd.flush()
  432. end
  433. local function update_airstatus()
  434. airstatus.get_sig_strength()
  435. airstatus.get_weather()
  436. end
  437. wdtInit()
  438. function ip_ready_handle(ip, adapter)
  439. log.info("ip_ready_handle",ip, adapter)
  440. if adapter == socket.LWIP_GP then
  441. sysplus.taskInitEx(update_airstatus, "update_airstatus")
  442. end
  443. end
  444. local function UITask()
  445. sys.wait(1000)
  446. log.info("合宙 8000 startup v1")
  447. -- aircamera.init()
  448. airlcd.lcd_init("AirLCD_1001")
  449. sys.subscribe("TP",tp_handal)
  450. while 1 do
  451. update()
  452. draw()
  453. if ((sid % 10) == 0) then
  454. log.info("sid: ", sid, cur_fun)
  455. end
  456. sid = sid + 1
  457. sys.wait(10)
  458. end
  459. end
  460. sys.subscribe("IP_READY", ip_ready_handle)
  461. sysplus.taskInitEx(UITask, taskName)
  462. -- 当前是给camera 表的变量赋值让camera 退出。 未来可以让 UI task 发消息给camera 任务,让camera 任务关闭摄像头,释放LCD
  463. -- 用户代码已结束---------------------------------------------
  464. -- 结尾总是这一句
  465. sys.run()
  466. -- sys.run()之后后面不要加任何语句!!!!!