main.lua 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381
  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 airmusic = require "airmusic"
  9. local airap = require "airap"
  10. local airtts = require "airtts"
  11. local airaudio = require "airaudio"
  12. local aircamera = require "aircamera"
  13. local airrus = require "russia"
  14. local airstatus = require "statusbar"
  15. local airtestwlan = require "test_wlan"
  16. local airbuzzer = require "airbuzzer"
  17. local taskName = "MAIN"
  18. local sid = 0
  19. -- 按键事件类型:
  20. -- "switch": 短按开机键切换菜单;
  21. -- "enter": 长按开机键进入功能菜单或者退出功能菜单
  22. -- 当前功能界面
  23. -- "main": 九宫格主界面
  24. -----------页面1------------------
  25. -- "gps": gps定位
  26. -- "wifiap": wifiap,可实现4g转wifi 用作热点传出
  27. -- "wifista": 链接wifi路由器
  28. -- "camera": 摄像头预览
  29. -- "call": 拨打电话
  30. -- "bt": 蓝牙
  31. -- "sms": 短信
  32. -- "tts": 文字转语音
  33. ------------页面2------------------
  34. -- "record": 录音
  35. -- "music": 播放音乐
  36. -- "tf": 驱动TF卡
  37. -- "gsensor": 运动传感器
  38. -- "pm": 电源管理
  39. -- "lan": 以太网lan 通讯,通过air8000 给以太网设备上网
  40. -- "wan": 以太网wan 通讯,通过以太网给air8000 上网
  41. ---------页面3------------------
  42. -- "multi-network": 多网融合演示
  43. -- "485": 485 通讯
  44. -- "can": can 通讯
  45. -- "onewire": onewire 通讯
  46. -- "pwm": 输出PWM 波形
  47. -- "uart": 串口输出
  48. -- "232": 232
  49. local cur_fun = "main"
  50. -- local cur_sel = 0
  51. -- local funlist = {
  52. -- "gps", "wifiap","wifista","camera", "call","bt","sms","tts",
  53. -- "record","music","tf","gsensor","pm","lan","wan",
  54. -- "multi-network","485","can","onewire","pwm","uart","232"
  55. -- }
  56. _G.bkcolor = lcd.rgb565(99, 180, 245,false)
  57. local function wdtInit()
  58. -- 添加硬狗防止程序卡死
  59. if wdt then
  60. wdt.init(9000) -- 初始化watchdog设置为9s
  61. sys.timerLoopStart(wdt.feed, 3000) -- 3s喂一次狗
  62. end
  63. end
  64. local function update()
  65. if cur_fun == "russia" then
  66. airrus.updaterus()
  67. end
  68. if airstatus.data.bat_level == 0 then
  69. airstatus.get_bat_level()
  70. end
  71. end
  72. local lock_push = 1
  73. local function main_local(x,y)
  74. if x > 0 and x < 100 and y > 64 and y < 192 then
  75. return 1
  76. elseif x > 100 and x < 200 and y > 64 and y < 192 then
  77. return 2
  78. elseif x > 200 and x < 300 and y > 64 and y < 192 then
  79. return 3
  80. elseif x > 0 and x < 100 and y > 192 and y < 320 then
  81. return 4
  82. elseif x > 100 and x < 200 and y > 192 and y < 320 then
  83. return 5
  84. elseif x > 200 and x < 300 and y > 192 and y < 320 then
  85. return 6
  86. elseif x > 0 and x < 100 and y > 320 and y < 448 then
  87. return 7
  88. elseif x > 100 and x < 200 and y > 320 and y < 448 then
  89. return 8
  90. elseif x > 200 and x < 300 and y > 320 and y < 448 then
  91. return 9
  92. end
  93. end
  94. local function handal_main(x,y)
  95. key = main_local(x,y)
  96. log.info("tp_handal key",key)
  97. if key == 1 then
  98. cur_fun = "gps"
  99. elseif key == 2 then
  100. cur_fun = "ap"
  101. elseif key == 3 then
  102. cur_fun = "sta"
  103. elseif key == 4 then
  104. cur_fun = "camera"
  105. elseif key == 5 then
  106. elseif key == 6 then
  107. elseif key == 7 then
  108. elseif key == 8 then -- tts
  109. cur_fun = "tts"
  110. elseif key == 9 then
  111. cur_fun = "main1"
  112. end
  113. end
  114. local function handal_main1(x,y)
  115. key = main_local(x,y)
  116. log.info("tp_handal key",key)
  117. if key == 1 then
  118. elseif key == 2 then
  119. airmusic.play("/luadb/1.mp3")
  120. elseif key == 3 then
  121. elseif key == 4 then
  122. elseif key == 5 then
  123. elseif key == 6 then
  124. elseif key == 7 then
  125. cur_fun = "main"
  126. elseif key == 8 then
  127. elseif key == 9 then
  128. cur_fun = "main2"
  129. end
  130. end
  131. local function handal_main2(x,y)
  132. key = main_local(x,y)
  133. log.info("tp_handal key",key)
  134. if key == 1 then
  135. elseif key == 2 then
  136. elseif key == 3 then
  137. elseif key == 4 then
  138. elseif key == 5 then
  139. elseif key == 6 then
  140. elseif key == 7 then
  141. cur_fun = "main1"
  142. elseif key == 8 then
  143. elseif key == 9 then
  144. cur_fun = "main"
  145. end
  146. end
  147. local function tp_handal(tp_device,tp_data)
  148. -- log.info("tp_handal",tp_data[1].x,tp_data[1].y,tp_data[1].event)
  149. if tp_data[1].event == 1 then
  150. lock_push = 0
  151. end
  152. if tp_data[1].event == 2 and lock_push == 0 then
  153. if cur_fun == "main" then
  154. handal_main(tp_data[1].x,tp_data[1].y)
  155. elseif cur_fun == "main1" then
  156. handal_main1(tp_data[1].x,tp_data[1].y)
  157. elseif cur_fun == "main2" then
  158. handal_main2(tp_data[1].x,tp_data[1].y)
  159. elseif cur_fun == "tts" then
  160. airtts.tp_handal(tp_data[1].x,tp_data[1].y,tp_data[1].event)
  161. elseif cur_fun == "camera" then
  162. aircamera.tp_handal(tp_data[1].x,tp_data[1].y,tp_data[1].event)
  163. elseif cur_fun == "gps" then
  164. airgps.tp_handal(tp_data[1].x,tp_data[1].y,tp_data[1].event)
  165. elseif cur_fun == "ap" then
  166. airap.tp_handal(tp_data[1].x,tp_data[1].y,tp_data[1].event)
  167. end
  168. lock_push = 1
  169. end
  170. end
  171. -- 画状态栏
  172. local function draw_statusbar()
  173. lcd.showImage(0, 0, "/luadb/signal" .. airstatus.data.sig_stren .. ".jpg")
  174. lcd.showImage(64, 0, "/luadb/power" .. airstatus.data.bat_level .. ".jpg")
  175. lcd.showImage(128, 0, "/luadb/temp.jpg")
  176. lcd.showImage(192, 0, "/luadb/humidity.jpg")
  177. lcd.showImage(0, 448, "/luadb/Lbottom.jpg")
  178. if airstatus.data.weather.result then
  179. lcd.setFont(lcd.font_opposansm32_chinese)
  180. lcd.drawStr(172, 30, tostring(airstatus.data.weather.temp))
  181. lcd.drawStr(236, 30, tostring(airstatus.data.weather.humidity))
  182. lcd.showImage(256, 0, airstatus.data.weather.text)
  183. else
  184. lcd.showImage(256, 0, "/luadb/default.jpg")
  185. end
  186. end
  187. --画九宫格界面
  188. local function draw_main()
  189. local i = 0
  190. local j = 0
  191. local x,y
  192. local fname
  193. local sel = 0
  194. for i = 1,3 do
  195. for j = 1,3 do
  196. x = 64 + (i-1)*128 + 24
  197. y = (j-1)*106 + 13
  198. sel = j+(i-1)*3
  199. fname = "/luadb/" .. "A" .. sel .. ".jpg"
  200. -- log.info("fname:", fname, x,y,sel,cur_sel)
  201. lcd.showImage(y,x,fname)
  202. end
  203. end
  204. end
  205. local function draw_main1()
  206. local i = 0
  207. local j = 0
  208. local x,y
  209. local fname
  210. local sel = 0
  211. for i = 1,3 do
  212. for j = 1,3 do
  213. x = 64 + (i-1)*128 + 24
  214. y = (j-1)*106 + 13
  215. sel = j+(i-1)*3
  216. fname = "/luadb/" .. "B" .. sel .. ".jpg"
  217. -- log.info("fname:", fname, x,y,sel,cur_sel)
  218. lcd.showImage(y,x,fname)
  219. end
  220. end
  221. end
  222. local function draw_main2()
  223. local i = 0
  224. local j = 0
  225. local x,y
  226. local fname
  227. local sel = 0
  228. for i = 1,3 do
  229. for j = 1,3 do
  230. x = 64 + (i-1)*128 + 24
  231. y = (j-1)*106 + 13
  232. sel = j+(i-1)*3
  233. fname = "/luadb/" .. "C" .. sel .. ".jpg"
  234. -- log.info("fname:", fname, x,y,sel,cur_sel)
  235. lcd.showImage(y,x,fname)
  236. end
  237. end
  238. end
  239. local function draw_pic()
  240. lcd.showImage(0,64,"/luadb/P1.jpg")
  241. end
  242. local function draw_tts()
  243. if airtts.run() then
  244. cur_fun = "main"
  245. end
  246. end
  247. local function draw_camera()
  248. if aircamera.run() then
  249. cur_fun = "main"
  250. end
  251. end
  252. local function draw_gps()
  253. aircamera.close()
  254. if airgps.run() then
  255. cur_fun = "main"
  256. end
  257. end
  258. local function draw_ap()
  259. if airap.run() then
  260. cur_fun = "main"
  261. end
  262. end
  263. local function draw_sta()
  264. if airsta.run() then
  265. cur_fun = "main"
  266. end
  267. end
  268. local function draw()
  269. if cur_fun == "camshow" then
  270. return
  271. end
  272. lcd.clear(_G.bkcolor)
  273. draw_statusbar()
  274. if cur_fun == "main" then
  275. draw_main()
  276. elseif cur_fun == "main1" then
  277. draw_main1()
  278. elseif cur_fun == "main2" then
  279. draw_main2()
  280. elseif cur_fun == "tts" then
  281. draw_tts()
  282. elseif cur_fun == "camera" then
  283. draw_camera()
  284. elseif cur_fun == "gps" then
  285. draw_gps()
  286. elseif cur_fun == "ap" then
  287. draw_ap()
  288. elseif cur_fun == "sta" then
  289. draw_sta()
  290. end
  291. lcd.showImage(0,448,"/luadb/Lbottom.jpg")
  292. lcd.flush()
  293. end
  294. local function update_airstatus()
  295. airstatus.get_sig_strength()
  296. airstatus.get_weather()
  297. end
  298. wdtInit()
  299. function ip_ready_handle(ip, adapter)
  300. log.info("ip_ready_handle",ip, adapter)
  301. if adapter == socket.LWIP_GP then
  302. sysplus.taskInitEx(update_airstatus, "update_airstatus")
  303. end
  304. end
  305. local function UITask()
  306. sys.wait(1000)
  307. log.info("合宙 8000 startup v1")
  308. -- aircamera.init()
  309. airlcd.lcd_init("AirLCD_1001")
  310. sys.subscribe("TP",tp_handal)
  311. while 1 do
  312. update()
  313. draw()
  314. if ((sid % 10) == 0) then
  315. log.info("sid: ", sid, cur_fun)
  316. end
  317. sid = sid + 1
  318. sys.wait(10)
  319. end
  320. end
  321. sys.subscribe("IP_READY", ip_ready_handle)
  322. sysplus.taskInitEx(UITask, taskName)
  323. -- 当前是给camera 表的变量赋值让camera 退出。 未来可以让 UI task 发消息给camera 任务,让camera 任务关闭摄像头,释放LCD
  324. -- 用户代码已结束---------------------------------------------
  325. -- 结尾总是这一句
  326. sys.run()
  327. -- sys.run()之后后面不要加任何语句!!!!!