Advertisement
Guest User

startup

a guest
Nov 14th, 2019
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.66 KB | None | 0 0
  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 / 10000)
  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. monitor = peripheral.wrap("bottom")
  53. battery = peripheral.find("Induction Matrix")
  54.  
  55. -- Check and bind monitor
  56. if monitor == nil then
  57.   error("ER: No screen found to display!")
  58. else
  59.   monitor.clear()
  60.   term.redirect(monitor)
  61.   term.setCursorPos(1, 1)
  62.   term.setBackgroundColor(colors.black)
  63. end
  64.  
  65. -- Check if we have a battery
  66. if battery == nil then
  67.   error("ER: No battery connected to computer")
  68. end
  69.  
  70. -- Draw our static fill volume box
  71. term.setTextColor(colors.white)
  72. term.setCursorPos(2, 2)
  73. print("+------+")
  74. term.setCursorPos(2, 11)
  75. print("+------+")
  76. for i = 3, 10 do
  77.   term.setCursorPos(2, i)
  78.   print("|")
  79.   term.setCursorPos(9, i)
  80.   print("|")
  81. end
  82.  
  83. -- Draw our static interface text
  84. term.setCursorPos(11, 2);
  85. print("Max RF:")
  86. term.setCursorPos(11, 3);
  87. print("Max Thru:")
  88.  
  89. term.setCursorPos(11, 5);
  90. print("Cur In:")
  91. term.setCursorPos(11, 6);
  92. print("Cur Out:")
  93. term.setCursorPos(11, 7);
  94. print("Cur Bal:")
  95.  
  96. term.setCursorPos(11, 9);
  97. print("Stored:")
  98. term.setCursorPos(11, 10);
  99. print("Filled:")
  100. term.setCursorPos(11, 11);
  101. print("Critical:")
  102.  
  103.  
  104. -- Entering our infinite loop of checking the battery
  105. -- This will refresh all information every 2 seconds
  106. alarmIsRinging = false
  107. alarmIsActive = false
  108. alarmCounter = 0
  109.  
  110. while true do
  111.  
  112.   -- Get our fixed battery values
  113.   batteryMaxCharge = battery.getMaxEnergy()
  114.   batteryMaxInOuts = battery.getTransferCap()
  115.   putValue(2, putNumber(batteryMaxCharge), colors.lightBlue)
  116.   putValue(3, putNumber(batteryMaxInOuts), colors.lightBlue)
  117.  
  118.   -- Get our input/output/balance battery values
  119.   batteryCurrentIn = battery.getInput()
  120.   batteryCurrentOut = battery.getOutput()
  121.   putValue(5, putNumber(batteryCurrentIn), colors.lightBlue)
  122.   putValue(6, putNumber(batteryCurrentOut), colors.lightBlue)
  123.  
  124.   batteryCurrentBalance = batteryCurrentIn - batteryCurrentOut
  125.   batteryCurrentColor = (batteryCurrentBalance >= 0) and colors.green or colors.red
  126.   batteryCurrentSign = (batteryCurrentBalance >= 0) and "+" or ""
  127.   putValue(7, batteryCurrentSign .. putNumber(batteryCurrentBalance), batteryCurrentColor)
  128.  
  129.   -- Get our statistical values
  130.   batteryCurrentCharge = battery.getEnergy()
  131.   putValue(9, putNumber(batteryCurrentCharge), colors.lightBlue)
  132.  
  133.   batteryCurrentColor = colors.red
  134.   batteryCurrentPercentage = ((batteryCurrentCharge / batteryMaxCharge) * 100)
  135.   if batteryCurrentPercentage > 30 then batteryCurrentColor = colors.orange end
  136.   if batteryCurrentPercentage > 60 then batteryCurrentColor = colors.green end
  137.   putValue(10, string.sub(putNumber(batteryCurrentPercentage), 0, 4) .. "%", batteryCurrentColor)
  138.  
  139.   batteryCurrentCritical = "Yes"
  140.   batteryCurrentColor = colors.red
  141.   if batteryCurrentPercentage > 15 then
  142.     batteryCurrentCritical = "No"
  143.     batteryCurrentColor = colors.green
  144.   end
  145.   putValue(11, batteryCurrentCritical, batteryCurrentColor)
  146.  
  147.   -- Draw the current charge graph
  148.   batteryCurrentColor = colors.red
  149.   if batteryCurrentPercentage > 30 then term.setTextColor(colors.orange) end
  150.   if batteryCurrentPercentage > 60 then term.setTextColor(colors.green) end
  151.   if batteryCurrentPercentage >= 100 then term.setTextColor(colors.lightBlue) end
  152.  
  153.   for i = 3, 10 do
  154.     term.setCursorPos(3, i)
  155.     print("      ")
  156.   end
  157.  
  158.   iterator = 0
  159.   for i = 3, 10 do
  160.     local compare = (12.5 * iterator)
  161.     if (batteryCurrentPercentage >= compare) then
  162.       term.setCursorPos(3, (13 - i))
  163.       local filler = ""
  164.       for i = 1, 6 do
  165.         local inhere = (compare + (i*2))
  166.         if batteryCurrentPercentage >= inhere then
  167.           filler = filler .. "#"
  168.         else
  169.           if batteryCurrentPercentage >= (inhere - 1) then
  170.             filler = filler .. "="
  171.           else
  172.             filler = filler .. "_"
  173.           end
  174.         end
  175.       end
  176.       print(filler)
  177.     end
  178.  
  179.     iterator = iterator + 1
  180.   end
  181.  
  182.   -- Hey, ring the alarm!
  183.   if batteryCurrentPercentage > 10 then
  184.     alarmIsRinging = false
  185.     alarmIsActive = false
  186.   end
  187.  
  188.   if batteryCurrentPercentage < 10 and alarmIsActive == false then
  189.     alarmIsRinging = true
  190.     alarmIsActive = true
  191.     alarmCounter = 0
  192.     redstone.setOutput("left", true)
  193.   end
  194.  
  195.   if alarmIsRinging == true then
  196.     alarmCounter = alarmCounter + 1
  197.     if alarmCounter >= 10 then
  198.       redstone.setOutput("left", false)
  199.       alarmIsRinging = false
  200.     end
  201.   end
  202.  
  203.   -- Wait 2s until next iteration
  204.   os.sleep(2)
  205.  
  206. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement