Prevent extra pin events with luacontrollers, microcontrollers, and FPGAs (#593)

This commit is contained in:
Jude Melton-Houghton
2022-02-27 15:12:37 -05:00
committed by GitHub
parent fef5c8cf68
commit 0d9e0274ae
3 changed files with 40 additions and 20 deletions

View File

@ -114,8 +114,9 @@ plg.register_nodes({
effector = {
rules = {}, -- replaced later
action_change = function(pos, _, rule, newstate)
plg.ports_changed(pos, rule, newstate)
plg.update(pos)
if plg.ports_changed(pos, rule, newstate) then
plg.update(pos)
end
end
}
},
@ -326,8 +327,10 @@ plg.update = function(pos)
plg.setports(pos, A, B, C, D)
end
-- Updates the port states according to the signal change.
-- Returns whether the port states actually changed.
plg.ports_changed = function(pos, rule, newstate)
if rule == nil then return end
if rule == nil then return false end
local meta = minetest.get_meta(pos)
local states
@ -347,10 +350,14 @@ plg.ports_changed = function(pos, rule, newstate)
local portno = ({4, 1, nil, 3, 2})[3 + rule.x + 2*rule.z]
states[portno] = (newstate == "on")
meta:set_string("portstates",
local new_portstates =
(states[1] and "1" or "0") .. (states[2] and "1" or "0") ..
(states[3] and "1" or "0") .. (states[4] and "1" or "0")
)
if new_portstates ~= s then
meta:set_string("portstates", new_portstates)
return true
end
return false
end
plg.getports = function(pos) -- gets merged states of INPUT & OUTPUT