mirror of
https://github.com/Kiritow/OpenComputerScripts.git
synced 2024-03-22 13:10:46 +08:00
update station 2/4 program
This commit is contained in:
parent
de7f462a93
commit
2114bc31ac
124
station_2_4.lua
124
station_2_4.lua
|
@ -101,6 +101,12 @@ local ab_timerid_1,ab_time_1
|
||||||
local ab_timerid_2,ab_time_2
|
local ab_timerid_2,ab_time_2
|
||||||
local ab_timerid_out,ab_time_out
|
local ab_timerid_out,ab_time_out
|
||||||
|
|
||||||
|
local ba_available_1=true
|
||||||
|
local ba_available_2=true
|
||||||
|
local ba_timerid_1,ba_time_1
|
||||||
|
local ba_timerid_2,ba_time_2
|
||||||
|
local ba_timerid_out,ba_time_out
|
||||||
|
|
||||||
local ebus=Queue.new()
|
local ebus=Queue.new()
|
||||||
|
|
||||||
local function doInit()
|
local function doInit()
|
||||||
|
@ -108,6 +114,8 @@ local function doInit()
|
||||||
function()
|
function()
|
||||||
ebus:push("stop")
|
ebus:push("stop")
|
||||||
end))
|
end))
|
||||||
|
|
||||||
|
--- AB
|
||||||
train_delegator("ab_st",
|
train_delegator("ab_st",
|
||||||
function(from,to)
|
function(from,to)
|
||||||
if(from<to) then
|
if(from<to) then
|
||||||
|
@ -135,6 +143,35 @@ local function doInit()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
)
|
)
|
||||||
|
|
||||||
|
--- BA
|
||||||
|
train_delegator("ba_st",
|
||||||
|
function(from,to)
|
||||||
|
if(from<to) then
|
||||||
|
ebus:push("ba_new_train")
|
||||||
|
else
|
||||||
|
ebus:push("ba_train_in")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
)
|
||||||
|
train_delegator("ba_ins1",
|
||||||
|
function(from,to)
|
||||||
|
if(from<to) then
|
||||||
|
ebus:push("ba_ins1_ready")
|
||||||
|
else
|
||||||
|
ebus:push("ba_ins1_leave")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
)
|
||||||
|
train_delegator("ba_ins2",
|
||||||
|
function(from,to)
|
||||||
|
if(from<to) then
|
||||||
|
ebus:push("ba_ins2_ready")
|
||||||
|
else
|
||||||
|
ebus:push("ba_ins2_leave")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function doCleanUp()
|
local function doCleanUp()
|
||||||
|
@ -163,6 +200,7 @@ local function TCSMain()
|
||||||
os.sleep(0.5) -- No event, delay for more info
|
os.sleep(0.5) -- No event, delay for more info
|
||||||
elseif(ev=="stop") then
|
elseif(ev=="stop") then
|
||||||
running=false
|
running=false
|
||||||
|
--- AB
|
||||||
elseif(ev=="ab_new_train") then -- AB New Train
|
elseif(ev=="ab_new_train") then -- AB New Train
|
||||||
local act=false
|
local act=false
|
||||||
if(readdevice("ab_sr")>0) then -- This train will coming into station
|
if(readdevice("ab_sr")>0) then -- This train will coming into station
|
||||||
|
@ -213,15 +251,12 @@ local function TCSMain()
|
||||||
if(ab_time_out==5) then
|
if(ab_time_out==5) then
|
||||||
ebus:push("ab_time_out_needstop")
|
ebus:push("ab_time_out_needstop")
|
||||||
end
|
end
|
||||||
end)
|
end,-1)
|
||||||
|
|
||||||
enabledevice("ab_k1")
|
enabledevice("ab_k1")
|
||||||
else
|
else
|
||||||
ebus:push(ev)
|
ebus:push(ev)
|
||||||
end
|
end
|
||||||
elseif(ev=="ab_time_out_needstop") then
|
|
||||||
RemoveTimer(ab_timerid_out)
|
|
||||||
ab_time_out=0
|
|
||||||
elseif(ev=="ab_ins2_ready") then
|
elseif(ev=="ab_ins2_ready") then
|
||||||
if(ab_time_out==0 and ab_time_2>ab_time_1 and readdevice("ab_lout")>0) then
|
if(ab_time_out==0 and ab_time_2>ab_time_1 and readdevice("ab_lout")>0) then
|
||||||
RemoveTimer(ab_timerid_2)
|
RemoveTimer(ab_timerid_2)
|
||||||
|
@ -235,12 +270,91 @@ local function TCSMain()
|
||||||
if(ab_time_out==5) then
|
if(ab_time_out==5) then
|
||||||
ebus:push("ab_time_out_needstop")
|
ebus:push("ab_time_out_needstop")
|
||||||
end
|
end
|
||||||
end)
|
end,-1)
|
||||||
|
|
||||||
enabledevice("ab_k2")
|
enabledevice("ab_k2")
|
||||||
else
|
else
|
||||||
ebus:push(ev)
|
ebus:push(ev)
|
||||||
end
|
end
|
||||||
|
--- BA
|
||||||
|
elseif(ev=="ba_new_train") then -- AB New Train
|
||||||
|
local act=false
|
||||||
|
if(readdevice("ba_sr")>0) then -- This train will coming into station
|
||||||
|
if(ba_available_1) then
|
||||||
|
ba_available_1=false
|
||||||
|
act=true
|
||||||
|
ba_time_1=0
|
||||||
|
ba_timerid_1=AddTimer(1,
|
||||||
|
function()
|
||||||
|
ba_time_1=ba_time_1+1
|
||||||
|
end,
|
||||||
|
-1)
|
||||||
|
disabledevice("ba_m")
|
||||||
|
disabledevice("ba_k1")
|
||||||
|
end
|
||||||
|
else -- This train will pass by station
|
||||||
|
if(ba_available_2) then
|
||||||
|
ba_available_2=false
|
||||||
|
act=true
|
||||||
|
ba_time_2=0
|
||||||
|
ba_timerid_2=AddTimer(1,
|
||||||
|
function()
|
||||||
|
ba_time_2=ba_time_2+1
|
||||||
|
end,
|
||||||
|
-1)
|
||||||
|
enabledevice("ba_m")
|
||||||
|
disabledevice("ba_k2")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if(act) then
|
||||||
|
enabledevice("ba_ko")
|
||||||
|
os.sleep(0.25)
|
||||||
|
disabledevice("ba_ko")
|
||||||
|
else -- Push Event back
|
||||||
|
ebus:push(ev)
|
||||||
|
end
|
||||||
|
elseif(ev=="ba_ins1_ready") then
|
||||||
|
if(ba_time_out==0 and ba_time_1>6 and ba_time_1>ba_time_2 and readdevice("ba_lout")>0) then
|
||||||
|
RemoveTimer(ba_timerid_1)
|
||||||
|
ba_time_1=0
|
||||||
|
ba_available_1=true
|
||||||
|
|
||||||
|
ba_time_out=1
|
||||||
|
ba_timerid_out=AddTimer(1,
|
||||||
|
function()
|
||||||
|
ba_time_out=ba_time_out+1
|
||||||
|
if(ba_time_out==5) then
|
||||||
|
ebus:push("ba_time_out_needstop")
|
||||||
|
end
|
||||||
|
end,-1)
|
||||||
|
|
||||||
|
enabledevice("ba_k1")
|
||||||
|
else
|
||||||
|
ebus:push(ev)
|
||||||
|
end
|
||||||
|
elseif(ev=="ba_ins2_ready") then
|
||||||
|
if(ba_time_out==0 and ba_time_2>ba_time_1 and readdevice("ba_lout")>0) then
|
||||||
|
RemoveTimer(ba_timerid_2)
|
||||||
|
ba_time_2=0
|
||||||
|
ba_available_2=true
|
||||||
|
|
||||||
|
ba_time_out=1
|
||||||
|
ba_timerid_out=AddTimer(1,
|
||||||
|
function()
|
||||||
|
ba_time_out=ba_time_out+1
|
||||||
|
if(ba_time_out==5) then
|
||||||
|
ebus:push("ba_time_out_needstop")
|
||||||
|
end
|
||||||
|
end,-1)
|
||||||
|
|
||||||
|
enabledevice("ba_k2")
|
||||||
|
else
|
||||||
|
ebus:push(ev)
|
||||||
|
end
|
||||||
|
elseif(ev=="ba_time_out_needstop") then
|
||||||
|
RemoveTimer(ba_timerid_out)
|
||||||
|
ba_time_out=0
|
||||||
else -- Ignore unknown event
|
else -- Ignore unknown event
|
||||||
-- Do nothing
|
-- Do nothing
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue
Block a user