Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- Program name: Test turbines
- Version: v1.01
- Programmer: IronClaymore
- Company: IC-TECH
- Last update: 04/07/2014
- Description: just a test
- ]]--
- local loopTime = 0.5 -- Time between program loops, in seconds. You probably don't need to alter this value.
- -- The following are just empty arrays
- local monitorList = {}
- local monitorNames = {}
- local reactorList = {}
- local reactorNames = {}
- local turbineList = {}
- local turbineNames = {}
- ----------
- -- Basic side determination for wrapping
- function getDeviceSide(deviceType)
- deviceType = deviceType:lower()
- for i, side in pairs(rs.getSides()) do
- if (peripheral.isPresent(side)) then
- if (string.lower(peripheral.getType(side)) == deviceType) then
- return side;
- end
- end
- end
- return nil;
- end
- -- Peripheral wrapping function
- function wrapThis(thing, f)
- local wrapped = nil
- while wrapped == nil and f <= 100 do
- wrapped = peripheral.wrap(thing.."_"..f)
- f = f + 1
- end
- if wrapped == nil then
- side = getDeviceSide(thing)
- if side ~= nil then
- return peripheral.wrap(side)
- else
- return nil
- end
- else
- return wrapped
- end
- end
- print("Initializing program...",1,1);
- -- Creates a list of all connected devices, whether adjacent to the computer or connected with wired modems
- -- Wraps them too, which is nice
- local function getDevices(deviceType)
- local deviceName = nil
- local deviceIndex = 1
- local deviceList, deviceNames = {}, {}
- local peripheralList = peripheral.getNames()
- deviceType = deviceType:lower() -- because case matters and it's stupid and causes bugs and I hate it
- for peripheralIndex = 1, #peripheralList do
- if (string.lower(peripheral.getType(peripheralList[peripheralIndex])) == deviceType) then
- deviceNames[deviceIndex] = peripheralList[peripheralIndex]
- deviceList[deviceIndex] = peripheral.wrap(peripheralList[peripheralIndex])
- deviceIndex = deviceIndex + 1
- end
- end
- return deviceList, deviceNames
- end
- -- Check for and initialise monitors
- local function findMonitors()
- monitorList = {}
- monitorList, monitorNames = getDevices("monitor")
- if #monitorList == 0 then
- print("No monitors found. Please connect one and restart the program.")
- sleep(5)
- finished = true
- os.reboot()
- else
- for monitorIndex = 1, #monitorList do
- local monitor = nil
- monitor = monitorList[monitorIndex]
- end
- end
- end
- -- Check for and initialise turbines
- local function findTurbines()
- turbineList = {}
- turbineList, turbineNames = getDevices("BigReactors-Turbine")
- if #turbineList == 0 then
- print("No turbines found. Please install connect one or more and restart the program.")
- sleep(5)
- finished = true
- os.reboot()
- else
- for turbineIndex = 1, #turbineList do
- local turbine = nil
- turbine = turbineList[turbineIndex]
- end
- end
- end
- -- Print stuff to the centre of a monitor
- local function printCentre(str, posY, monitorIndex)
- local monitor = nil
- monitor = monitorList[monitorIndex]
- local width, height = monitor.getSize()
- monitor.setCursorPos(math.floor(width/2) - math.ceil(str:len()/2), posY)
- monitor.write(str)
- end
- -- Print stuff to the left side of a monitor
- local function printLeft(str, posY, monitorIndex)
- local monitor = nil
- monitor = monitorList[monitorIndex]
- local width, height = monitor.getSize()
- monitor.setCursorPos(2,posY)
- monitor.write(str)
- end
- -- Print stuff to the right side of a monitor
- local function printRight(str, posY, monitorIndex)
- local monitor = nil
- monitor = monitorList[monitorIndex]
- local width = monitor.getSize()
- monitor.setCursorPos(width - str:len()+1, posY)
- monitor.write(str)
- end
- -- Draw solid bar (paintutils only outputs to term, not monitor, which is why it needs an annoying redirect in there)
- local function drawBar(startX, startY, endX, endY, colour, monitorIndex)
- local monitor = nil
- monitor = monitorList[monitorIndex]
- term.redirect(monitor)
- paintutils.drawLine(startX, startY, endX, endY, colour)
- monitor.setBackgroundColor(colors.black)
- term.native()
- end
- -- Draw stuff on the bottom part of the monitors, which will be the same for all of them
- function drawBottomPart()
- local turbine = nil
- local onlineTurbine = 0
- local totalTurbineRF = 0
- local monitor, monitorIndex = nil, 1
- monitor = monitorList[monitorIndex]
- for turbineIndex = 1, #turbineList do
- turbine = turbineList[turbineIndex]
- if turbine.getConnected() then
- if turbine.getActive() then
- onlineTurbine = onlineTurbine + 1
- end
- totalTurbineRF = totalTurbineRF + turbine.getEnergyProducedLastTick()
- end
- end
- printLeft("Number of Turbines: ", 2, monitorIndex)
- printLeft(onlineTurbine, 3, monitorIndex)
- printLeft("Total power output: ", 4, monitorIndex)
- printLeft(math.floor(totalTurbineRF), 5, monitorIndex)
- end
- -- Main program
- function main()
- while not finished do
- findMonitors()
- findTurbines()
- drawBottomPart()
- sleep(loopTime)
- end
- end
- -- Event handler for exiting, editting and debugging
- function eventHandler()
- while not finished do
- event, arg1, arg2, arg3 = os.pullEvent()
- if event == "char" and not inManualMode then
- local ch = string.lower(arg1)
- if ch == "q" then
- finished = true
- elseif ch == "r" then
- finished = true
- os.reboot()
- end
- end
- end
- end
- while not finished do
- parallel.waitForAny(eventHandler, main)
- sleep(loopTime)
- end
- -- Returns control to the terminal if the program has an error or whatever
- term.clear()
- term.setCursorPos(1,1)
Advertisement
Add Comment
Please, Sign In to add comment