useful_programs
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
useful_programs [2024/03/19 09:24] – [Detection of change of state] emozolyak | useful_programs [2024/03/19 09:39] (current) – [Detection of change of state] emozolyak | ||
---|---|---|---|
Line 1526: | Line 1526: | ||
if (self.prev and v ~= self.prev ) then | if (self.prev and v ~= self.prev ) then | ||
out = true | out = true | ||
- | cb() | + | |
end | end | ||
self.prev = v | self.prev = v | ||
Line 1540: | Line 1540: | ||
| | ||
onchange1(R(110), | onchange1(R(110), | ||
+ | ------- Detecting changes of a set of registers ---------------- | ||
+ | local regSet = {{110, function() | ||
+ | INFO(" | ||
+ | end }, | ||
+ | {1, function() | ||
+ | | ||
+ | end }, | ||
+ | {200, function() | ||
+ | INFO(" | ||
+ | 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), | ||
+ | end | ||
end | end | ||
</ | </ |
useful_programs.txt · Last modified: 2024/03/19 09:39 by emozolyak