Fix libevent, add transport system.

This commit is contained in:
Kirigaya Kazuto 2018-01-04 13:44:40 +08:00
parent a67752ac76
commit 8b0d3e213a
4 changed files with 101 additions and 3 deletions

View File

@ -99,7 +99,7 @@ local function doEventTranslate(raw_event)
t["targetAddress"]=c
t["data"]=d
t["metadata"]=e
elseif(name=="minecraft") then
elseif(name=="minecart") then
t["detectorAddress"]=a
t["minecartType"]=b
t["minecartName"]=c
@ -151,8 +151,12 @@ function RemoveEventListener(ListenerID)
end
function WaitEvent(EventName)
checkstring(EventName)
return doEventTranslate(table.pack(event.pull(EventName)))
if(EventName~=nil) then
checkstring(EventName)
return doEventTranslate(table.pack(event.pull(EventName)))
else
return doEventTranslate(table.pack(event.pull()))
end
end
function WaitEventFor(EventName,TimeOut)

9
transport_center.lua Normal file
View File

@ -0,0 +1,9 @@
local component=require("component")
local event=require("event")
require("util")
local function main()
end

85
transport_client.lua Normal file
View File

@ -0,0 +1,85 @@
local component=require("component")
local event=require("event")
require("util")
--- Auto Configure
local digital_controller = proxy("digital_controller_box")
local digital_receiver = proxy("digital_receiver_box")
local transposer = proxy("transposer")
local routing_track = proxy("routing_track")
--- Manually Configure
local route_in_ab = proxy("routing_switch","6")
local route_in_ba = proxy("routing_switch","a")
local route_out = proxy("routing_switch","1")
-- Value: 1 Green 2 Blinking Yello 3 Yello 4 Blinking Red 5 Red
local green=1
local byello=2
local yello=3
local bred=4
local red=5
local function setSignal(name,value)
digital_controller.setAspect(name,value)
end
local function checkDevice()
local function doCheckDevice(device)
if(device==nil) then
error("Some device is nil. Please double check your configure.")
end
end
doCheckDevice(digital_controller)
doCheckDevice(digital_receiver)
doCheckDevice(transposer)
doCheckDevice(routing_track)
doCheckDevice(route_in_ab)
doCheckDevice(route_in_ba)
doCheckDevice(route_out)
local t=digital_controller.getSignalNames()
local function checkSigName(name)
local found=false
for k,v in pairs(t) do
if(v==name) then
return true
end
end
error("CheckSigName: Failed to check signal: " .. name)
end
checkSigName("Cart_Ctrl")
checkSigName("Lamp")
checkSigName("Box_Ctrl")
t=digital_receiver.getSignalNames()
checkSigName("Cart_Ready")
print("Check device pass.")
end
local function resetDevice()
digital_controller.setEveryAspect(red)
setSignal("Lamp",green)
route_in_ab.setRoutingTable({})
route_in_ba.setRoutingTable({})
route_out.setRoutingTable({})
print("Device reset done.")
end
local function main()
checkDevice()
resetDevice()
while true do
print("Please put your things in the box. Then press ENTER.")
local e=event.pull(e)
end
end
main()

0
transport_repo.lua Normal file
View File