mirror of
https://github.com/Kiritow/OpenComputerScripts.git
synced 2024-03-22 13:10:46 +08:00
Add Train Report Program
This commit is contained in:
parent
e0c3a48cb2
commit
03a98233e8
|
@ -337,6 +337,8 @@ function CreateEventBus()
|
|||
-- Enable using t:listen(...)
|
||||
listen=EventBusListen,
|
||||
next=GetNextEvent,
|
||||
close=DestroyEventBus,
|
||||
-- Deprecated
|
||||
reset=DestroyEventBus
|
||||
}
|
||||
end
|
||||
|
|
45
train_report_watcher.lua
Normal file
45
train_report_watcher.lua
Normal file
|
@ -0,0 +1,45 @@
|
|||
require("libevent")
|
||||
require("util")
|
||||
local serialization=require("serialization")
|
||||
|
||||
--- Auto configured
|
||||
local t=proxy("tunnel")
|
||||
local wc=proxy("digital_detector")
|
||||
|
||||
--- Manunal configure
|
||||
local report_name="SL-1-1"
|
||||
|
||||
local function main()
|
||||
if(type(t)=="nil") then
|
||||
error("Tunnel card not found.")
|
||||
end
|
||||
if(type(wc)=="nil") then
|
||||
error("Digital detector not found.")
|
||||
end
|
||||
|
||||
local bus=CreateEventBus()
|
||||
bus:listen("minecart")
|
||||
bus:listen("interrupted")
|
||||
|
||||
while true do
|
||||
local e=bus:next()
|
||||
if(e.event=="interrupted") then
|
||||
break
|
||||
elseif(e.event=="minecart") then
|
||||
local tb={}
|
||||
tb.type=e.minecartType
|
||||
tb.dest=e.destination
|
||||
t.send("TrainReport",serialization.serialize(tb))
|
||||
print("Train:",e.minecartType,e.destination)
|
||||
end
|
||||
end
|
||||
|
||||
bus:reset()
|
||||
end
|
||||
|
||||
print("Train Report Watcher Started!")
|
||||
print("Author: Kiritow")
|
||||
print("StationName: ",report_name)
|
||||
print("Press Ctrl+C to stop program.")
|
||||
main()
|
||||
print("Program stopped.")
|
Loading…
Reference in New Issue
Block a user