Advertisement
Guest User

Untitled

a guest
Aug 12th, 2017
431
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.10 KB | None | 0 0
  1. batboxex = 0
  2. cesus = 0
  3. mfes = 0
  4. mfsus = 0
  5. mon = 0
  6. debug = 0
  7.  
  8. term.clear()
  9. term.setCursorPos(1, 1)
  10. print("Press any key for debug mode")
  11. while true do
  12. os.starttimer(3)
  13. local event = os.pullEvent()
  14. if event == "timer" then break
  15. else
  16. debug = 1
  17. break
  18. end
  19. end
  20. term.clear()
  21.  
  22. term.setCursorPos(1, 1)
  23. if debug == 1 then
  24. print("Scanning for connected IC2 storage devices..")
  25. sleep(2)
  26. print("Peripherals detected:\n")
  27. sleep(0.5)
  28. end
  29. tBatbox = {}
  30. tCesu = {}
  31. tMfe = {}
  32. tMsfu = {}
  33. tMon = {}
  34. tMonName = {}
  35.  
  36. for_,name in pairs(peripheral.getNames()) do
  37. if debug == 1 then
  38. print(name.." "..peripheral.getType(name))
  39. sleep(0.15)
  40. end
  41. if name:match"batbox" then
  42. batboxes = batboxes+1
  43. tBatbox[#Batbox+1] = peripheral.wrap(name)
  44. elseif name:match"cesu" then
  45. cesus = cesus+1
  46. tCesu[#tCesu+1] = peripheral.wrap(name)
  47. elseif name:match"mfe" then
  48. mfes = mfes+1
  49. tMfsu[#tMfsu+1] = peripheral.wrap(name)
  50. elseif name:match"mfsu" then
  51. mfsus = mfsus+1
  52. tMfsu[#tMfsu+1] = peripheral.wrap(name)
  53. elseif peripheral.getType(name) == "monitor" then
  54. mon = mon+1
  55. tMonName[mon] = name
  56. tMon[mon] = peripheral.wrap(name)
  57. tMon[mon].clear()
  58. end
  59. end
  60.  
  61. if debug == 1 then
  62. sleep(2)
  63. term.clear()
  64. term.setCursorPos(1, 1)
  65. sleep(0.25)
  66. end
  67. total = batboxes+cesus+mfes+mfsus
  68.  
  69. if total > 0 then
  70. print("The following storage devices are connected\n")
  71. sleep(1)
  72. print("Batbox: ", batboxes)
  73. sleep(0.25)
  74. print("CESU: ", cesus)
  75. sleep(0.25)
  76. print("MFE: ", mfes)
  77. sleep(0.25)
  78. print("MFSU: ", mfsus)
  79. sleep(1)
  80. else
  81. debug = 1
  82. term.setTextColor(colors.red)
  83. print("ERROR;\n\nNo Storage devices found!\n\nTerminating")
  84. term.setTextColor(colors.white)
  85. os.exit()
  86. end
  87.  
  88. if debug == 1 then
  89. print(" ")
  90. if batboxes > 0 then
  91. for i = 1,batboxes do
  92. print("Wrapped batbox at\"tBatbox[", i, "]\"")
  93. sleep(0.15)
  94. end
  95. end
  96. print(" ")
  97. if cesus > 0 then
  98. for i = 1, cesus do
  99. print("Wrapped CESUS at \"tCesu[", i, "]\"")
  100. sleep(0.15)
  101. end
  102. end
  103. print(" ")
  104. if mfes > 0 then
  105. for i = 1, mfes do
  106. print("Wrapped MFE at \"tMfe[", i, "]\"")
  107. sleep(0.15)
  108. end
  109. end
  110. print(" ")
  111. if mfsus > 0 then
  112. for i = 1, mfsus do
  113. print("Wrapped MFSU at \"tMfsu[", i, "]\"")
  114. sleep(0.15)
  115. end
  116. end
  117. sleep(5)
  118. end
  119. term.clear()
  120. sleep(0.15)
  121. term.setCursorPos(1, 1)
  122. print("Ready to monitor ", total, " energy storage devices.")
  123. sleep(0.5)
  124.  
  125. --Device detection and wrapping complete
  126.  
  127. if mon > 0 then
  128. print("\nWhere do you want to output the data?\n")
  129. sleep(0.15)
  130. print("0 - this Terminal")
  131. for i = 1,mon do
  132. print(i, " - ", tMonName[i])
  133. end
  134.  
  135. while true do
  136. monout = io.read()
  137. monout = tonumber(monout)
  138. if (monout > 0) and (monout < mon+1) then
  139. monitor = tMon[monout]
  140. break
  141. elseif monout == 0 then
  142. monitor = term
  143. break
  144. elseif mon == 0 then
  145. monitor = term
  146. break
  147. else print("Not a valid output")
  148. end
  149. end
  150. end
  151.  
  152. pbat = {}
  153. fbat = {}
  154. pces = {}
  155. fces = {}
  156. pmfe = {}
  157. fmfe = {}
  158. pmfs = {}
  159. fmfs = {}
  160. totalcap = 0
  161.  
  162. if batboxes > 0 then
  163. cbat = tBatobx[1].getEUCapacity()
  164. totalCap = totalCap+cbat*batboxes
  165. end
  166.  
  167. if cesus > 0 then
  168. cces = tCesu[1].getEUCapacity()
  169. totalCap = totalCap+cces*cesus
  170. end
  171.  
  172. if mfes > 0 then
  173. cmfe = tMfe[1].getEUCapacity()
  174. totalCap = totalCap+cmfe*mfes
  175. end
  176.  
  177. if mfsus > 0 then
  178. cmfs = tMfsu[1].getEUCapacity()
  179. totalCap = totalCap+cmfs*mfsus
  180. end
  181.  
  182. function round(num, idp)
  183. local mult = 10^(idp or 0)
  184. return math.floor(num*mult+0.5)/mult
  185. end
  186.  
  187. while true do
  188. monitor.clear()
  189. monitor.setCursorPos(1, 1)
  190. monitor.write("unit | EU stored | Eu Capacity | Fill")
  191. monitorsetCursorPos(1, 2)
  192. monitor.write("------+-------------+---------------+-----")
  193. line = 3
  194. totalFill=0
  195.  
  196. for i = 1, batboxes do
  197. pbat[i] = tBatbox[i].getEUStored()
  198. fbat[i] = round(pbat[i]/cbat*100, 0)
  199. totalFill = totalFill+pbat[i]
  200. if pbat[i] < 10 then
  201. length = 4
  202. elseif pbat[i] < 100 then
  203. length = 3
  204. elseif pbat[i] < 1000 then
  205. length = 2
  206. elseif pbat[i] < 100000 then
  207. length = 1
  208. else
  209. length = 0
  210. end
  211.  
  212. if pbat[i] == 0 then
  213. fbat[i] = 0
  214. lengthf = 2
  215. elseif fbat[i] < 10 then
  216. lengthf = 2
  217. elseif fbat[i] < 100 then
  218. lengthf = 1
  219. else
  220. lengthf = 0
  221. end
  222.  
  223. monitor.setCursorPos(1, line)
  224. monitor.write("BatB"...i.." |")
  225. monitor.setCursorPos(14+length, line)
  226. monitor.write(pbat[i].." |")
  227. monitor.setCursorPos(28, line)
  228. monitor.write(cbat.." |")
  229. monitor.setCursorPos(36+lengthf, line)
  230. monitor.write(fbat[i].."%")
  231. line = line+1
  232. end
  233.  
  234. for i = 1,cesus do
  235. pces[i] = tCesu[i].getEUStored()
  236. fces[i] = round(pces[i]/cces*100, 0)
  237. totalFill = totalFill+pces[i]
  238. if pces[i] < 10 then
  239. length = 5
  240. elseif pces[i] < 100 then
  241. length = 4
  242. elseif pces[i] < 1000 then
  243. length = 3
  244. elseif pces[i] <10000
  245. length = 2
  246. elseif pces[i] <100000
  247. length = 1
  248. else
  249. length = 0
  250. end
  251.  
  252. if pces[i] == 0 then
  253. fces[i] = 0
  254. lengthf = 2
  255. elseif fces[i] < 10 then
  256. lengthf = 2
  257. elseif fces[i] < 100 then
  258. lengthf = 1
  259. else
  260. lengthf = 0
  261. end
  262. monitor.setCursorPos(1, line)
  263. monitor.write("CESU"..i.." |")
  264. monitor.setCursorPos(13+length, line)
  265. monitor.write(pces[i].." |")
  266. monitor.setCursorPos(27, line)
  267. monitor.write(cces.." |")
  268. monitor.setCursorPos(36+lengthf, line)
  269. monitor.write(fces[i].."%")
  270. line = line+1
  271.  
  272. end
  273.  
  274. for i = 1, mfes do
  275. pmfe[i] = tMfe[i].getEUStored()
  276. fmfe[i] = round(pmfe[i]/cmfe*100, 0)
  277. totalFill = totalFill+pmfe[i]
  278. if pmfe[i] < 10 then
  279. length = 6
  280. elseif pmfe[i] < 100 then
  281. length = 5
  282. elseif pmfe[i] < 1000 then
  283. length = 4
  284. elseif pmfe[i] < 10000 then
  285. length = 3
  286. elseif pmfe[i] < 100000 then
  287. length = 2
  288. elseif pmfe[i] < 1000000 then
  289. length = 1
  290. else
  291. length = 0
  292. end
  293.  
  294. if pmfe[i] == 0 then
  295. fmfe[i] = 0
  296. lengthf = 2
  297. elseif fmfe[i] < 10 then
  298. lengthf = 2
  299. elseif fmfe[i] < 100 then
  300. lengthf = 1
  301. else
  302. lengthf = 0
  303. end
  304.  
  305. monitor.setCursorPos(1, line)
  306. monitor.write("MFE"..i.." |")
  307. monitor.setCursorPos(12+length, line)
  308. monitor.write(pmfe[i].." |")
  309. monitor.setCursorPos(26, line)
  310. monitor.write(cmfe.." |")
  311. monitor.setCursorPos(36+lengthf, line)
  312. monitor.write(fmfe[i].."%")
  313. line = line+1
  314. end
  315.  
  316. for i = 1, mfsus do
  317. pmfs[i] = tMfsu[i].getEUStored()
  318. fmfs[i] = round(pmfs[i]/cmfs*100, 0)
  319. totalFill = totalFill+pmfs[i]
  320. if pmfs[i] < 10 then
  321. length = 7
  322. elseif pmfs[i] < 100 then
  323. length = 6
  324. elseif pmfs[i] < 1000 then
  325. length = 5
  326. elseif pmfs[i] < 10000 then
  327. length = 4
  328. elseif pmfs[i] < 100000 then
  329. length = 3
  330. elseif pmfs[i] < 1000000 then
  331. length = 2
  332. elseif pmfs[i] < 10000000 then
  333. length = 1
  334. else
  335. length = 0
  336. end
  337.  
  338. if pmfs == 0 then
  339. fmfs[i] = 0
  340. lengthf = 2
  341. elseif fmfs[i] < 10 then
  342. lengthf = 2
  343. elseif fmfs[i] < 100 then
  344. lengthf = 1
  345. else
  346. lengthf = 0
  347. end
  348. monitor.setCursorPos(1, line)
  349. monitor.write("MFSU"..i.." |")
  350. monitor.setCursorPos(11+length, line)
  351. monitor.write(pmfs[i].." |")
  352. monitor.setCursorPos(25, line)
  353. monitor.write(cmfs.." |")
  354. monitor.setCursorPos(36+lengthf, line)
  355. monitor.write(fmfs[i].."%")
  356. line = line+1
  357.  
  358. end
  359. if total < 17 then
  360. monitor.setCursorPos(1, 19)
  361. monitor.setBackgroundColor(colors.gray)
  362. totalFill = totalFill / totalCap * 100
  363. monitor.write(" ")
  364. fFilled = totalFill*0.39
  365. fFilled = round(fFilled, 0)
  366. for i = 1, fFilled do
  367. monitor.setBackgroundColor(colors.white)
  368. monitor.setCursorPos(i, 19)
  369. monitor.write(" ")
  370. end
  371. end
  372. monitor.setBackgroundColor(colors.black)
  373. sleep(0.1)
  374. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement