View difference between Paste ID: XYNPGRgb and SUYQ5ur0
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.wrap("back") == nil then
80
      else cube = peripheral.wrap("back")
81
      IC2 = true
82
    end
83
  end
84
  
85
  
86
  function convert(color)
87
    if color == "white" then color = colors.white end
88
    if color == "orange" then color = colors.orange end
89
    if color == "magenta" then color = colors.magenta end
90
    if color == "lightBlue" then color = colors.lightBlue end
91
    if color == "yellow" then color = colors.yellow end
92
    if color == "lime" then color = colors.lime end
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
    if color == "purple" then color = colors.purple end
98
    if color == "blue" then color = colors.blue end
99
    if color == "brown" then color = colors.brown end
100
    if color == "green" then color = colors.green end
101
    if color == "red" then color = colors.red end
102
    if color == "black" then color = colors.black end
103
    return color
104
  end
105
  
106
  function eChange()
107
    newE = curE
108
    local difference = (newE-oldE)
109
    oldE = curE
110
    if rate == "f" then dividend = 20 elseif rate == "s" then dividend = 100 end
111
    local change = math.floor(difference/dividend)
112
    return(change)
113
  end
114
115
  function timeLeft(tickspersec, left)
116
    local time = math.floor(left/tickspersec)
117
    local min = math.floor(time/20/60)
118
    if min < 0 then min = min * -1 end
119
    return(min)
120
  end
121
122
123
--PreFace
124
  --Color Coneverter
125
  --Load Settings
126
    title = config("title")
127
    rate = config("rate")
128
    dynamic = config("dynamic")
129
    colorTB = config("colorTB")
130
    colorTT = config("colorTT")
131
    colorMB = config("colorMB")
132
    colorST = config("colorST")
133
    colorBT = config("colorBT")
134
    colorBE = config("colorBE")
135
    colorBF = config("colorBF")
136
    colorPR = config("colorPR")
137
    colorPos = config("colorPos")
138
    colorNeg = config("colorNeg")
139
    redstone = config("redstone")
140
    storage = tonumber(config("storage")) or 0
141
    side = config("side")
142
    bundled = config("bundled")
143
    options = config("options")
144
    IC2Check()
145
    
146
  --Shows Settings inside control computer
147
    intro()
148
    term.setTextColour(colors.red)
149
    print("Final Settings")
150
    term.setTextColour(colors.blue)
151
    print(" Title: "..title)
152
    print("  Total storage: " ..storage)
153
    if rate == "f" then print(" Refresh Rate: fast") else print(" Refresh Rate: slow") end
154
    if dynamic == "y" then print(" Dynamic Scaling: true") else print(" Dynamic Scaling: false") end
155
    if options == "y" then
156
      term.setTextColour(colors.red)
157
      print("\nAdvanced Options")
158
      term.setTextColour(colors.blue)
159
      print(" Title Text Color: "..colorTT)
160
      print(" Title Background: "..colorTB)
161
      print(" Background Color: "..colorMB)
162
      print(" Statistics Color: "..colorST)
163
      print(" Bar Percent Text: "..colorBT)
164
      print(" Bars Empty Color: "..colorBE)
165
      print(" Bar Filled Color: "..colorBF)
166
      print(" Positive Change: "..colorPos)
167
      print(" Negative Change: "..colorNeg)
168
    end
169
    term.setTextColour(colors.gray)
170
    print("Million < Billion < Trillion < Quadrillion")
171
    term.setTextColour(colors.red)
172
    print("\nIf settings are incorrect. Run setup.lua")
173
    print("Hold CTRL+T to stop program")
174
175
  --RF/EU label
176
    if IC2 == true then energyAPI = " RF" else energyAPI = " RF" end
177
    if IC2 == true then energyAPI_ = "RF" else energyAPI_ = "RF" end
178
    
179
  --Wraps the Monitor
180
    mon = peripheral.find("monitor")
181
    monX,monY = mon.getSize()
182-
	  capacitorCount = 1
182+
183-
	  maxE = 1000000 * capacitorCount
183+
184
    monX,monY = mon.getSize()
185
    oldE,newE,curE,maxE = 0,0,0,0
186
    
187
  while true do    
188
      if dynamic == "y" then textScale() end
189
190
  --Main Program
191
    --Variables for Calculations
192
	  maxE = storage 
193
	  curE = cube.getEnergyStored() or 1
194
	  mbtq = ""
195
	  ebtq = ""
196
197
      percent = math.floor(((curE/maxE)*100)+0.5)
198
      bar = math.floor(((curE/maxE)*(monX-2))+0.5)
199
      stats = curE
200
      statsmax = maxE
201
    --Redstone Output
202
      if redstone == "y" then
203
        if bundled == "1" then
204
          if percent >= 99 then 
205
            rs.setBundledOutput(side,convert(colorPR))
206
            else rs.setBundledOutput(side,0)
207
          end
208
        else
209
          if percent >= 99 then
210
            rs.setOutput(side,true)
211
            else rs.setOutput(side,false)
212
          end
213
        end
214
      end
215
216
    --Centers and Displays Title On Monitor
