SHOW:
|
|
- or go back to the newest paste.
| 1 | function putValue (line, text, color) | |
| 2 | local align = 30 - string.len(text) | |
| 3 | term.setCursorPos(align, line) | |
| 4 | term.setTextColor(color) | |
| 5 | print(text) | |
| 6 | end | |
| 7 | ||
| 8 | function putNumber (number) | |
| 9 | local round = 0 | |
| 10 | local texts = "" | |
| 11 | ||
| 12 | if number >= 1000000000000000000 then | |
| 13 | round = (number / 1000000000000000000) | |
| 14 | texts = string.sub(round, 0, 5) .. " ERF" | |
| 15 | else | |
| 16 | if number >= 1000000000000000 then | |
| 17 | round = (number / 1000000000000000) | |
| 18 | texts = string.sub(round, 0, 5) .. " PRF" | |
| 19 | else | |
| 20 | if number >= 1000000000000 then | |
| 21 | round = (number / 1000000000000) | |
| 22 | texts = string.sub(round, 0, 5) .. " TRF" | |
| 23 | else | |
| 24 | if number >= 1000000000 then | |
| 25 | round = (number / 10000000000) | |
| 26 | texts = string.sub(round, 0, 5) .. " GRF" | |
| 27 | else | |
| 28 | if number >= 1000000 then | |
| 29 | round = (number / 10000000) | |
| 30 | texts = string.sub(round, 0, 5) .. " MRF" | |
| 31 | else | |
| 32 | if number >= 1000 then | |
| 33 | round = (number / 10000) | |
| 34 | texts = string.sub(round, 0, 5) .. " kRF" | |
| 35 | else | |
| 36 | texts = string.sub(number, 0, 5) .. " RF" | |
| 37 | end | |
| 38 | end | |
| 39 | end | |
| 40 | end | |
| 41 | end | |
| 42 | end | |
| 43 | ||
| 44 | return texts | |
| 45 | end | |
| 46 | ||
| 47 | ||
| 48 | ||
| 49 | ||
| 50 | -- Initialize our interface! | |
| 51 | -- Find all of our peripherals | |
| 52 | monitor = peripheral.wrap("bottom")
| |
| 53 | - | battery = peripheral.find("Induction Matrix")
|
| 53 | + | battery = peripheral.find("warpdriveForceFieldProjector")
|
| 54 | ||
| 55 | -- Check and bind monitor | |
| 56 | if monitor == nil then | |
| 57 | error("ER: No screen found to display!")
| |
| 58 | else | |
| 59 | monitor.clear() | |
| 60 | term.redirect(monitor) | |
| 61 | term.setCursorPos(1, 1) | |
| 62 | term.setBackgroundColor(colors.black) | |
| 63 | print("Shield Information: Main")
| |
| 64 | end | |
| 65 | ||
| 66 | -- Check if we have a battery | |
| 67 | if battery == nil then | |
| 68 | error("ER: No battery connected to computer")
| |
| 69 | end | |
| 70 | ||
| 71 | -- Draw our static fill volume box | |
| 72 | term.setTextColor(colors.white) | |
| 73 | term.setCursorPos(2, 2) | |
| 74 | print("+------+")
| |
| 75 | term.setCursorPos(2, 11) | |
| 76 | print("+------+")
| |
| 77 | for i = 3, 10 do | |
| 78 | term.setCursorPos(2, i) | |
| 79 | print("|")
| |
| 80 | term.setCursorPos(9, i) | |
| 81 | print("|")
| |
| 82 | end | |
| 83 | ||
| 84 | -- Draw our static interface text | |
| 85 | term.setCursorPos(11, 2); | |
| 86 | print("Max RF:")
| |
| 87 | term.setCursorPos(11, 3); | |
| 88 | print("Max Thru:")
| |
| 89 | ||
| 90 | term.setCursorPos(11, 5); | |
| 91 | print("Cur In:")
| |
| 92 | term.setCursorPos(11, 6); | |
| 93 | print("Cur Out:")
| |
| 94 | term.setCursorPos(11, 7); | |
| 95 | print("Cur Bal:")
| |
| 96 | ||
| 97 | term.setCursorPos(11, 9); | |
| 98 | print("Stored:")
| |
| 99 | term.setCursorPos(11, 10); | |
| 100 | print("Filled:")
| |
| 101 | term.setCursorPos(11, 11); | |
| 102 | print("Critical:")
| |
| 103 | ||
| 104 | ||
| 105 | -- Entering our infinite loop of checking the battery | |
| 106 | -- This will refresh all information every 2 seconds | |
| 107 | alarmIsRinging = false | |
| 108 | alarmIsActive = false | |
| 109 | alarmCounter = 0 | |
| 110 | isAssemblyValid = forcefieldprojector.getAssemblyStatus() | |
| 111 | energyStored, energyMax, energyUnits = forcefieldprojector.getEnergyStatus() | |
| 112 | - | -- Get our fixed battery values |
| 112 | + | isEnabled = forcefieldprojector.enable() |
| 113 | - | batteryMaxCharge = battery.getMaxEnergy() |
| 113 | + | tier = forcefieldprojector.getTier() |
| 114 | - | batteryMaxInOuts = battery.getTransferCap() |
| 114 | + | |
| 115 | - | putValue(2, putNumber(batteryMaxCharge), colors.lightBlue) |
| 115 | + | |
| 116 | - | putValue(3, putNumber(batteryMaxInOuts), colors.lightBlue) |
| 116 | + | |
| 117 | -- batteryCurrentIn = battery.getInput() | |
| 118 | -- batteryCurrentOut = battery.getOutput() | |
| 119 | - | batteryCurrentIn = battery.getInput() |
| 119 | + | -- putValue(5, putNumber(batteryCurrentIn), colors.lightBlue) |
| 120 | - | batteryCurrentOut = battery.getOutput() |
| 120 | + | -- putValue(6, putNumber(batteryCurrentOut), colors.lightBlue) |
| 121 | - | putValue(5, putNumber(batteryCurrentIn), colors.lightBlue) |
| 121 | + | |
| 122 | - | putValue(6, putNumber(batteryCurrentOut), colors.lightBlue) |
| 122 | + | -- batteryCurrentBalance = batteryCurrentIn - batteryCurrentOut |
| 123 | -- batteryCurrentColor = (batteryCurrentBalance >= 0) and colors.green or colors.red | |
| 124 | - | batteryCurrentBalance = batteryCurrentIn - batteryCurrentOut |
| 124 | + | -- batteryCurrentSign = (batteryCurrentBalance >= 0) and "+" or "" |
| 125 | - | batteryCurrentColor = (batteryCurrentBalance >= 0) and colors.green or colors.red |
| 125 | + | |
| 126 | - | batteryCurrentSign = (batteryCurrentBalance >= 0) and "+" or "" |
| 126 | + | |
| 127 | -- Get our statistical values | |
| 128 | batteryCurrentCharge = battery.getEnergy() | |
| 129 | putValue(9, putNumber(energyStored), colors.lightBlue) | |
| 130 | ||
| 131 | - | putValue(9, putNumber(batteryCurrentCharge), colors.lightBlue) |
| 131 | + | |
| 132 | batteryCurrentPercentage = ((energyStored / energyMax) * 100) | |
| 133 | if batteryCurrentPercentage > 30 then batteryCurrentColor = colors.orange end | |
| 134 | - | batteryCurrentPercentage = ((batteryCurrentCharge / batteryMaxCharge) * 100) |
| 134 | + | |
| 135 | putValue(10, string.sub(putNumber(batteryCurrentPercentage), 0, 4) .. "%", batteryCurrentColor) | |
| 136 | ||
| 137 | batteryCurrentCritical = "Yes" | |
| 138 | batteryCurrentColor = colors.red | |
| 139 | if batteryCurrentPercentage > 15 then | |
| 140 | batteryCurrentCritical = "No" | |
| 141 | batteryCurrentColor = colors.green | |
| 142 | end | |
| 143 | putValue(11, batteryCurrentCritical, batteryCurrentColor) | |
| 144 | ||
| 145 | -- Draw the current charge graph | |
| 146 | batteryCurrentColor = colors.red | |
| 147 | if batteryCurrentPercentage > 30 then term.setTextColor(colors.orange) end | |
| 148 | if batteryCurrentPercentage > 60 then term.setTextColor(colors.green) end | |
| 149 | if batteryCurrentPercentage >= 100 then term.setTextColor(colors.lightBlue) end | |
| 150 | ||
| 151 | for i = 3, 10 do | |
| 152 | term.setCursorPos(3, i) | |
| 153 | print(" ")
| |
| 154 | end | |
| 155 | ||
| 156 | iterator = 0 | |
| 157 | for i = 3, 10 do | |
| 158 | local compare = (12.5 * iterator) | |
| 159 | if (batteryCurrentPercentage >= compare) then | |
| 160 | term.setCursorPos(3, (13 - i)) | |
| 161 | local filler = "" | |
| 162 | for i = 1, 6 do | |
| 163 | local inhere = (compare + (i*2)) | |
| 164 | if batteryCurrentPercentage >= inhere then | |
| 165 | filler = filler .. "#" | |
| 166 | else | |
| 167 | if batteryCurrentPercentage >= (inhere - 1) then | |
| 168 | filler = filler .. "=" | |
| 169 | else | |
| 170 | filler = filler .. "_" | |
| 171 | end | |
| 172 | end | |
| 173 | end | |
| 174 | print(filler) | |
| 175 | end | |
| 176 | ||
| 177 | iterator = iterator + 1 | |
| 178 | end | |
| 179 | ||
| 180 | -- Hey, ring the alarm! | |
| 181 | if batteryCurrentPercentage > 10 then | |
| 182 | alarmIsRinging = false | |
| 183 | alarmIsActive = false | |
| 184 | end | |
| 185 | ||
| 186 | if batteryCurrentPercentage < 10 and alarmIsActive == false then | |
| 187 | alarmIsRinging = true | |
| 188 | alarmIsActive = true | |
| 189 | alarmCounter = 0 | |
| 190 | redstone.setOutput("left", true)
| |
| 191 | end | |
| 192 | ||
| 193 | if alarmIsRinging == true then | |
| 194 | alarmCounter = alarmCounter + 1 | |
| 195 | if alarmCounter >= 10 then | |
| 196 | redstone.setOutput("left", false)
| |
| 197 | alarmIsRinging = false | |
| 198 | end | |
| 199 | end | |
| 200 | ||
| 201 | -- Wait 2s until next iteration | |
| 202 | os.sleep(2) | |
| 203 | ||
| 204 | end |