From 4a13e93cb35e90b849eaa7831f1a3ae0762f30e3 Mon Sep 17 00:00:00 2001 From: kiritow <1362050620@qq.com> Date: Wed, 25 Oct 2017 22:19:12 +0800 Subject: [PATCH] Update station 2/4 program --- station_2_4.lua | 96 ++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 91 insertions(+), 5 deletions(-) diff --git a/station_2_4.lua b/station_2_4.lua index 1002916..7641940 100644 --- a/station_2_4.lua +++ b/station_2_4.lua @@ -11,6 +11,7 @@ local sides=require("sides") -- Config your update functions here (Do not change function name) local redin1 = proxy("redstone", "") local redin2 = proxy("redstone", "") +local redin3 = proxy("redstone", "") local redout1 = proxy("redstone", "") local redout2 = proxy("redstone", "") @@ -25,6 +26,12 @@ local redirect_tb= ["ba_sr"] = {redin2,sides.east}, ["ba_lout"] = {redin2,sides.south}, + -- ins: Inside station sensor + ["ab_ins1"] = {redin3,sides.north}, + ["ab_ins2"] = {redin3,sides.east}, + ["ba_ins1"] = {redin3,sides.south}, + ["ba_ins2"] = {redin3,sides.west}, + ["ab_ko"]={redout1,sides.north}, ["ab_m"]={redout1,sides.east}, ["ab_k1"]={redout1,sides.south}, @@ -66,6 +73,15 @@ local function disabledevice(Name) end end +local function readdevice(Name) + local d,s=getRawFromName(Name) + if(d~=nil and s~=nil) then + return d.getInput(s) + else + error("failed to read device input") + end +end + local evl=Queue.new() local function train_delegator(Name,callback_func) @@ -79,15 +95,38 @@ local function train_delegator(Name,callback_func) evl:push(ret) end +local ab_available_1=true +local ab_available_2=true +local ab_timerid_1,ab_time_1 +local ab_timerid_2,ab_time_2 + +local ebus=Queue.new() + local function doInit() train_delegator("ab_st", function(from,to) if(from0) then -- This train will coming into station + if(ab_available_1) then + ab_available_1=false + act=true + ab_time_1=0 + ab_timerid_1=AddTimer(1, + function() + ab_time_1=ab_time_1+1 + end, + -1) + end + else -- This train will pass by station + if(ab_available_2) then + ab_available_2=false + act=true + ab_time_2=0 + ab_timerid_2=AddTimer(1, + function() + ab_time_2=ab_time_2+1 + end, + -1) + end + end + + if(act) then + enabledevice("ab_ko") + os.sleep(0.25) + disabledevice("ab_ko") + else -- Push Event back + ebus:push(ev) + end + else -- Ignore unknown event + -- Do nothing + end + + end + doCleanUp() end