add: 对air780eg_gnsstest进行改造,拆分多个文件,6228独立成库
[LuatOS.git] / demo / air780eg_gnsstest / testGnss.lua
blob43e86b99a03cf44f1716e3c80631df3a85dc5a8a
2 -- libgnss库初始化
3 libgnss.clear() -- 清空数据,兼初始化
5 -- LED和ADC初始化
6 LED_GNSS = 24
7 gpio.setup(LED_GNSS, 0) -- GNSS定位成功灯
9 local gnss = require("uc6228")
11 sys.taskInit(function()
12 log.debug("提醒", "室内无GNSS信号,定位不会成功, 要到空旷的室外,起码要看得到天空")
13 gnss.setup({
14 uart_id=2,
15 uart_forward = uart.VUART_0, -- 转发到虚拟串口,方便对接GnssToolKit3
16 debug=true
18 pm.power(pm.GPS, true)
19 gnss.start()
20 gnss.agps()
21 end)
23 sys.taskInit(function()
24 while 1 do
25 sys.wait(5000)
26 -- log.info("RMC", json.encode(libgnss.getRmc(2) or {}, "7f"))
27 -- log.info("INT", libgnss.getIntLocation())
28 -- log.info("GGA", libgnss.getGga(3))
29 -- log.info("GLL", json.encode(libgnss.getGll(2) or {}, "7f"))
30 -- log.info("GSA", json.encode(libgnss.getGsa(1) or {}, "7f"))
31 -- log.info("GSV", json.encode(libgnss.getGsv(2) or {}, "7f"))
32 -- log.info("VTG", json.encode(libgnss.getVtg(2) or {}, "7f"))
33 -- log.info("ZDA", json.encode(libgnss.getZda(2) or {}, "7f"))
34 -- log.info("date", os.date())
35 -- log.info("sys", rtos.meminfo("sys"))
36 -- log.info("lua", rtos.meminfo("lua"))
37 end
38 end)
40 -- 订阅GNSS状态编码
41 sys.subscribe("GNSS_STATE", function(event, ticks)
42 -- event取值有
43 -- FIXED 定位成功
44 -- LOSE 定位丢失
45 -- ticks是事件发生的时间,一般可以忽略
46 local onoff = libgnss.isFix() and 1 or 0
47 log.info("GNSS", "LED", onoff)
48 gpio.set(LED_GNSS, onoff)
49 end)