Posts: 4663
Threads: 24
Joined: Aug 2017
Reputation:
213
------------------------------
Ctrl+F5
Posts: 36
Threads: 10
Joined: Sep 2021
Reputation:
0
thank you Hello, I only need to send a value of 0 (OFF) when pressed for 3-4 seconds (a short press does nothing). What should I refer to in the script? thanks
Posts: 4663
Threads: 24
Joined: Aug 2017
Reputation:
213
Try this (not tested)
Code:
if not client then
timeout = 1 -- long press in seconds
mapping = {
['32/1/1'] = { short = '32/1/2', long = '32/1/3' },
['32/1/4'] = { short = '32/1/5', long = '32/1/6' },
}
timerstep = timeout / 4
function eventhandler(event)
local object = mapping[ event.dst ]
if not object then
return
end
local value = busdatatype.decode(event.datahex, dt.bool)
if value then
object.timer = timeout
elseif object.timer then
object.timer = nil
-- grp.write(object.short, not grp.getvalue(object.short), dt.bool)
end
end
client = require('localbus').new(1)
clientfd = socket.fdmaskset(client:getfd(), 'r')
client:sethandler('groupwrite', eventhandler)
timer = require('timerfd').new(timerstep)
timerfd = socket.fdmaskset(timer:getfd(), 'r')
end
res, clientstat, timerstat = socket.selectfds(10, clientfd, timerfd)
if clientstat then
client:step()
end
if timerstat then
timer:read()
for addr, object in pairs(mapping) do
if object.timer then
object.timer = object.timer - timerstep
if object.timer <= 0 then
object.timer = nil
grp.write(object.long, false, dt.bool)
end
end
end
end
------------------------------
Ctrl+F5