From c403627bf221e0625374bf5e0ba4aa69cfe5e0c1 Mon Sep 17 00:00:00 2001 From: kiritow <1362050620@qq.com> Date: Wed, 25 Oct 2017 15:30:43 +0800 Subject: [PATCH] Add station 2/4 program --- station_2_4.lua | 112 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 112 insertions(+) create mode 100644 station_2_4.lua diff --git a/station_2_4.lua b/station_2_4.lua new file mode 100644 index 0000000..1002916 --- /dev/null +++ b/station_2_4.lua @@ -0,0 +1,112 @@ +--[[ + Station 2/4 Standard Schedule Program +]] + +require("libevent") +require("util") +require("checkarg") +require("queue") +local sides=require("sides") + +-- Config your update functions here (Do not change function name) +local redin1 = proxy("redstone", "") +local redin2 = proxy("redstone", "") +local redout1 = proxy("redstone", "") +local redout2 = proxy("redstone", "") + +-- Redirect Table +local redirect_tb= +{ + ["ab_st"]={redin1,sides.north}, + ["ab_sr"]={redin1,sides.east}, + ["ab_lout"]={redin1,sides.south}, + + ["ba_st"] = {redin2,sides.north}, + ["ba_sr"] = {redin2,sides.east}, + ["ba_lout"] = {redin2,sides.south}, + + ["ab_ko"]={redout1,sides.north}, + ["ab_m"]={redout1,sides.east}, + ["ab_k1"]={redout1,sides.south}, + ["ab_k2"]={redout1,sides.west}, + + ["ba_ko"]={redout2,sides.north}, + ["ba_m"]={redout2,sides.east}, + ["ba_k1"]={redout2,sides.south}, + ["ba_k2"]={redout2,sides.west}, + + ["last_unused"]={"unused",sides.north} +} + +local function getNameFromRaw(Device,Side) + for k,t in pairs(redirect_tb) do + if(t[1].address == Device and t[2]==Side) then + return k + end + end + + return nil +end + +local function getRawFromName(Name) + return redirect_tb[Name][1],redirect_tb[Name][2] +end + +local function enabledevice(Name) + local d, s = getRawFromName(Name) + if (d ~= nil and s ~= nil) then + d.setOutput(s, 15) + end +end + +local function disabledevice(Name) + local d, s = getRawFromName(Name) + if (d ~= nil and s ~= nil) then + d.setOutput(s, 0) + end +end + +local evl=Queue.new() + +local function train_delegator(Name,callback_func) + local ret=AddEventListener("redstone_changed", + function(ev,dev,sd,from,to) + if(getNameFromRaw(dev,sd)==Name) then + callback_func(from,to) + end + end) + print("Delegator: ",ret) + evl:push(ret) +end + +local function doInit() + train_delegator("ab_st", + function(from,to) + if(from