Advertisement
Guest User

PowerMonitor V: BVB

a guest
Dec 18th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.58 KB | None | 0 0
  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 meats following criteria:
  3. 1: 0_Mr_Redstone_0 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. Modified by BobVonBob for Zetta Industries Compatibility]]
  7.  
  8. program = "Power Monitoring Program V:30"
  9.  
  10. --Function
  11. function intro()
  12. term.setBackgroundColour(colors.white)
  13. term.clear()
  14. term.setCursorPos(1,1)
  15. term.setTextColour(colors.green)
  16. print(program.." -Written By: 0_Mr_Redstone_0 AKA MoJoCreatior, Modified by BobVonBob")
  17. print(" ")
  18. end
  19.  
  20. function centerText(text,yVal)
  21. length = string.len(text)
  22. minus = math.floor(monX-length)
  23. x = math.floor(minus/2)
  24. mon.setCursorPos(x+1,yVal)
  25. mon.write(text)
  26. end
  27.  
  28. function centerTextC(text,line,colorB,colorT)
  29. mon.setBackgroundColour(colorB)
  30. mon.setTextColour(colorT)
  31. length = string.len(text)
  32. minus = math.floor(monX-length)
  33. x = math.floor(minus/2)
  34. mon.setCursorPos(x+1,line)
  35. mon.write(text)
  36. end
  37.  
  38. function clearScreen()
  39. mon.setBackgroundColour(convert(colorMB))
  40. mon.clear()
  41. end
  42.  
  43. function config(name)
  44. if fs.exists("config/"..name) then
  45. cfg = fs.open("config/"..name,"r")
  46. name = cfg.readAll()
  47. cfg.close()
  48. return name
  49. else
  50. fs.delete("startup")
  51. startup = fs.open("startup","w")
  52. startup.write('shell.run("setup.lua")')
  53. startup.close()
  54. term.setTextColour(colors.red)
  55. print("ERROR! 404")
  56. print(name.." config not found")
  57. term.setTextColour(colors.blue)
  58. print("rebooting into setup")
  59. print("3") sleep(1)
  60. print("2") sleep(1)
  61. print("1") sleep(1)
  62. os.reboot()
  63. end
  64. end
  65.  
  66. function textScale()
  67. mon.setTextScale(0.5)
  68. monX,monY = mon.getSize()
  69. if monX <= 16 or monY <= 11 then mon.setTextScale(0.5) elseif
  70. monX <= 37 or monY <= 25 then mon.setTextScale(1) elseif
  71. monX <= 58 or monY <= 39 then mon.setTextScale(1.5) elseif
  72. monX <= 80 or monY <= 53 then mon.setTextScale(2) elseif
  73. monX <= 101 or monY <= 68 then mon.setTextScale(2.5) else
  74. mon.setTextScale(3)
  75. end
  76. end
  77.  
  78. function IC2Check()
  79. IC2 = false
  80. if peripheral.find("mfsu") == nil then
  81. else cube = peripheral.find("mfsu")
  82. IC2 = true
  83. end
  84. if peripheral.find("mfe") == nil then
  85. else cube = peripheral.find("mfe")
  86. IC2 = true
  87. end
  88. if peripheral.find("cesu") == nil then
  89. else cube = peripheral.find("cesu")
  90. IC2 = true
  91. end
  92. if peripheral.find("batbox") == nil then
  93. else cube = peripheral.find("batbox")
  94. IC2 = true
  95. end
  96. end
  97.  
  98. function mekanismCheck()
  99. mekanism = false
  100. if peripheral.find("Basic Energy Cube") == nil then
  101. else cube = peripheral.find("Basic Energy Cube")
  102. mekanism = true
  103. end
  104. if peripheral.find("Advanced Energy Cube") == nil then
  105. else cube = peripheral.find("Advanced Energy Cube")
  106. mekanism = true
  107. end
  108. if peripheral.find("Elite Energy Cube") == nil then
  109. else cube = peripheral.find("Elite Energy Cube")
  110. mekanism = true
  111. end
  112. if peripheral.find("Ultimate Energy Cube") == nil then
  113. else cube = peripheral.find("Ultimate Energy Cube")
  114. mekanism = true
  115. end
  116. if peripheral.find("Induction Matrix") == nil then
  117. else cube = peripheral.find("Induction Matrix")
  118. mekanism = true
  119. end
  120. end
  121.  
  122. function RFAPI()
  123. if peripheral.find("tile_thermalexpansion_cell_resonant_name") == nil then
  124. else cube = peripheral.find("tile_thermalexpansion_cell_resonant_name")
  125. end
  126. if peripheral.find("tile_blockcapacitorbank_name") == nil then
  127. else cube = peripheral.find("tile_blockcapacitorbank_name")
  128. end
  129. end
  130.  
  131. function ZICheck()
  132. ZI = false
  133. if peripheral.find("big_battery") == nil then
  134. else cube = peripheral.find("big_battery")
  135. ZI = true
  136. end
  137. end
  138.  
  139. function convert(color)
  140. if color == "white" then color = colors.white end
  141. if color == "orange" then color = colors.orange end
  142. if color == "magenta" then color = colors.magenta end
  143. if color == "lightBlue" then color = colors.lightBlue end
  144. if color == "yellow" then color = colors.yellow end
  145. if color == "lime" then color = colors.lime end
  146. if color == "pinkgray" then color = colors.pinkgray end
  147. if color == "gray" then color = colors.gray end
  148. if color == "lightGray" then color = colors.lightGray end
  149. if color == "cyan" then color = colors.cyan end
  150. if color == "purple" then color = colors.purple end
  151. if color == "blue" then color = colors.blue end
  152. if color == "brown" then color = colors.brown end
  153. if color == "green" then color = colors.green end
  154. if color == "red" then color = colors.red end
  155. if color == "black" then color = colors.black end
  156. return color
  157. end
  158.  
  159. function eChange()
  160. newE = curE
  161. local difference = (newE-oldE)
  162. oldE = curE
  163. if rate == "f" then dividend = 20 elseif rate == "s" then dividend = 100 end
  164. local change = math.floor(difference/dividend)
  165. return(change)
  166. end
  167.  
  168. --PreFace
  169. --Color Coneverter
  170. --Load Settings
  171. title = config("title")
  172. rate = config("rate")
  173. dynamic = config("dynamic")
  174. colorTB = config("colorTB")
  175. colorTT = config("colorTT")
  176. colorMB = config("colorMB")
  177. colorST = config("colorST")
  178. colorBT = config("colorBT")
  179. colorBE = config("colorBE")
  180. colorBF = config("colorBF")
  181. colorPR = config("colorPR")
  182. colorPos = config("colorPos")
  183. colorNeg = config("colorNeg")
  184. redstone = config("redstone")
  185. side = config("side")
  186. bundled = config("bundled")
  187. options = config("options")
  188. IC2Check()
  189. mekanismCheck()
  190. RFAPI()
  191. ZICheck()
  192.  
  193. --Shows Settings inside control computer
  194. intro()
  195. term.setTextColour(colors.red)
  196. print("Final Settings")
  197. term.setTextColour(colors.blue)
  198. print(" Title: "..title)
  199. if rate == "f" then print(" Refresh Rate: fast") else print(" Refresh Rate: slow") end
  200. if mekanism == true then print(" Mekanism: true") else print(" Mekanism: false") end
  201. if IC2 == true then print(" IC2: true") else print(" IC2: false") end
  202. if ZI == true then print(" ZI: true") else print(" ZI: false") end
  203. if dynamic == "y" then print(" Dynamic Scaling: true") else print(" Dynamic Scaling: false") end
  204. if options == "y" then
  205. term.setTextColour(colors.red)
  206. print("\nAdvanced Options")
  207. term.setTextColour(colors.blue)
  208. print(" Title Text Color: "..colorTT)
  209. print(" Title Background: "..colorTB)
  210. print(" Background Color: "..colorMB)
  211. print(" Statistics Color: "..colorST)
  212. print(" Bar Percent Text: "..colorBT)
  213. print(" Bars Empty Color: "..colorBE)
  214. print(" Bar Filled Color: "..colorBF)
  215. print(" Positive Change: "..colorPos)
  216. print(" Negative Change: "..colorNeg)
  217. end
  218. term.setTextColour(colors.gray)
  219. print("Million < Billion < Trillion < Quadrillion")
  220. term.setTextColour(colors.red)
  221. print("\nIf settings are incorrect. Run setup.lua")
  222. print("Hold CTRL+T to stop program")
  223.  
  224. --RF/EU label
  225. if IC2 == true then energyAPI = " EU" else energyAPI = " RF" end
  226. if IC2 == true then energyAPI_ = "EU" else energyAPI_ = "RF" end
  227.  
  228. --Wraps the Monitor
  229. mon = peripheral.find("monitor")
  230. monX,monY = mon.getSize()
  231. textScale()
  232.  
  233. monX,monY = mon.getSize()
  234. oldE,newE,curE,maxE = 0,0,0,0
  235.  
  236. while true do
  237. if dynamic == "y" then textScale() end
  238.  
  239. --Main Program
  240. --Variables for Calculations
  241. if mekanism == true then maxE = cube.getMaxEnergy() or 1
  242. elseif IC2 == true then maxE = cube.getEUCapacity() or 1
  243. else maxE = cube.getMaxEnergyStored() or 1
  244. end
  245. if mekanism == true then curE = cube.getEnergy() or 1
  246. elseif IC2 == true then curE = cube.getEUStored() or 1
  247. else curE = cube.getEnergyStored() or 1
  248. end
  249. if mekanism == true then
  250. maxE = math.floor(maxE/2.5)
  251. curE = math.floor(curE/2.5)
  252. end
  253.  
  254. percent = math.floor(((curE/maxE)*100)+0.5)
  255. bar = math.floor(((curE/maxE)*(monX-2))+0.5)
  256. stats = curE
  257.  
  258. --Redstone Output
  259. if redstone == "y" then
  260. if bundled == "1" then
  261. if percent >= 99 then
  262. rs.setBundledOutput(side,convert(colorPR))
  263. else rs.setBundledOutput(side,0)
  264. end
  265. else
  266. if percent >= 99 then
  267. rs.setOutput(side,true)
  268. else rs.setOutput(side,false)
  269. end
  270. end
  271. end
  272.  
  273. --Centers and Displays Title On Monitor
  274.  
  275. clearScreen()
  276. mon.setBackgroundColour(colors.black)
  277. mon.setTextColour(colors.lightGray)
  278. mon.setCursorPos(1,1)
  279. centerTextC(string.rep(" ",string.len(title)+2),1,convert(colorTB),convert(colorTT))
  280. centerTextC(title,1,convert(colorTB),convert(colorTT))
  281.  
  282. --Monitor Statistics
  283. --[[if curE >= 1000000 and curE <= 1000000000 then
  284. stats = math.floor(stats/1000)
  285. stats = (stats/1000)
  286. mbtq = " M"
  287. else]]if curE >= 1000000000 and curE <= 1000000000000 then
  288. stats = math.floor(stats/100000)
  289. stats = (stats/1000)
  290. mbtq = " B"
  291. elseif curE >= 1000000000000 and curE <= 1000000000000000 then
  292. stats = math.floor(stats/100000000)
  293. stats = (stats/1000)
  294. mbtq = " T"
  295. elseif curE >= 1000000000000000 then
  296. stats = math.floor(stats/100000000000)
  297. stats = (stats/1000)
  298. mbtq = " Q"
  299. elseif curE <= 1000000 then mbtq = " "
  300. end
  301. mon.setBackgroundColour(convert(colorMB))
  302. mon.setTextColour(convert(colorST))
  303. if curE >= 1000000 then eAPI = energyAPI_ else eAPI = energyAPI end
  304. centerText(stats..mbtq..eAPI,3)
  305. --[[
  306. if monX >= math.floor(string.len(stats)+9)
  307. then
  308. centerText("Total:"..stats..mbtq..eAPI,3)
  309. else
  310. centerText("Total:",3)
  311. centerText(stats..mbtq..eAPI,4)
  312. end
  313. ]]
  314.  
  315. --Change Per Tick Calculator and Display
  316. e_Change = eChange()
  317. if e_Change >= 0 then sign = "+" elseif e_Change <= 0 then sign = "-" end
  318. if e_Change >= 0 then signC = colorPos elseif e_Change <= 0 then signC = colorNeg end
  319. centerTextC(sign..e_Change..energyAPI.."/t",5,convert(colorMB),convert(signC))
  320.  
  321. centerTextC(percent.."% Full",monY-3,convert(colorMB),convert(colorBT))
  322.  
  323. --Loading Bar Code Re-Written Much MUCH simpler than before
  324. mon.setCursorPos(2,monY-2)
  325. mon.setBackgroundColour(convert(colorBE))
  326. mon.write(string.rep(" ",monX-2))
  327. mon.setCursorPos(2,monY-2)
  328. mon.setBackgroundColour(convert(colorBF))
  329. mon.write(string.rep(" ",bar))
  330.  
  331. mon.setCursorPos(2,monY-1)
  332. mon.setBackgroundColour(convert(colorBE))
  333. mon.write(string.rep(" ",monX-2))
  334. mon.setCursorPos(2,monY-1)
  335. mon.setBackgroundColour(convert(colorBF))
  336. mon.write(string.rep(" ",bar))
  337.  
  338. if rate == "f" then os.sleep(1)
  339. elseif rate == "s" then os.sleep(5)
  340. else os.sleep(5) end
  341. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement