8 Star 26 Fork 14

wibim / luat-jt808

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
shk.lua 2.10 KB
一键复制 编辑 原始数据 按行查看 历史
wibim 提交于 2020-02-15 14:44 . 第一次上代码
module(...,package.seeall)
local i2cid,intregaddr = 0,0x1A
local initstr,indcnt1,indcnt2 = "",0,0
local function clrint()
print("--zbb--shk.clrint 1")
if pincfg.GSENSOR() == 0 then
print("--zbb--shk.clrint 2")
local rlt = i2c.read(i2cid,intregaddr,1)
print("--zbb--shk.clrint rlt",rlt)
end
end
local function init2()
local cmd,i = {0x1B,0x00,0x6A,0x01,0x1E,0x20,0x21,0x04,0x1B,0x00,0x1B,0xDA,0x1B,0xDA}
--local cmd,i = {0x1B,0x00,0x6A,0x01,0x1E,0x20,0x21,0x04,0x1D,0x06,0x1B,0x1A,0x1B,0x9A}
--local cmd,i = {0x1B,0x00,0x6A,0x01,0x1E,0x20,0x21,0x04,0x1B,0x1A,0x1B,0x9A}
for i=1,#cmd,2 do
i2c.write(i2cid,cmd[i],cmd[i+1])
print("--zbb--shk.init2",string.format("%02X",cmd[i]),string.format("%02X",string.byte(i2c.read(i2cid,cmd[i],1))))
initstr = initstr..","..(string.format("%02X",cmd[i]) or "nil")..":"..(string.format("%02X",string.byte(i2c.read(i2cid,cmd[i],1))) or "nil")
end
clrint()
end
local function checkready()
local s = i2c.read(i2cid,0x1D,1)
-- print("--zbb--shk.checkready",s,(s and s~="") and string.byte(s) or "read nil")
if s and s~="" then
if bit.band(string.byte(s),0x80)==0 then
init2()
return
end
end
sys.timerStart(checkready,1000)
end
local function init()
local i2cslaveaddr = 0x0E
if i2c.setup(i2cid,i2c.SLOW,i2cslaveaddr) ~= i2c.SLOW then
print("shk.init fail")
initstr = "fail"
return
end
i2c.write(i2cid,0x1D,0x80)
sys.timerStart(checkready,1000)
end
local function init3()
i2c.write(i2cid,0x1D,0x80)
sys.timerStart(checkready,1000)
end
function checkabnormal()
print(nil,"shk.checkabnormal")
local val = i2c.read(i2cid,0x1B,1)
if not val or val=="" or string.byte(val)~=0xDA then
print(nil,"shk.checkabnormal 0x1B")
--i2c.close(i2cid)
init3()
init()
return
end
end
function getdebugstr()
return initstr..";".."indcnt1:"..indcnt1..";".."indcnt2:"..indcnt2
end
function ind(data)
print("shk.ind",data,cpu.INT_GPIO_NEGEDGE)
if data == cpu.INT_GPIO_NEGEDGE then --下降沿中断
clrint()
print("shk.ind DEV_SHK_IND")
sys.publish("DEV_SHK_IND")
end
end
init()
sys.timerLoopStart(clrint,30000)
sys.timerLoopStart(checkabnormal,300000)
Lua
1
https://gitee.com/wibim/luat-jt808.git
git@gitee.com:wibim/luat-jt808.git
wibim
luat-jt808
luat-jt808
master

搜索帮助