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 / 1000) | |
| 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 | local Uri = "https://discordapp.com/api/webhooks/5012594536742922/mkGG2V7yuFzpfs50GxoM4QLKz6U0NB6YoVumbjrY4LKHpB9m0zXnLWl1ntM-9_O4Ua2R" | |
| 53 | ||
| 54 | monitor = peripheral.wrap("bottom")
| |
| 55 | battery = peripheral.find("warpdriveForceFieldProjector")
| |
| 56 | ||
| 57 | -- Check and bind monitor | |
| 58 | if monitor == nil then | |
| 59 | error("ER: No screen found to display!")
| |
| 60 | else | |
| 61 | monitor.clear() | |
| 62 | term.redirect(monitor) | |
| 63 | term.setCursorPos(1, 1) | |
| 64 | term.setBackgroundColor(colors.black) | |
| 65 | print(" Shield Information")
| |
| 66 | end | |
| 67 | ||
| 68 | -- Check if we have a battery | |
| 69 | if battery == nil then | |
| 70 | error("ER: No battery connected to computer")
| |
| 71 | end | |
| 72 | ||
| 73 | -- Draw our static fill volume box | |
| 74 | term.setTextColor(colors.white) | |
| 75 | term.setCursorPos(2, 2) | |
| 76 | print("+------+")
| |
| 77 | term.setCursorPos(2, 11) | |
| 78 | print("+------+")
| |
| 79 | for i = 3, 10 do | |
| 80 | term.setCursorPos(2, i) | |
| 81 | print("|")
| |
| 82 | term.setCursorPos(9, i) | |
| 83 | print("|")
| |
| 84 | end | |
| 85 | ||
| 86 | -- Draw our static interface text | |
| 87 | term.setCursorPos(11, 2); | |
| 88 | print("Shield:")
| |
| 89 | term.setCursorPos(11, 3); | |
| 90 | print("Tier:")
| |
| 91 | ||
| 92 | term.setCursorPos(11, 5); | |
| 93 | print("Valid:")
| |
| 94 | term.setCursorPos(11, 6); | |
| 95 | print("Controls:")
| |
| 96 | --term.setCursorPos(11, 7); | |
| 97 | --print("Enable Disable")
| |
| 98 | term.setCursorPos(11, 9); | |
| 99 | print("Stored:")
| |
| 100 | term.setCursorPos(11, 10); | |
| 101 | print("Filled:")
| |
| 102 | term.setCursorPos(11, 11); | |
| 103 | print("Critical:")
| |
| 104 | ||
| 105 | ||
| 106 | -- Entering our infinite loop of checking the battery | |
| 107 | -- This will refresh all information every 2 seconds | |
| 108 | alarmIsRinging = false | |
| 109 | alarmIsActive = false | |
| 110 | alarmCounter = 0 | |
| 111 | isAssemblyValid = battery.getAssemblyStatus() | |
| 112 | energyStored, energyMax, energyUnits = battery.getEnergyStatus() | |
| 113 | --isEnabled = battery.enable() | |
| 114 | tier = battery.getTier() | |
| 115 | name = battery.name() | |
| 116 | while true do | |
| 117 | - | term.setCursorPos(11, 7); |
| 117 | + | |
| 118 | - | term.setTextColor(colors.green) |
| 118 | + | |
| 119 | if isEnabled == true then | |
| 120 | --putValue(6, "Skipping", colors.green) | |
| 121 | else | |
| 122 | battery.enable(true) | |
| 123 | isEnabled = true | |
| 124 | end | |
| 125 | putValue(6," Enabled!", colors.green) | |
| 126 | http.post(uri,"{\"content\":\"```yaml\\nShield Name: "..name.." \\nTier: "..tier.." \\nEnergy: "..energyStored.." \\nStatus: "..isEnabled.."```\"}",{['content-type']="application/json"})
| |
| 127 | - | term.setCursorPos(11, 7); |
| 127 | + | |
| 128 | - | term.setTextColor(colors.red) |
| 128 | + | |
| 129 | putValue(6,"Disabled!", colors.red) | |
| 130 | end | |
| 131 | -- Get our input/output/balance battery values | |
| 132 | if not isAssemblyValid then | |
| 133 | batteryCurrentIn = "Invalid" | |
| 134 | putValue(5, batteryCurrentIn, colors.red) | |
| 135 | else | |
| 136 | batteryCurrentIn = "Valid" | |
| 137 | putValue(5, batteryCurrentIn, colors.green) | |
| 138 | end | |
| 139 | --batteryCurrentOut = battery.getOutput() | |
| 140 | -- putValue(5, batteryCurrentIn, colors.lightBlue) | |
| 141 | -- putValue(6, putNumber(batteryCurrentOut), colors.lightBlue) | |
| 142 | ||
| 143 | -- batteryCurrentBalance = batteryCurrentIn - batteryCurrentOut | |
| 144 | -- batteryCurrentColor = (batteryCurrentBalance >= 0) and colors.green or colors.red | |
| 145 | -- batteryCurrentSign = (batteryCurrentBalance >= 0) and "+" or "" | |
| 146 | if tier == 1 then | |
| 147 | tier1 = "Basic" | |
| 148 | elseif tier == 2 then | |
| 149 | tier1 = "Advanced" | |
| 150 | else | |
| 151 | tier1 = "Superior" | |
| 152 | end | |
| 153 | putValue(3, tier1, colors.green) | |
| 154 | putValue(2, name, colors.green) | |
| 155 | -- Get our statistical values | |
| 156 | batteryCurrentCharge = energyStored | |
| 157 | putValue(9, putNumber(energyStored), colors.lightBlue) | |
| 158 | ||
| 159 | batteryCurrentColor = colors.red | |
| 160 | batteryCurrentPercentage = ((energyStored / energyMax) * 100) | |
| 161 | if batteryCurrentPercentage > 30 then batteryCurrentColor = colors.orange end | |
| 162 | if batteryCurrentPercentage > 60 then batteryCurrentColor = colors.green end | |
| 163 | putValue(10, string.sub(putNumber(batteryCurrentPercentage), 0, 4) .. "%", batteryCurrentColor) | |
| 164 | ||
| 165 | batteryCurrentCritical = "Yes" | |
| 166 | batteryCurrentColor = colors.red | |
| 167 | if batteryCurrentPercentage > 15 then | |
| 168 | batteryCurrentCritical = "No" | |
| 169 | batteryCurrentColor = colors.green | |
| 170 | end | |
| 171 | putValue(11, batteryCurrentCritical, batteryCurrentColor) | |
| 172 | ||
| 173 | -- Draw the current charge graph | |
| 174 | batteryCurrentColor = colors.red | |
| 175 | if batteryCurrentPercentage > 30 then term.setTextColor(colors.orange) end | |
| 176 | if batteryCurrentPercentage > 60 then term.setTextColor(colors.green) end | |
| 177 | if batteryCurrentPercentage >= 100 then term.setTextColor(colors.green) end | |
| 178 | ||
| 179 | for i = 3, 10 do | |
| 180 | term.setCursorPos(3, i) | |
| 181 | print(" ")
| |
| 182 | end | |
| 183 | ||
| 184 | iterator = 0 | |
| 185 | for i = 3, 10 do | |
| 186 | local compare = (12.5 * iterator) | |
| 187 | if (batteryCurrentPercentage >= compare) then | |
| 188 | term.setCursorPos(3, (13 - i)) | |
| 189 | local filler = "" | |
| 190 | for i = 1, 6 do | |
| 191 | local inhere = (compare + (i*2)) | |
| 192 | if batteryCurrentPercentage >= inhere then | |
| 193 | filler = filler .. "#" | |
| 194 | else | |
| 195 | if batteryCurrentPercentage >= (inhere - 1) then | |
| 196 | filler = filler .. "=" | |
| 197 | else | |
| 198 | filler = filler .. "_" | |
| 199 | end | |
| 200 | end | |
| 201 | end | |
| 202 | print(filler) | |
| 203 | end | |
| 204 | ||
| 205 | iterator = iterator + 1 | |
| 206 | end | |
| 207 | ||
| 208 | -- Hey, ring the alarm! | |
| 209 | if batteryCurrentPercentage > 10 then | |
| 210 | alarmIsRinging = false | |
| 211 | alarmIsActive = false | |
| 212 | end | |
| 213 | ||
| 214 | if batteryCurrentPercentage < 10 and alarmIsActive == false then | |
| 215 | alarmIsRinging = true | |
| 216 | alarmIsActive = true | |
| 217 | alarmCounter = 0 | |
| 218 | redstone.setOutput("left", true)
| |
| 219 | end | |
| 220 | ||
| 221 | if alarmIsRinging == true then | |
| 222 | alarmCounter = alarmCounter + 1 | |
| 223 | if alarmCounter >= 10 then | |
| 224 | redstone.setOutput("left", false)
| |
| 225 | alarmIsRinging = false | |
| 226 | end | |
| 227 | end | |
| 228 | ||
| 229 | -- Wait 2s until next iteration | |
| 230 | os.sleep(2) | |
| 231 | ||
| 232 | end |