217
218
      clearScreen()
219
      mon.setBackgroundColour(colors.black)
220
      mon.setTextColour(colors.lightGray)
221
      mon.setCursorPos(1,1)
222
      centerTextC(string.rep(" ",string.len(title)+2),1,convert(colorTB),convert(colorTT))
223
      centerTextC(title,1,convert(colorTB),convert(colorTT))
224
225
    --Monitor Statistics
226
      --[[if curE >= 1000000 and curE <= 1000000000 then
227
        stats = math.floor(stats/1000)
228
        stats = (stats/1000)
229
        mbtq = " M"
230
      else]]if curE >= 1000000000 and curE <= 1000000000000 then
231
        stats = math.floor(stats/1000000)
232
        stats = (stats/1000)
233
        mbtq = " B"
234
      elseif curE >= 1000000000000 and curE <= 1000000000000000 then
235
        stats = math.floor(stats/1000000000)
236-
      centerText(stats..mbtq..eAPI,3)
236+
237
        mbtq = " T"
238
      elseif curE >= 1000000000000000 then
239
        stats = math.floor(stats/1000000000000)
240
        stats = (stats/1000)
241
        mbtq = " Q"
242
      elseif curE <= 1000000 then mbtq = " "
243
      end
244
245
246
    --Monitor Statistics
247
      --[[if maxE >= 1000000 and maxE <= 1000000000 then
248-
      e_Change = eChange()
248+
        statsmax = math.floor(stats/1000)
249-
      if e_Change >= 0 then sign = "+" elseif e_Change <= 0 then sign = "-" end
249+
        statsmax = (stats/1000)
250-
      if e_Change >= 0 then signC = colorPos elseif e_Change <= 0 then signC = colorNeg end
250+
        ebtq = " M"
251-
      centerTextC(sign..e_Change..energyAPI.."/t",5,convert(colorMB),convert(signC))
251+
      else]]if maxE >= 1000000000 and maxE <= 1000000000000 then
252
        statsmax = math.floor(stats/1000000)
253
        statsmax = (stats/1000)
254
        ebtq = " B"
255
      elseif maxE >= 1000000000000 and maxE <= 1000000000000000 then
256
        statsmax = math.floor(stats/1000000000)
257
        statsmax = (stats/1000)
258
        ebtq = " T"
259
      elseif maxE >= 1000000000000000 then
260
        statsmax  = math.floor(stats/1000000000000)
261
        statsmax = (stats/1000)
262
        ebtq = " Q"
263
      elseif maxE <= 1000000 then ebtq = " "
264
      end 
265
266
      mon.setBackgroundColour(convert(colorMB))
267
      mon.setTextColour(convert(colorST))
268
      if curE >= 1000000 then eAPI = energyAPI_ else eAPI = energyAPI end
269
      centerText(stats..mbtq..eAPI.." / "..statsmax..ebtq..eAPI,3)
270
      --[[
271
      if monX >= math.floor(string.len(stats)+9)
272
        then
273
          centerText("Total:"..stats..mbtq..eAPI,3)
274
        else
275
          centerText("Total:",3) 
276
          centerText(stats..mbtq..eAPI,4) 
277
      end
278
      ]]
279
      
280
    --Change Per Tick Calculator and Display
281
      E_Change = eChange()
282
      T_Left = ""
283
      Suffix = ""
284
285
      if E_Change == 0 then T_Left = "Storage Full" else T_Left = timeLeft(E_Change, curE) end
286
      if E_Change == 0 then T_Left = "Storage Full" elseif E_Change <= 0 then Suffix = " Min Left!" elseif E_Change >= 0 then T_Left = "Charging" end
287
      if E_Change >= 0 then Sign = "+" elseif E_Change <= 0 then Sign = "-" end
288
      if E_Change >= 0 then SignC = colorPos elseif E_Change <= 0 then SignC = colorNeg end
289
      centerTextC(Sign..E_Change..energyAPI.."/t",5,convert(colorMB),convert(SignC))
290
      centerTextC(T_Left..Suffix,6,convert(colorMB),convert(SignC))
291
292
      centerTextC(percent.."% Full",monY-3,convert(colorMB),convert(colorBT))
293
    
294
    --Loading Bar Code Re-Written Much MUCH simpler than before
295
      mon.setCursorPos(2,monY-2)
296
      mon.setBackgroundColour(convert(colorBE))
297
      mon.write(string.rep(" ",monX-2))
298
      mon.setCursorPos(2,monY-2)
299
      mon.setBackgroundColour(convert(colorBF))
300
      mon.write(string.rep(" ",bar))
301
    
302
      mon.setCursorPos(2,monY-1)
303
      mon.setBackgroundColour(convert(colorBE))
304
      mon.write(string.rep(" ",monX-2))
305
      mon.setCursorPos(2,monY-1)
306
      mon.setBackgroundColour(convert(colorBF))
307
      mon.write(string.rep(" ",bar))
308
    
309
      if rate == "f" then os.sleep(1)
310
      elseif rate == "s" then os.sleep(5)
311
      else os.sleep(5) end
312
  end