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

@ -43,13 +43,16 @@ local rules = {
------------------
-- These helpers are required to set the port states of the luacontroller
-- Updates the real port states according to the signal change.
-- Returns whether the real port states actually changed.
local function update_real_port_states(pos, rule_name, new_state)
local meta = minetest.get_meta(pos)
if rule_name == nil then
meta:set_int("real_portstates", 1)
return
return true
end
local n = meta:get_int("real_portstates") - 1
local real_portstates = meta:get_int("real_portstates")
local n = real_portstates - 1
local L = {}
for i = 1, 4 do
L[i] = n % 2
@ -66,12 +69,12 @@ local function update_real_port_states(pos, rule_name, new_state)
local port = pos_to_side[rule_name.x + (2 * rule_name.z) + 3]
L[port] = (new_state == "on") and 1 or 0
end
meta:set_int("real_portstates",
1 +
1 * L[1] +
2 * L[2] +
4 * L[3] +
8 * L[4])
local new_portstates = 1 + 1 * L[1] + 2 * L[2] + 4 * L[3] + 8 * L[4]
if new_portstates ~= real_portstates then
meta:set_int("real_portstates", new_portstates)
return true
end
return false
end
@ -826,8 +829,9 @@ for d = 0, 1 do
effector = {
rules = input_rules[cid],
action_change = function (pos, _, rule_name, new_state)
update_real_port_states(pos, rule_name, new_state)
run(pos, {type=new_state, pin=rule_name})
if update_real_port_states(pos, rule_name, new_state) then
run(pos, {type=new_state, pin=rule_name})
end
end,
},
receptor = {