Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local basalt = require("basalt")
- local modem = peripheral.find("modem") or error("No modem attached", 0)
- terminate = false;
- connected = false;
- address = 0
- replyAddress = 23
- password = "tardim-1"
- modem.open(replyAddress)
- print("boot")
- function listen()
- while not terminate do
- local event, par1, par2, par3, par4, par5 = os.pullEvent()
- if event == "modem_message" then
- local side = par1
- local channel = par2
- local replyChannel = par3
- local message = par4
- local distance = par5
- messageReceived(side, channel, replyChannel, message, distance)
- end
- sleep(0.1)
- end
- end
- function messageReceived(side, channel, replyChannel, message, distance)
- if message[1] == "ok" then
- address = tonumber(message[2])
- sleep(0.1)
- modem.transmit(address, replyAddress, {"pass", password})
- end
- if message[1] == "correct" then
- connected = true
- updateConnection("Connected")
- end
- if message[1] == "status" then
- updateStatus(message[2])
- updateFuel(message[3])
- end
- if message[1] == "location_set" then
- updateSummonStatus("Location Set")
- end
- if message[1] == "remat" then
- updateSummonStatus("Remat")
- end
- if message[1] == "demat" then
- updateSummonStatus("Demat")
- end
- if message[1] == "inFlight" then
- updateSummonStatus("Tardim is already in flight")
- end
- if message[1] == "landed" then
- updateSummonStatus("Tardim is already lannded")
- end
- end
- --> Now we want to create a base frame, we call the variable "main" - by default everything you create is visible. (you don't need to use :show())
- local main = basalt.createFrame()
- local buttonConnect = main:addButton()
- buttonConnect:setPosition(1, 1)
- buttonConnect:setSize(10, 1)
- buttonConnect:setText("Connect")
- local function connectButtonClick()
- modem.transmit(address, replyAddress, {"connect"})
- end
- buttonConnect:onClick(connectButtonClick)
- -- Connection field
- local connectionLabel = main:addLabel()
- connectionLabel:setPosition(1, 2)
- connectionLabel:setSize(30, 1)
- connectionLabel:setText("Connection: Not connected")
- -- Status field
- local statusLabel = main:addLabel()
- statusLabel:setPosition(1, 3)
- statusLabel:setSize(30, 1)
- statusLabel:setText("Status: ")
- -- Fuel field
- local fuelLabel = main:addLabel()
- fuelLabel:setPosition(1, 4)
- fuelLabel:setSize(30, 1)
- fuelLabel:setText("Fuel: N/A")
- -- Coordinate input fields
- local xLabel = main:addLabel()
- xLabel:setPosition(1, 6)
- xLabel:setSize(5, 1)
- xLabel:setText("X:")
- local xInput = main:addInput()
- xInput:setPosition(7, 6)
- xInput:setSize(5, 1)
- xInput:setInputType("number")
- xInput:setDefaultText("0")
- xInput:onChange(function(self)
- xInputValue = tonumber(self:getValue())
- end)
- local yLabel = main:addLabel()
- yLabel:setPosition(1, 7)
- yLabel:setSize(5, 1)
- yLabel:setText("Y:")
- local yInput = main:addInput()
- yInput:setPosition(7, 7)
- yInput:setSize(5, 1)
- yInput:setInputType("number")
- yInput:setDefaultText("0")
- yInput:onChange(function(self)
- yInputValue = tonumber(self:getValue())
- end)
- local zLabel = main:addLabel()
- zLabel:setPosition(1, 8)
- zLabel:setSize(5, 1)
- zLabel:setText("Z:")
- local zInput = main:addInput()
- zInput:setPosition(7, 8)
- zInput:setSize(5, 1)
- zInput:setInputType("number")
- zInput:setDefaultText("0")
- zInput:onChange(function(self)
- zInputValue = tonumber(self:getValue())
- end)
- -- Remat button
- local rematButton = main:addButton()
- rematButton:setPosition(15, 6)
- rematButton:setSize(10, 1)
- rematButton:setText("Remat")
- local function rematButtonClick()
- if connected == true then
- modem.transmit(address, replyAddress, {"remat"})
- end
- end
- rematButton:onClick(rematButtonClick)
- -- Demat button
- local dematButton = main:addButton()
- dematButton:setPosition(15, 7)
- dematButton:setSize(10, 1)
- dematButton:setText("Demat")
- local function dematButtonClick()
- if connected == true then
- modem.transmit(address, replyAddress, {"demat"})
- end
- end
- dematButton:onClick(dematButtonClick)
- -- Summon Status field
- local summonStatusLabel = main:addLabel()
- summonStatusLabel:setPosition(1, 9)
- summonStatusLabel:setSize(30, 1)
- local confirmButton = main:addButton()
- confirmButton:setPosition(1, 11)
- confirmButton:setSize(10, 1)
- confirmButton:setText("Confirm")
- local function confirmButtonClick()
- if connected == true then
- if xInputValue and yInputValue and zInputValue then
- updateSummonStatus("Location send")
- modem.transmit(address, replyAddress, {"location", xInputValue, yInputValue, zInputValue})
- else
- updateSummonStatus("Please enter valid coordinates.")
- end
- end
- end
- confirmButton:onClick(confirmButtonClick)
- function updateStatus(status)
- statusLabel:setText("Status: " .. tostring(status))
- end
- function updateConnection(status)
- connectionLabel:setText("Connection: " .. status)
- end
- function updateFuel(fuel)
- fuelLabel:setText("Fuel: " .. fuel)
- end
- function updateSummonStatus(status)
- summonStatusLabel:setText(status)
- end
- function main_loop()
- basalt.autoUpdate()
- while true do
- end
- end
- function ping()
- while true do
- if connected == true then
- modem.transmit(address, replyAddress, {"status"})
- end
- sleep(2)
- end
- end
- parallel.waitForAll(listen, main_loop, ping)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement