bug fixes for oop changes
This commit is contained in:
@ -1,7 +1,10 @@
|
||||
|
||||
return function(gate)
|
||||
gate.lastTickChanged = 0
|
||||
gate.listenState = "wait"
|
||||
gate.bitsReceived = 0
|
||||
gate.valReceived = 0
|
||||
Gate.initdata(gate)
|
||||
local gatedata = Gate.getdata(gate)
|
||||
|
||||
gatedata.lastTickChanged = 0
|
||||
gatedata.listenState = "wait"
|
||||
gatedata.bitsReceived = 0
|
||||
gatedata.valReceived = 0
|
||||
end
|
||||
|
@ -1,27 +1,29 @@
|
||||
|
||||
local function getBit(gate, val)
|
||||
local gatedata = Gate.getdata(gate)
|
||||
|
||||
--print("get bit", val)
|
||||
if gate.listenState=="wait" then
|
||||
if gatedata.listenState=="wait" then
|
||||
if val==1 then
|
||||
gate.listenState = "getbits"
|
||||
gate.bitsReceived = 0
|
||||
gatedata.listenState = "getbits"
|
||||
gatedata.bitsReceived = 0
|
||||
--print("", "state = listen")
|
||||
end
|
||||
elseif gate.listenState=="getbits" then
|
||||
gate.valReceived = gate.valReceived + math.pow(2, textbrick2_bitsNeeded-1-gate.bitsReceived)*val
|
||||
gate.bitsReceived = gate.bitsReceived+1
|
||||
elseif gatedata.listenState=="getbits" then
|
||||
gatedata.valReceived = gatedata.valReceived + math.pow(2, textbrick2_bitsNeeded-1-gatedata.bitsReceived)*val
|
||||
gatedata.bitsReceived = gatedata.bitsReceived+1
|
||||
|
||||
--print("", "append", gate.bitsReceived-1, val)
|
||||
--print("", "append", gatedata.bitsReceived-1, val)
|
||||
|
||||
if gate.bitsReceived==textbrick2_bitsNeeded then
|
||||
if gatedata.bitsReceived==textbrick2_bitsNeeded then
|
||||
|
||||
gate.listenState = "terminate"
|
||||
gatedata.listenState = "terminate"
|
||||
end
|
||||
elseif gate.listenState=="terminate" then
|
||||
elseif gatedata.listenState=="terminate" then
|
||||
if val==1 then
|
||||
--print("", "terminate")
|
||||
|
||||
local printid = gate.valReceived
|
||||
local printid = gatedata.valReceived
|
||||
local printname = textbrick2_idxToPrint[printid]
|
||||
|
||||
Gate.cb(gate, printname)
|
||||
@ -29,29 +31,31 @@ local function getBit(gate, val)
|
||||
--print("", "set print", string.format("%02x", printid), printname)
|
||||
end
|
||||
|
||||
gate.listenState = "wait"
|
||||
gatedata.listenState = "wait"
|
||||
|
||||
gate.bitsReceived = 0
|
||||
gate.valReceived = 0
|
||||
gatedata.bitsReceived = 0
|
||||
gatedata.valReceived = 0
|
||||
end
|
||||
end
|
||||
|
||||
local function changeTo(gate, val)
|
||||
local gatedata = Gate.getdata(gate)
|
||||
|
||||
local tick = Gate.gettick(gate)
|
||||
local ticks = tick-gate.lastTickChanged
|
||||
local ticks = tick-gatedata.lastTickChanged
|
||||
|
||||
local bits = math.min(ticks, 10)
|
||||
for i = 1, bits do
|
||||
getBit(gate, val)
|
||||
end
|
||||
|
||||
gate.lastTickChanged = tick
|
||||
gatedata.lastTickChanged = tick
|
||||
end
|
||||
|
||||
return function(gate)
|
||||
if Gate.getportisrising(gate, 1) then
|
||||
changeTo(gate, 0)
|
||||
elseif Gate.getportisfalling(gate, 2) then
|
||||
elseif Gate.getportisfalling(gate, 1) then
|
||||
changeTo(gate, 1)
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user