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