Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Turbine Monitor
- local t = peripheral.find("BigReactors-Turbine")
- local m = peripheral.find("monitor")
- function formatNumToString(val, sp, mod)
- local nStr = round(val, mod)
- nStr = tostring(nStr)
- nStr = string.rep(" ", sp - nStr:len())..nStr
- return nStr
- end --function formatString(val, sp)
- function round(num, i)
- local mult = 10^(i or 0)
- return math.floor(num * mult + 0.5) / mult
- end --function round(num, i)
- function rightJustify(w, sLen, mod)
- local x = math.floor(w) - math.ceil(sLen + mod)
- return x
- end --funtion rightJustify(w, sLen, mod)
- local function writeAt(text, x, y, foreCol, backCol)
- if foreCol then term.setTextColour(foreCol) end
- if backCol then term.setBackgroundColour(backCol) end
- if x or y then
- local curX, curY = term.getCursorPos()
- term.setCursorPos(x or curX, y or curY)
- end
- term.write(text)
- end --function writeAt(text, x, y, foreCol, backCol)
- local function drawScreen()
- local x, y = m.getSize()
- term.redirect(m)
- paintutils.drawLine(1, 1, x, 1, colors.green)
- paintutils.drawLine(1, y, x, y, colors.green)
- paintutils.drawLine(1, 1, 1, y, colors.green)
- paintutils.drawLine(x, 1, x, y, colors.green)
- writeAt("TURBINE 1", 9, 1, colors.black, colors.green)
- writeAt("Turbine:", 2, 3, colors.cyan, colors.black)
- writeAt("Turbine Speed:", 2, 4)
- writeAt("Power Output:", 2, 5)
- writeAt("Power Stored:", 2, 6)
- writeAt("Coil:", 2, 7)
- writeAt("NOT PRESENT", 13, 3, colors.red)
- end -- function drawScreen()
- function getTurbineStats()
- local tStats = {} --array matrix for turbine stats.
- tStats[1] = t.getRotorSpeed()
- tStats[2] = t.getEnergyStored()
- tStats[3] = t.getEnergyProducedLastTick()
- tStats[4] = t.getActive()
- tStats[5] = t.getInductorEngaged()
- return tStats --returns the array matrix of stored stats
- end --function getTurbineStats()
- function displayStats()
- local tStats = getTurbineStats() --gets turbine stats
- local w = 0
- local rpm = tStats[1]
- local eStor = tStats[2]
- local eProd = tStats[3]
- local act = tStats[4]
- local cEng = tStats[5]
- rpm = formatNumToString(rpm, 8, 1)
- eStor = formatNumToString(eStor, 8, 0)
- eProd = formatNumToString(eProd, 8, 0)
- term.redirect(m)
- local w = term.getSize()
- if act then -- turbine active/inactive display
- writeAt(" ACTIVE", 13, 3, colors.lime)
- else
- writeAt(" INACTIVE", 13, 3, colors.red)
- end -- if act then
- writeAt(rpm, rightJustify(w, rpm:len(), 1), 4, colors.white)
- writeAt(eProd, rightJustify(w, eProd:len(), 1), 5)
- writeAt(eStor, rightJustify(w, eStor:len(), 1), 6)
- if cEng then --coil engaged/disengaged display
- writeAt(" ENGAGED", 14, 7, colors.lime, colors.black)
- else
- writeAt("DISENGAGED", 14, 7, colors.red, colors.black)
- end --if cEng then
- end --function displayStats()
- m.clear()
- drawScreen()
- while true do
- getTurbineStats()
- displayStats()
- os.sleep(1)
- end -- while true do
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement