Ledger Nano X - The secure hardware wallet
SHARE
TWEET

test2

a guest Apr 8th, 2020 139 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local charts = require("charts") --Using the Charts Library (https://oc.cil.li/topic/1359-charts-library/)
  2. local component = require("component")
  3. local event = require("event")
  4. local term = require("term")
  5. local text = require("text")
  6.  
  7. term.clear()
  8. local gpu = term.gpu()
  9. gpu.setResolution(96, 30) --to make the text bigger, using a 3x2 monitor
  10.  
  11. local matrix = component.list("induction_matrix")
  12. for a, _ in pairs(matrix) do matrix = component.proxy(a) end
  13. local maxEnergy = math.floor(matrix.getMaxEnergy() / 2.5 ) --values are 2.5x higher than listed in the matrix gui for some reason, this fixes it
  14. --local transferCap = matrix.getTransferCap()  --saving in case I need the value in the future
  15.  
  16. local powerBar = charts.Container{
  17.   x = 1,
  18.   y = 1,
  19.   width = 96,
  20.   height = 5,
  21.   payload = charts.ProgressBar {
  22.     direction = charts.sides.RIGHT,
  23.     value = 0,
  24.     min = 0,
  25.     max = maxEnergy,
  26.     colorFunc = function(_, perc )
  27.       if perc >= .9 then
  28.         return 0x00db00
  29.       end
  30.       if perc >= .75 then
  31.         return 0x99db00
  32.       end
  33.       if perc >= .5 then
  34.         return 0xffdb00
  35.       end
  36.       if perc >= .25 then
  37.         return 0xff4900
  38.       end
  39.       if perc >= .1 then
  40.         return 0xff0000
  41.       end
  42.     end
  43.   }
  44. }
  45.  
  46. local inputHist = charts.Container {
  47.   x = 1,
  48.   y = 6,
  49.   width = 48,
  50.   height = 24,
  51.   payload = charts.Histogram {
  52.     max = 1,
  53.     maxSeen = 1,
  54.     colorFunc = function(index, norm, value, self, container)
  55.       return 0x0049ff
  56.     end
  57.   }
  58. }
  59. local outputHist = charts.Container {
  60.   x = 49,
  61.   y = 6,
  62.   width = 48,
  63.   height = 24,
  64.   payload = charts.Histogram {
  65.     max = 1,
  66.     maxSeen = 1,
  67.     colorFunc = function(index, norm, value, self, container)
  68.       return 0xff6d40
  69.     end
  70.   }
  71. }
  72.  
  73. function centerText(_str, x1, x2)  --function to write text centered between two X values
  74.   local x1 = x1 or 1  --if no values for x are given, assume full screen.
  75.   local x2 = x2 or 96
  76.   local start = math.floor(((x2 - x1) - #_str)/2) + x1
  77.   local _, y = term.getCursor()
  78.   term.setCursor(start, y)
  79.   term.write(_str)
  80. end
  81.  
  82. function comma_value(amount) --format big numbers with commas.
  83.   local formatted = tostring(amount)
  84.   while true do  
  85.     formatted, k = string.gsub(formatted, "^(-?%d+)(%d%d%d)", '%1,%2')
  86.     if (k==0) then
  87.       break
  88.     end
  89.   end
  90.   return formatted
  91. end
  92.  
  93. function round(num, numDecimalPlaces)
  94.   local mult = 10^(numDecimalPlaces or 0)
  95.   num = math.floor(num * mult + 0.5) / mult
  96.   if num ~= 100 then
  97.     return string.format("%."..numDecimalPlaces.."f", num)
  98.   end
  99.   return "100"
  100. end
  101.  
  102. function sum(table)
  103.     local sum = 0
  104.     for k,v in pairs(table) do
  105.         sum = sum + v
  106.     end
  107.     return sum
  108. end
  109.  
  110. function getMaxValue(table)  --find the maximum value in a table
  111.   local highest = 1
  112.   for _,v in pairs(table) do
  113.     if v > highest then highest = v end
  114.   end
  115.   return highest
  116. end
  117.  
  118. function setMaxValue()  --Makes sure the Histograms are using the same scale
  119.   local highest = 1
  120.   local inMax = getMaxValue(inputHist.payload.values)
  121.   local outMax = getMaxValue(outputHist.payload.values)
  122.   if inMax > highest then highest = inMax end
  123.   if outMax > highest then highest = outMax end
  124.   inputHist.payload.max = highest
  125.   outputHist.payload.max = highest
  126. end
  127.  
  128.  
  129.  
  130. while true do
  131.   --local startTime = computer.uptime()
  132.   local _, _, x, y = event.pull( 1, "touch" )
  133.   if x and y then goto quit end
  134.  
  135.   local energy = math.floor(matrix.getEnergy() * 0.4)  --values are 2.5x higher than listed in the matrix gui for some reason, this fixes it
  136.   local input = math.floor(matrix.getInput() * 0.4)
  137.   local output = math.floor(matrix.getOutput() * 0.4)
  138.    
  139.   table.insert(inputHist.payload.values, input)
  140.   table.insert(outputHist.payload.values, output)
  141.   powerBar.payload.value = energy
  142.  
  143.   if #inputHist.payload.values > 48 then --don't let the Histograms overflow their area and stop displaying data
  144.     table.remove(inputHist.payload.values, 1)
  145.     table.remove(outputHist.payload.values, 1)
  146.   end
  147.   setMaxValue()
  148.  
  149.   powerBar:draw()
  150.   inputHist:draw()
  151.   outputHist:draw()
  152.  
  153.   --Gotta write the labels and numbers on top of the Bar and Histograms.
  154.  
  155.   term.setCursor(1,1)
  156.   centerText("Induction Matrix")
  157.   term.setCursor(1, 2)
  158.   local tmp = comma_value(energy * 2.5).." RF"  
  159.   centerText(tmp)
  160.   tmp = round(((energy/maxEnergy) * 100), 2) .. "%"
  161.   term.setCursor(1,3)
  162.   centerText(tmp)
  163.   term.setCursor(1,4)
  164.   tmp = (sum(inputHist.payload.values) - sum(outputHist.payload.values))/48
  165.   tmp = round(tmp, 0)
  166.   tmp = comma_value(tmp)
  167.   tmp = "Average I/O Rate: " .. tmp .. " RF/t"
  168.   centerText(tmp)
  169.   term.setCursor(1, 28)
  170.   centerText("Input Rate", 1, 48)
  171.   centerText("Output Rate", 49, 96)
  172.   term.setCursor(1, 29)
  173.   tmp = comma_value(input / 3.2).." RF"
  174.   centerText(tmp, 1, 48)  
  175.    tmp = comma_value(output / 3.2).." RF"
  176.   centerText(tmp, 49, 96)
  177.  
  178.   --term.setCursor(1, 15)
  179.   --centerText(tostring(computer.uptime()-startTime))
  180. end
  181.  
  182. ::quit::
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top