Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ---
- --- Generated by EmmyLua(https://github.com/EmmyLua)
- --- Created by cdbab.
- --- DateTime: 1/9/2025 7:11 AM
- ---
- ---
- print("running node")
- local basalt = require("basalt")
- local subnetStatusText = ""
- local sunbnetStatusColor = colors.red
- peripheral.find("modem", rednet.open)
- local delay = 120
- local authCode = 1111
- local subnetStatus = false
- local commAttempts = 0
- local maxCommAttempts = 5
- local cmdType = {AUTH = "authCode", CMD = "command", VAR = "var", ARG = "args"}
- local root = basalt.createFrame():setTheme({ButtonBG=colors.cyan, ButtonText=colors.white, FrameBG = colors.lightGray, FrameFG = colors.black})
- local timer = root:addTimer()
- local delayPanel = root:addFrame():setPosition(2,2):setSize("parent.w - 3", "parent.h / 2 - 3"):setBorder(colors.black)
- local debugPanel = root:addFrame():setPosition(2,"parent.h / 2 + 1"):setSize("parent.w - 3", "parent.h / 2 - 3"):setBorder(colors.black)
- local delayControl = delayPanel:addFrame():setPosition(2,2):setSize("parent.w - 2",5):setForeground(colors.black):setBorder(colors.white)
- local delaySetButton = delayControl:addButton():setText("Set Delay"):setVerticalAlign("center"):setHorizontalAlign("center"):setSize(11,1):setPosition("parent.w / 2 - 5", "parent.h - 1")
- local timeInput = delayControl:addInput():setInputType("number"):setDefaultText(tostring(delay)):setInputLimit(3):setSize(11,1):setPosition("parent.w / 2 - 5",2)
- local subnetControl = debugPanel:addFrame():setPosition(2,2):setSize("parent.w - 2",5):setForeground(colors.black):setBorder(colors.white)
- if subnetStatus then
- subnetStatusText = "Online"
- sunbnetStatusColor = colors.gray
- else
- subnetStatusText = "Offline"
- sunbnetStatusColor = colors.green
- end
- local subnetStatusTitleLabel = subnetControl:addLabel():setText("Subnet Status: "):setSize(15, 1):setPosition("parent.w / 2 - 6",2)
- local subnetStatusLabel = subnetControl:addLabel():setText(subnetStatusText):setSize(#subnetStatusText, 1):setPosition("parent.w / 2 - 3",3)
- local subnetToggleButton = subnetControl:addButton():setText("Start Subnet"):setSize(14,1):setBackground(sunbnetStatusColor):setPosition("parent.w / 2 - 6",4)
- local function fetchMsg()
- print("receiving message")
- local id, message = rednet.receive(nil, 5)
- if message == nil then
- error("Message received but was empty.",0)
- end
- if message[cmdType.AUTH] == authCode and message[cmdType.CMD] == "var" then
- return message[cmdType.ARG][1]
- else
- return false
- end
- end
- local function sendMsg(cmd, ...)
- local arg={...}
- commAttempts = commAttempts + 1
- if comAttempts == maxCommAttempts then
- error("Cannot communicate with controller. Controller might not be online")
- return
- end
- print("sending message")
- local response
- local msg = {}
- msg["authCode"] = authCode
- msg["command"] = cmd
- if #arg > 0 then
- msg["args"] = arg
- end
- rednet.broadcast(msg)
- response = fetchMsg()
- if response == false then
- sendMsg(cmd, ...)
- end
- return response
- end
- local function fetchInfo()
- -- add your logic here
- basalt.debug("Requesting Status!")
- subnetStatus = sendMsg("getSubnetStatus")
- delay = sendMsg("getDelay")
- timeInput:setDefaultText(tostring(delay))
- end
- timer:onCall(fetchInfo())
- :setTime(1, -1)
- :start()
- delaySetButton:onClick(function(self,event,button,x,y)
- --TODO set timer delay
- if(event=="mouse_click")and(button==1)then
- basalt.debug("Left mousebutton got clicked!")
- end
- end)
- subnetToggleButton:onClick(function(self,event,button,x,y)
- --TODO sub 10 seconds from timer delay
- if(event=="mouse_click")and(button==1)then
- basalt.debug("Left mousebutton got clicked!")
- end
- end)
- basalt.autoUpdate()
Advertisement
Add Comment
Please, Sign In to add comment