(11.04.2024, 14:45)admin Wrote: Post your script. What exactly have you changed?
-- maximum time between presses
presstimeout = 0.5
mapping = {
['9/0/0'] = {
-- single press
single_address = '9/1/0',
single_value = FALSE,
-- double press
double_address = '9/2/0',
double_value = TRUE,
-- multi (3+) press (optional)
multi_address = '9/0/9',
multi_value = 33,
},
['9/0/1'] = {
-- single press
single_address = '1/3/40',
single_value = TRUE,
-- double press
double_address = '1/3/41',
double_value = TRUE,
},
}
require('copas')
function write(map, key)
local address = map[ key .. '_address']
local value = map[ key .. '_value']
if address and value ~= nil then
grp.write(address, value)
return true
end
end
function timerthread(addr, map)
local counter = 0
local timeout = -1 -- suspend thread
while true do
copas.sleep(timeout)
if map.counter == counter then
if timeout == presstimeout then
if counter == 1 then
write(map, 'single')
elseif counter == 2 or not write(map, 'multi') then
write(map, 'double')
end
timeout = -1
counter = 0
map.counter = 0
end
else
timeout = presstimeout
counter = map.counter
end
end
end
for addr, map in pairs(mapping) do
map.counter = 0
map.thread = copas.addthread(timerthread, addr, map)
end
function eventhandler(event)
local map = mapping[ event.dst ]
if map then
map.counter = map.counter + 1
copas.wakeup(map.thread)
end
end
lb = require('localbus').new(1)
lb
ethandler('groupwrite', eventhandler)
copas.addserver(lb.sock, function()
lb.sock = copas.wrap(lb.sock)
while true do
lb
tep()
end
end, 1)
copas.loop()
ONLY: adress and value...