SHOW:
|
|
- or go back to the newest paste.
| 1 | --[[ Power Monitoring Program Written By: 0_Mr_Redstone_0 AKA MoJoCreatior | |
| 2 | This code is considered free for use both commercial and private and can be redistributed so long as it meets following criteria: | |
| 3 | 1: Player_Athena and MoJoCreatior are credited as the original authors | |
| 4 | 2: You do not try to take full ownership of the code/written program | |
| 5 | 3: If you modify the code for re-upload you must provide it under the same conditions. as in- Open Source, and credited to me as original author]] | |
| 6 | ||
| 7 | program = "Power Monitoring Program V:30" | |
| 8 | ||
| 9 | --Function | |
| 10 | function intro() | |
| 11 | term.setBackgroundColour(colors.white) | |
| 12 | term.clear() | |
| 13 | term.setCursorPos(1,1) | |
| 14 | term.setTextColour(colors.green) | |
| 15 | print(program.." -Written By: 0_Mr_Redstone_0 AKA MoJoCreatior") | |
| 16 | print(" ")
| |
| 17 | end | |
| 18 | ||
| 19 | function centerText(text,yVal) | |
| 20 | length = string.len(text) | |
| 21 | minus = math.floor(monX-length) | |
| 22 | x = math.floor(minus/2) | |
| 23 | mon.setCursorPos(x+1,yVal) | |
| 24 | mon.write(text) | |
| 25 | end | |
| 26 | ||
| 27 | function centerTextC(text,line,colorB,colorT) | |
| 28 | mon.setBackgroundColour(colorB) | |
| 29 | mon.setTextColour(colorT) | |
| 30 | length = string.len(text) | |
| 31 | minus = math.floor(monX-length) | |
| 32 | x = math.floor(minus/2) | |
| 33 | mon.setCursorPos(x+1,line) | |
| 34 | mon.write(text) | |
| 35 | end | |
| 36 | ||
| 37 | function clearScreen() | |
| 38 | mon.setBackgroundColour(convert(colorMB)) | |
| 39 | mon.clear() | |
| 40 | end | |
| 41 | ||
| 42 | function config(name) | |
| 43 | if fs.exists("config/"..name) then
| |
| 44 | cfg = fs.open("config/"..name,"r")
| |
| 45 | name = cfg.readAll() | |
| 46 | cfg.close() | |
| 47 | return name | |
| 48 | else | |
| 49 | fs.delete("startup")
| |
| 50 | startup = fs.open("startup","w")
| |
| 51 | startup.write('shell.run("setup.lua")')
| |
| 52 | startup.close() | |
| 53 | term.setTextColour(colors.red) | |
| 54 | print("ERROR! 404")
| |
| 55 | print(name.." config not found") | |
| 56 | term.setTextColour(colors.blue) | |
| 57 | print("rebooting into setup")
| |
| 58 | print("3") sleep(1)
| |
| 59 | print("2") sleep(1)
| |
| 60 | print("1") sleep(1)
| |
| 61 | os.reboot() | |
| 62 | end | |
| 63 | end | |
| 64 | ||
| 65 | function textScale() | |
| 66 | mon.setTextScale(0.5) | |
| 67 | monX,monY = mon.getSize() | |
| 68 | if monX <= 16 or monY <= 11 then mon.setTextScale(0.5) elseif | |
| 69 | monX <= 37 or monY <= 25 then mon.setTextScale(1) elseif | |
| 70 | monX <= 58 or monY <= 39 then mon.setTextScale(1.5) elseif | |
| 71 | monX <= 80 or monY <= 53 then mon.setTextScale(2) elseif | |
| 72 | monX <= 101 or monY <= 68 then mon.setTextScale(2.5) else | |
| 73 | mon.setTextScale(3) | |
| 74 | end | |
| 75 | end | |
| 76 | ||
| 77 | function IC2Check() | |
| 78 | IC2 = false | |
| 79 | - | if peripheral.find("mfsu") == nil then
|
| 79 | + | if peripheral.wrap("back") == nil then
|
| 80 | - | else cube = peripheral.find("mfsu")
|
| 80 | + | else cube = peripheral.wrap("back")
|
| 81 | IC2 = true | |
| 82 | end | |
| 83 | - | if peripheral.find("mfe") == nil then
|
| 83 | + | |
| 84 | - | else cube = peripheral.find("mfe")
|
| 84 | + | |
| 85 | ||
| 86 | function convert(color) | |
| 87 | - | if peripheral.find("cesu") == nil then
|
| 87 | + | |
| 88 | - | else cube = peripheral.find("cesu")
|
| 88 | + | |
| 89 | if color == "magenta" then color = colors.magenta end | |
| 90 | if color == "lightBlue" then color = colors.lightBlue end | |
| 91 | - | if peripheral.find("batbox") == nil then
|
| 91 | + | |
| 92 | - | else cube = peripheral.find("batbox")
|
| 92 | + | |
| 93 | if color == "pinkgray" then color = colors.pinkgray end | |
| 94 | if color == "gray" then color = colors.gray end | |
| 95 | if color == "lightGray" then color = colors.lightGray end | |
| 96 | if color == "cyan" then color = colors.cyan end | |
| 97 | - | function mekanismCheck() |
| 97 | + | |
| 98 | - | mekanism = false |
| 98 | + | |
| 99 | - | if peripheral.find("Basic Energy Cube") == nil then
|
| 99 | + | |
| 100 | - | else cube = peripheral.find("Basic Energy Cube")
|
| 100 | + | |
| 101 | - | mekanism = true |
| 101 | + | |
| 102 | if color == "black" then color = colors.black end | |
| 103 | - | if peripheral.find("Advanced Energy Cube") == nil then
|
| 103 | + | |
| 104 | - | else cube = peripheral.find("Advanced Energy Cube")
|
| 104 | + | |
| 105 | - | mekanism = true |
| 105 | + | |
| 106 | function eChange() | |
| 107 | - | if peripheral.find("Elite Energy Cube") == nil then
|
| 107 | + | |
| 108 | - | else cube = peripheral.find("Elite Energy Cube")
|
| 108 | + | |
| 109 | - | mekanism = true |
| 109 | + | |
| 110 | if rate == "f" then dividend = 20 elseif rate == "s" then dividend = 100 end | |
| 111 | - | if peripheral.find("Ultimate Energy Cube") == nil then
|
| 111 | + | |
| 112 | - | else cube = peripheral.find("Ultimate Energy Cube")
|
| 112 | + | |
| 113 | - | mekanism = true |
| 113 | + | |
| 114 | ||
| 115 | - | if peripheral.find("Induction Matrix") == nil then
|
| 115 | + | |
| 116 | - | else cube = peripheral.find("Induction Matrix")
|
| 116 | + | |
| 117 | - | mekanism = true |
| 117 | + | |
| 118 | title = config("title")
| |
| 119 | rate = config("rate")
| |
| 120 | dynamic = config("dynamic")
| |
| 121 | - | function RFAPI() |
| 121 | + | |
| 122 | - | rfAPI = false |
| 122 | + | |
| 123 | - | if peripheral.find("tile_thermalexpansion_cell_resonant_name") == nil then
|
| 123 | + | |
| 124 | - | else cube = peripheral.find("tile_thermalexpansion_cell_resonant_name")
|
| 124 | + | |
| 125 | - | rfAPI = true |
| 125 | + | |
| 126 | colorBE = config("colorBE")
| |
| 127 | - | if peripheral.find("tile_blockcapacitorbank_name") == nil then
|
| 127 | + | |
| 128 | - | else cube = peripheral.find("tile_blockcapacitorbank_name")
|
| 128 | + | |
| 129 | - | rfAPI = true |
| 129 | + | |
| 130 | colorNeg = config("colorNeg")
| |
| 131 | - | if peripheral.find("extrautils_generatorsolar") == nil then
|
| 131 | + | |
| 132 | - | else cube = peripheral.find("extrautils_generatorsolar")
|
| 132 | + | |
| 133 | - | rfAPI = true |
| 133 | + | |
| 134 | options = config("options")
| |
| 135 | IC2Check() | |
| 136 | ||
| 137 | --Shows Settings inside control computer | |
| 138 | intro() | |
| 139 | term.setTextColour(colors.red) | |
| 140 | print("Final Settings")
| |
| 141 | term.setTextColour(colors.blue) | |
| 142 | print(" Title: "..title)
| |
| 143 | if rate == "f" then print(" Refresh Rate: fast") else print(" Refresh Rate: slow") end
| |
| 144 | if dynamic == "y" then print(" Dynamic Scaling: true") else print(" Dynamic Scaling: false") end
| |
| 145 | if options == "y" then | |
| 146 | term.setTextColour(colors.red) | |
| 147 | print("\nAdvanced Options")
| |
| 148 | term.setTextColour(colors.blue) | |
| 149 | print(" Title Text Color: "..colorTT)
| |
| 150 | print(" Title Background: "..colorTB)
| |
| 151 | print(" Background Color: "..colorMB)
| |
| 152 | print(" Statistics Color: "..colorST)
| |
| 153 | print(" Bar Percent Text: "..colorBT)
| |
| 154 | print(" Bars Empty Color: "..colorBE)
| |
| 155 | print(" Bar Filled Color: "..colorBF)
| |
| 156 | print(" Positive Change: "..colorPos)
| |
| 157 | print(" Negative Change: "..colorNeg)
| |
| 158 | end | |
| 159 | term.setTextColour(colors.gray) | |
| 160 | print("Million < Billion < Trillion < Quadrillion")
| |
| 161 | term.setTextColour(colors.red) | |
| 162 | print("\nIf settings are incorrect. Run setup.lua")
| |
| 163 | print("Hold CTRL+T to stop program")
| |
| 164 | ||
| 165 | --RF/EU label | |
| 166 | if IC2 == true then energyAPI = " RF" else energyAPI = " RF" end | |
| 167 | if IC2 == true then energyAPI_ = "RF" else energyAPI_ = "RF" end | |
| 168 | ||
| 169 | --Wraps the Monitor | |
| 170 | mon = peripheral.find("monitor")
| |
| 171 | monX,monY = mon.getSize() | |
| 172 | textScale() | |
| 173 | ||
| 174 | monX,monY = mon.getSize() | |
| 175 | oldE,newE,curE,maxE = 0,0,0,0 | |
| 176 | ||
| 177 | while true do | |
| 178 | if dynamic == "y" then textScale() end | |
| 179 | ||
| 180 | --Main Program | |
| 181 | --Variables for Calculations | |
| 182 | capacitorCount = 1 | |
| 183 | maxE = 1000000 * capacitorCount | |
| 184 | curE = cube.getEnergyStored() or 1 | |
| 185 | ||
| 186 | percent = math.floor(((curE/maxE)*100)+0.5) | |
| 187 | - | mekanismCheck() |
| 187 | + | |
| 188 | - | RFAPI() |
| 188 | + | |
| 189 | ||
| 190 | --Redstone Output | |
| 191 | if redstone == "y" then | |
| 192 | if bundled == "1" then | |
| 193 | if percent >= 99 then | |
| 194 | rs.setBundledOutput(side,convert(colorPR)) | |
| 195 | else rs.setBundledOutput(side,0) | |
| 196 | end | |
| 197 | - | if mekanism == true then print(" Mekanism: true") else print(" Mekanism: false") end
|
| 197 | + | |
| 198 | - | if IC2 == true then print(" IC2: true") else print(" IC2: false") end
|
| 198 | + | |
| 199 | rs.setOutput(side,true) | |
| 200 | else rs.setOutput(side,false) | |
| 201 | end | |
| 202 | end | |
| 203 | end | |
| 204 | ||
| 205 | --Centers and Displays Title On Monitor | |
| 206 | ||
| 207 | clearScreen() | |
| 208 | mon.setBackgroundColour(colors.black) | |
| 209 | mon.setTextColour(colors.lightGray) | |
| 210 | mon.setCursorPos(1,1) | |
| 211 | centerTextC(string.rep(" ",string.len(title)+2),1,convert(colorTB),convert(colorTT))
| |
| 212 | centerTextC(title,1,convert(colorTB),convert(colorTT)) | |
| 213 | ||
| 214 | --Monitor Statistics | |
| 215 | --[[if curE >= 1000000 and curE <= 1000000000 then | |
| 216 | stats = math.floor(stats/1000) | |
| 217 | stats = (stats/1000) | |
| 218 | mbtq = " M" | |
| 219 | else]]if curE >= 1000000000 and curE <= 1000000000000 then | |
| 220 | stats = math.floor(stats/1000000) | |
| 221 | - | if IC2 == true then energyAPI = " EU" else energyAPI = " RF" end |
| 221 | + | |
| 222 | - | if IC2 == true then energyAPI_ = "EU" else energyAPI_ = "RF" end |
| 222 | + | |
| 223 | elseif curE >= 1000000000000 and curE <= 1000000000000000 then | |
| 224 | stats = math.floor(stats/1000000000) | |
| 225 | stats = (stats/1000) | |
| 226 | mbtq = " T" | |
| 227 | elseif curE >= 1000000000000000 then | |
| 228 | stats = math.floor(stats/1000000000000) | |
| 229 | stats = (stats/1000) | |
| 230 | mbtq = " Q" | |
| 231 | elseif curE <= 1000000 then mbtq = " " | |
| 232 | end | |
| 233 | mon.setBackgroundColour(convert(colorMB)) | |
| 234 | mon.setTextColour(convert(colorST)) | |
| 235 | if curE >= 1000000 then eAPI = energyAPI_ else eAPI = energyAPI end | |
| 236 | centerText(stats..mbtq..eAPI,3) | |
| 237 | - | if mekanism == true then maxE = cube.getMaxEnergy() or 1 |
| 237 | + | |
| 238 | - | elseif IC2 == true then maxE = cube.getEUCapacity() or 1 |
| 238 | + | |
| 239 | - | else maxE = cube.getMaxEnergyStored() or 1 |
| 239 | + | |
| 240 | centerText("Total:"..stats..mbtq..eAPI,3)
| |
| 241 | - | if mekanism == true then curE = cube.getEnergy() or 1 |
| 241 | + | |
| 242 | - | elseif IC2 == true then curE = cube.getEUStored() or 1 |
| 242 | + | |
| 243 | - | else curE = cube.getEnergyStored() or 1 |
| 243 | + | |
| 244 | end | |
| 245 | - | if mekanism == true then |
| 245 | + | |
| 246 | - | maxE = math.floor(maxE/2.5) |
| 246 | + | |
| 247 | - | curE = math.floor(curE/2.5) |
| 247 | + | |
| 248 | e_Change = eChange() | |
| 249 | if e_Change >= 0 then sign = "+" elseif e_Change <= 0 then sign = "-" end | |
| 250 | if e_Change >= 0 then signC = colorPos elseif e_Change <= 0 then signC = colorNeg end | |
| 251 | centerTextC(sign..e_Change..energyAPI.."/t",5,convert(colorMB),convert(signC)) | |
| 252 | ||
| 253 | centerTextC(percent.."% Full",monY-3,convert(colorMB),convert(colorBT)) | |
| 254 | ||
| 255 | --Loading Bar Code Re-Written Much MUCH simpler than before | |
| 256 | mon.setCursorPos(2,monY-2) | |
| 257 | mon.setBackgroundColour(convert(colorBE)) | |
| 258 | mon.write(string.rep(" ",monX-2))
| |
| 259 | mon.setCursorPos(2,monY-2) | |
| 260 | mon.setBackgroundColour(convert(colorBF)) | |
| 261 | mon.write(string.rep(" ",bar))
| |
| 262 | ||
| 263 | mon.setCursorPos(2,monY-1) | |
| 264 | mon.setBackgroundColour(convert(colorBE)) | |
| 265 | mon.write(string.rep(" ",monX-2))
| |
| 266 | mon.setCursorPos(2,monY-1) | |
| 267 | mon.setBackgroundColour(convert(colorBF)) | |
| 268 | mon.write(string.rep(" ",bar))
| |
| 269 | ||
| 270 | if rate == "f" then os.sleep(1) | |
| 271 | elseif rate == "s" then os.sleep(5) | |
| 272 | else os.sleep(5) end | |
| 273 | end |