Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Setup
- local modem = peripheral.wrap("left")
- local mon = peripheral.wrap("bottom")
- local txChannel = 1410
- local rxChannel = 1400
- local room = "storage" --for how in the control room "production" or "storage"
- --Variables
- local data={}
- modem.open(rxChannel)
- mon.setTextScale(0.5)
- x, y = mon.getSize()
- --Functions
- function showMessage(line, message, sender)
- --mon.setTextScale(0.5)
- if sender == "RedNet" then
- mon.setCursorPos(1,line)
- mon.setTextColor( colors.lime)
- mon.write("RedNet")
- sleep (0.2)
- mon.setCursorPos(1,line)
- mon.clearLine()
- mon.setTextColor( colors.gray )
- mon.write("RedNet")
- end
- mon.setCursorPos(10,line)
- mon.write(" ")
- mon.setCursorPos(10,line)
- mon.setTextColor( colors.white )
- mon.write("message: "..message)
- end
- --Functions
- function drawCentered(line, text)
- mon.setCursorPos((x - string.len(text))/ 2, line)
- mon.write(text)
- end
- function drawAcross(line, char)
- mon.setCursorPos(1, line)
- for i = 1, x do
- mon.write(char)
- end
- end
- function drawPcBar(line, char, size)
- oldColor = mon.getTextColor()
- mon.setCursorPos(1, line)
- mon.clearLine()
- maxLengt = math.ceil(x * 0.8)
- sizeB = math.ceil(size*maxLengt/100)
- mon.setTextColor( colors.white )
- mon.setCursorPos(1, line)
- mon.write("[")
- mon.setCursorPos(2, line)
- if size < 25 then newColor = colors.red end
- if ((size < 75) and (size > 25)) then newColor = colors.orange end
- if size > 75 then newColor = colors.lime end
- mon.setTextColor( newColor )
- for i = 1, sizeB do
- mon.write(char)
- end
- mon.setCursorPos((maxLengt+2), line)
- mon.setTextColor( colors.white )
- mon.write("] "..size.."%")
- mon.setTextColor( oldColor )
- end
- function differential(line, actual, maximum, variation)
- mon.setCursorPos(1, line)
- mon.clearLine()
- mon.write(actual.."RF /"..maximum.."RF")
- oldColor = mon.getTextColor()
- if variation < 0 then newColor = colors.red else newColor = colors.lime end
- mon.setTextColor( newColor )
- mon.setCursorPos(30, line)
- mon.write(variation.."RF")
- mon.setTextColor( oldColor )
- end
- --body
- --prepare screen for storage operator
- if room == "storage" then
- mon.clear()
- mon.setTextColor( colors.white )
- mon.setBackgroundColor(colors.gray)
- drawCentered(2, "Power storage monitoring")
- drawAcross(3, "=")
- --Coal part
- drawAcross(6, "-")
- mon.setTextColor(colors.yellow)
- mon.setCursorPos(5,7)
- mon.write("Coal RF storage:")
- --Renewable part
- mon.setTextColor( colors.white )
- drawAcross(11, "-")
- mon.setTextColor(colors.yellow)
- mon.setCursorPos(5,12)
- mon.write("Renewable RF storage:")
- --Nuclear part
- mon.setTextColor( colors.white )
- drawAcross(16, "-")
- mon.setTextColor(colors.yellow)
- mon.setCursorPos(5,17)
- mon.write("Nuclear RF storage:")
- --Reserve part 1
- mon.setTextColor( colors.white )
- drawAcross(21, "-")
- mon.setTextColor(colors.yellow)
- mon.setCursorPos(5,22)
- mon.write("Unused RF storage:")
- --Reserve part 2
- mon.setTextColor( colors.white )
- drawAcross(26, "-")
- mon.setTextColor(colors.yellow)
- mon.setCursorPos(5,27)
- mon.write("Unused RF storage:")
- end
- --prepare screen for production operator
- --loop
- while true do
- event, side, frequency, replyFrequency, message, distance = os.pullEvent("modem_message")
- showMessage(4, message, "RedNet")
- data = textutils.unserialize(message)
- local production = data[1] --Where RF come from
- local typeOf = data[2] --What control room the message is for
- --Production control room
- if room == "production" then
- end
- --Storage control room
- if room == "storage" then
- local maxCap = data[3] --Max RF in this storage
- local actCap = data[4] --RF stored in this storage
- local pcCap = (actCap*100)/maxCap --RF stored in %
- pcCap = math.ceil(pcCap)
- --Coal
- if production == "coal" then
- drawPcBar(8, "#", pcCap)
- coalActCap = actCap
- if coalOldCap then var = coalActCap - coalOldCap end
- if var then differential(9, actCap, maxCap, var) end
- coalOldCap = coalActCap
- end
- --Renewable
- if production == "renewable" then
- drawPcBar(13, "#", pcCap)
- renewableActCap = actCap
- if renewableOldCap then var = renewableActCap - renewableOldCap end
- if var then differential(14, actCap, maxCap, var) end
- renewableOldCap = renewableActCap
- end
- --Nuclear
- if production == "nuclear" then
- drawPcBar(18, "#", pcCap)
- NuclearActCap = actCap
- if nuclearOldCap then var = NuclearActCap - nuclearOldCap end
- if var then differential(19, actCap, maxCap, var) end
- nuclearOldCap = NuclearActCap
- end
- end
- end
Add Comment
Please, Sign In to add comment