This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

Activation after holding a button
#4
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
Reply


Messages In This Thread
Activation after holding a button - by Nir70 - 20.11.2024, 08:32
RE: Activation after holding a button - by Daniel - 20.11.2024, 15:53

Forum Jump: