mirror of
https://github.com/Kiritow/OpenComputerScripts.git
synced 2024-03-22 13:10:46 +08:00
Update Station 2/3 Program. Add Debug output
This commit is contained in:
parent
8b69b13d85
commit
2ddca1e9d1
|
@ -51,6 +51,24 @@ local mid_time = 0
|
||||||
local ab_exit_time = 0
|
local ab_exit_time = 0
|
||||||
local ba_exit_time = 0
|
local ba_exit_time = 0
|
||||||
|
|
||||||
|
-- Debug Output
|
||||||
|
local dprint = print
|
||||||
|
|
||||||
|
local function debugClearOutput()
|
||||||
|
if(dprint ~= nil) then
|
||||||
|
os.execute("clear")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local function debugOutputInfo()
|
||||||
|
dprint("ab_st",ab_st,"ab_sr",ab_sr,"ba_st",ba_st,"ba_sr",ba_sr,"ab_lin",ab_lin,"ab_lout",ab_lout,"ba_lin",ba_lin,"ba_lout",ba_lout)
|
||||||
|
dprint("mid_direction",mid_direction,"ab_station_time",ab_station_time,"ba_station_time",ba_station_time,"mid_time",mid_time,"ab_exit_time",ab_exit_time,"ba_exit_time",ba_exit_time)
|
||||||
|
end
|
||||||
|
|
||||||
|
local function debugValueInfo()
|
||||||
|
dprint("ab_ko",ab_ko,"ab_m",ab_m,"ab_ks",ab_ks,"mid_ka",mid_ka,"ba_ko",ba_ko,"ba_m",ba_m,"ba_ks",ba_ks,"mid_kb",mid_kb)
|
||||||
|
end
|
||||||
|
|
||||||
--[[
|
--[[
|
||||||
Internal Functions
|
Internal Functions
|
||||||
]]
|
]]
|
||||||
|
@ -59,12 +77,21 @@ local function doInit()
|
||||||
updateRedstoneOutput()
|
updateRedstoneOutput()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function doCheck()
|
||||||
|
if(redin1==nil or redin2==nil or redout1==nil or redout2==nil) then
|
||||||
|
print("Redstone Configure")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
-- Main Program
|
-- Main Program
|
||||||
local function main()
|
local function main()
|
||||||
|
doCheck()
|
||||||
doInit()
|
doInit()
|
||||||
while true do
|
while true do
|
||||||
|
debugClearOutput()
|
||||||
-- Flush input
|
-- Flush input
|
||||||
updateRedstoneInput()
|
updateRedstoneInput()
|
||||||
|
debugOutputInfo()
|
||||||
-- Update status
|
-- Update status
|
||||||
if (ab_station_time > 0) then
|
if (ab_station_time > 0) then
|
||||||
ab_station_time = ab_station_time + 1
|
ab_station_time = ab_station_time + 1
|
||||||
|
@ -92,15 +119,18 @@ local function main()
|
||||||
if (ab_st > 0) then -- New incoming bus from A to B
|
if (ab_st > 0) then -- New incoming bus from A to B
|
||||||
if (ab_sr > 0) then -- This bus want to stop
|
if (ab_sr > 0) then -- This bus want to stop
|
||||||
if (ab_station_time == 0) then -- If AB Station is free
|
if (ab_station_time == 0) then -- If AB Station is free
|
||||||
|
dprint("A-->B Train In")
|
||||||
ab_ko = 15 -- enable to allow incoming
|
ab_ko = 15 -- enable to allow incoming
|
||||||
ab_ks = 0 -- disable to let it stop
|
ab_ks = 0 -- disable to let it stop
|
||||||
ab_m = 0 -- disable to allow incoming to station
|
ab_m = 0 -- disable to allow incoming to station
|
||||||
ab_station_time = 1 -- Start Time Counter
|
ab_station_time = 1 -- Start Time Counter
|
||||||
else -- AB Station is not free
|
else -- AB Station is not free
|
||||||
-- This train should wait outside the station
|
-- This train should wait outside the station
|
||||||
|
dprint("A-->B Train Pending")
|
||||||
end
|
end
|
||||||
else -- This bus want to pass by
|
else -- This bus want to pass by
|
||||||
if (mid_time == 0) then -- Mid is free
|
if (mid_time == 0) then -- Mid is free
|
||||||
|
dprint("A-->Mid Train In")
|
||||||
ab_ko = 15 -- enable to allow incoming
|
ab_ko = 15 -- enable to allow incoming
|
||||||
ab_m = 15 -- enable motor to let it pass.
|
ab_m = 15 -- enable motor to let it pass.
|
||||||
mid_ka = 15 -- enable switch from A
|
mid_ka = 15 -- enable switch from A
|
||||||
|
@ -108,6 +138,7 @@ local function main()
|
||||||
mid_direction = "ab"
|
mid_direction = "ab"
|
||||||
mid_time = 1 -- Start time counter
|
mid_time = 1 -- Start time counter
|
||||||
else -- Mid is busy
|
else -- Mid is busy
|
||||||
|
dprint("A-->Mid Train Pending")
|
||||||
-- This train should wait outside the station
|
-- This train should wait outside the station
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -116,15 +147,18 @@ local function main()
|
||||||
if (ba_st > 0) then -- New incoming bus from B to A
|
if (ba_st > 0) then -- New incoming bus from B to A
|
||||||
if (ba_sr > 0) then -- This bus want to stop
|
if (ba_sr > 0) then -- This bus want to stop
|
||||||
if (ba_station_time == 0) then -- If BA Station is free
|
if (ba_station_time == 0) then -- If BA Station is free
|
||||||
|
dprint("B-->A Train In")
|
||||||
ba_ko = 15 -- enable to allow incoming
|
ba_ko = 15 -- enable to allow incoming
|
||||||
ba_ks = 0 -- disable to let it stop
|
ba_ks = 0 -- disable to let it stop
|
||||||
ba_m = 0 -- disable to allow incoming to station
|
ba_m = 0 -- disable to allow incoming to station
|
||||||
ba_station_time = 1 -- Start Time Counter
|
ba_station_time = 1 -- Start Time Counter
|
||||||
else -- BA Station is not free
|
else -- BA Station is not free
|
||||||
-- This train should wait outside the station
|
-- This train should wait outside the station
|
||||||
|
dprint("B-->A Train Pending")
|
||||||
end
|
end
|
||||||
else -- This bus want to pass by
|
else -- This bus want to pass by
|
||||||
if (mid_time == 0) then -- Mid is free
|
if (mid_time == 0) then -- Mid is free
|
||||||
|
dprint("B-->Mid Train In")
|
||||||
ba_ko = 15 -- enable to allow incoming
|
ba_ko = 15 -- enable to allow incoming
|
||||||
ba_m = 15 -- enable motor to let it pass.
|
ba_m = 15 -- enable motor to let it pass.
|
||||||
mid_ka = 0
|
mid_ka = 0
|
||||||
|
@ -132,6 +166,7 @@ local function main()
|
||||||
mid_direction = "ba"
|
mid_direction = "ba"
|
||||||
mid_time = 1
|
mid_time = 1
|
||||||
else -- Mid is busy
|
else -- Mid is busy
|
||||||
|
dprint("B-->Mid Train Pending")
|
||||||
-- This train should wait outside the station
|
-- This train should wait outside the station
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -141,19 +176,23 @@ local function main()
|
||||||
-- Judge which train should pass.
|
-- Judge which train should pass.
|
||||||
if (ab_station_time > 16 and (mid_time > 0 and mid_direction == "ab")) then -- Two Trains
|
if (ab_station_time > 16 and (mid_time > 0 and mid_direction == "ab")) then -- Two Trains
|
||||||
if (ab_station_time > mid_time) then -- StationTrain wait longer.
|
if (ab_station_time > mid_time) then -- StationTrain wait longer.
|
||||||
|
dprint("A-->B Train Out")
|
||||||
ab_station_time = 0 -- Stop counter
|
ab_station_time = 0 -- Stop counter
|
||||||
ab_ks = 15 -- enable swith to let it go
|
ab_ks = 15 -- enable swith to let it go
|
||||||
ab_exit_time = 1
|
ab_exit_time = 1
|
||||||
else -- MidTrain wait longer
|
else -- MidTrain wait longer
|
||||||
|
dprint("Mid-->B Train out")
|
||||||
mid_time = 0 -- Stop Counter
|
mid_time = 0 -- Stop Counter
|
||||||
mid_kb = 15
|
mid_kb = 15
|
||||||
ab_exit_time = 1
|
ab_exit_time = 1
|
||||||
end
|
end
|
||||||
elseif (ab_station_time > 16) then --Only Station Train
|
elseif (ab_station_time > 16) then --Only Station Train
|
||||||
|
dprint("A-->B Train Out")
|
||||||
ab_station_time = 0
|
ab_station_time = 0
|
||||||
ab_ks = 15
|
ab_ks = 15
|
||||||
ab_exit_time = 1
|
ab_exit_time = 1
|
||||||
elseif (mid_time > 0 and mid_direction == "ab") then -- Only Mid Train
|
elseif (mid_time > 0 and mid_direction == "ab") then -- Only Mid Train
|
||||||
|
dprint("Mid-->B Train Out")
|
||||||
mid_time = 0
|
mid_time = 0
|
||||||
mid_kb = 15
|
mid_kb = 15
|
||||||
ab_exit_time = 1
|
ab_exit_time = 1
|
||||||
|
@ -164,29 +203,36 @@ local function main()
|
||||||
-- Judge which train should pass.
|
-- Judge which train should pass.
|
||||||
if (ba_station_time > 16 and (mid_time > 0 and mid_direction == "ba")) then -- Two Trains
|
if (ba_station_time > 16 and (mid_time > 0 and mid_direction == "ba")) then -- Two Trains
|
||||||
if (ba_station_time > mid_time) then -- StationTrain wait longer.
|
if (ba_station_time > mid_time) then -- StationTrain wait longer.
|
||||||
|
dprint("B-->A Train Out")
|
||||||
ba_station_time = 0 -- Stop counter
|
ba_station_time = 0 -- Stop counter
|
||||||
ba_ks = 15 -- enable swith to let it go
|
ba_ks = 15 -- enable swith to let it go
|
||||||
ba_exit_time = 1
|
ba_exit_time = 1
|
||||||
else -- MidTrain wait longer
|
else -- MidTrain wait longer
|
||||||
|
dprint("Mid-->A Train Out")
|
||||||
mid_time = 0 -- Stop Counter
|
mid_time = 0 -- Stop Counter
|
||||||
mid_ka = 15
|
mid_ka = 15
|
||||||
ba_exit_time = 1
|
ba_exit_time = 1
|
||||||
end
|
end
|
||||||
elseif (ba_station_time > 16) then --Only Station Train
|
elseif (ba_station_time > 16) then --Only Station Train
|
||||||
|
dprint("B-->A Train Out")
|
||||||
ba_station_time = 0
|
ba_station_time = 0
|
||||||
ba_ks = 15
|
ba_ks = 15
|
||||||
ba_exit_time = 1
|
ba_exit_time = 1
|
||||||
elseif (mid_time > 0 and mid_direction == "ba") then -- Only Mid Train
|
elseif (mid_time > 0 and mid_direction == "ba") then -- Only Mid Train
|
||||||
|
dprint("Mid-->A Train Out")
|
||||||
mid_time = 0
|
mid_time = 0
|
||||||
mid_ka = 15
|
mid_ka = 15
|
||||||
ba_exit_time = 1
|
ba_exit_time = 1
|
||||||
end -- No train
|
end -- No train
|
||||||
end
|
end
|
||||||
|
|
||||||
|
debugValueInfo()
|
||||||
|
|
||||||
-- Set output
|
-- Set output
|
||||||
updateRedstoneOutput()
|
updateRedstoneOutput()
|
||||||
|
|
||||||
-- Sleep for next loop
|
-- Sleep for next loop
|
||||||
|
dprint("==========")
|
||||||
os.sleep(0.5)
|
os.sleep(0.5)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue
Block a user