User Tools

Site Tools


useful_programs

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
useful_programs [2024/03/19 09:25] – [Detection of change of state] emozolyakuseful_programs [2024/03/19 09:39] (current) – [Detection of change of state] emozolyak
Line 1540: Line 1540:
      
   onchange1(R(110), function() INFO("true!") end )   onchange1(R(110), function() INFO("true!") end )
 +    ------- Detecting changes of a set of registers ----------------
 +  local regSet = {{110, function() 
 +                            INFO("I'm a callback for reg 110")
 +                    end },
 +                   {1, function() 
 +                       INFO("I'm a callback for reg 1")
 +                    end }, 
 +                    {200, function() 
 +                        INFO("I'm a callback for reg 200")
 +                    end }, 
 +                 
 +   }
 +  
 +  local handlers = {} 
 +  
 +  -- registereing handlers 
 +  if (not handlers[regSet[1][1]]) then 
 +      for _, s in ipairs(regSet) do
 +          handlers[s[1]] = OnChange()
 +      end 
 +  end 
 +   
 +  -- using  handlers 
 +  for _, s in ipairs(regSet) do
 +      local reg, func   = s[1], s[2]
 +      handlers[reg](R(reg), func())    
 +  end 
 end end
 </code> </code>
useful_programs.txt · Last modified: 2024/03/19 09:39 by emozolyak

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki