Advertisement
Guest User

Untitled

a guest
May 30th, 2015
227
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.17 KB | None | 0 0
  1.  
  2. local computer = require("computer")
  3. local component = require("component")
  4. local sides = require("sides")
  5.  
  6. local Black = 0x000000
  7. local Blue = 0x0000FF
  8. local Green = 0x008000
  9. local Red = 0xFF0000
  10. local White = 0xFFFFFF
  11. local Yellow = 0xFFFF00
  12.  
  13. local gpu = component.gpu
  14. local batBuffer = component.batterybuffer_16_tier_03
  15. local w, h = gpu.getResolution()
  16. local previousCharge = 0
  17. local refreshRate = 5
  18.  
  19. local function round(num) return math.floor(num+.5) end
  20.  
  21. local function drawMainScreen()
  22. gpu.setBackground(Black)
  23. gpu.fill(1, 1, w, h, " ") -- clears the screen
  24. gpu.setForeground(Yellow)
  25. gpu.setResolution(17, 3)
  26. end
  27.  
  28. local function getStoredCharge(c)
  29. local inv = c.getAllStacks()
  30. local storedCharge = 0
  31. local maxCharge = 0
  32. local differenceCharge = 0
  33. for i = 1, c.getInventorySize(), 1 do
  34. if inv[i] == nil then
  35. else
  36. storedCharge = storedCharge + inv[i].charge
  37. maxCharge = maxCharge + inv[i].maxCharge
  38. end
  39. end
  40. maxCharge = maxCharge + c.getEUCapacity()
  41. storedCharge = storedCharge + c.getStoredEU()
  42. if previousCharge > storedCharge then
  43. differenceCharge = 0
  44. previousCharge = storedCharge
  45. else
  46. differenceCharge = 1
  47. previousCharge = storedCharge
  48. end
  49. return maxCharge, storedCharge, differenceCharge
  50. end
  51.  
  52. local function updateScreen()
  53. local maxCharge, storedCharge, differenceCharge = getStoredCharge(batBuffer)
  54. gpu.fill(1, 2, 17, 3, " ")
  55. gpu.fill(1, 3, 17, 3, " ")
  56. gpu.setForeground(Blue)
  57. gpu.set(1, 1, "Stored EU")
  58. gpu.setForeground(Yellow)
  59. gpu.set(1, 2, "Max: " .. maxCharge .. " EU")
  60. if differenceCharge == 0 then
  61. gpu.setForeground(Red)
  62. else
  63. gpu.setForeground(Green)
  64. end
  65. gpu.set(1, 3, tostring(storedCharge) .. " EU " .. tostring(round(((storedCharge/maxCharge)*100))) .. "%")
  66. end
  67.  
  68. drawMainScreen()
  69. while true do
  70. updateScreen()
  71. os.sleep(refreshRate)
  72. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement