代码拉取完成,页面将自动刷新
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)
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。