Advertisement
gpochy

prijembaterynew

Jul 1st, 2016
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.47 KB | None | 0 0
  1. local mon = peripheral.wrap("top")
  2. rednet.open("right")
  3.  
  4. local kapacitapos = 0
  5. local x=1
  6. local nazev = "Reaktor"
  7.  
  8. mon.setBackgroundColor(colors.black)
  9. mon.setTextScale(1)
  10.  
  11. function comma_value(amount)
  12.    local formatted = amount
  13.    local swap = false
  14.    if formatted < 0 then
  15.       formatted = formatted*-1
  16.       swap = true
  17.    end
  18.    while true do
  19.       formatted, k = string.gsub(formatted, "^(%d+)(%d%d%d)", '%1,%2')
  20.       if k == 0 then
  21.          break
  22.       end
  23.    end
  24.    if swap then
  25.      formatted = "-"..formatted
  26.    end
  27.    return formatted
  28. end
  29.  
  30. function bar(a)
  31. w,h = mon.getSize()
  32. mon.setCursorPos(2,a)
  33. mon.setTextScale(0.5)
  34. mon.setBackgroundColor(colors.gray)
  35. for i=1, w-2 do
  36. mon.write(" ")
  37. end
  38. mon.setCursorPos(2,a+1)
  39. mon.write(" ")
  40. mon.setBackgroundColor(colors.lime)
  41. barproc = (w-4)/100
  42. barproc = math.floor(barproc*kapacitaproc)
  43. for i=1, barproc do
  44. mon.write(" ")
  45. end
  46. mon.setBackgroundColor(colors.gray)
  47. for i=1, w-barproc-3 do
  48. mon.write(" ")
  49. end
  50. mon.setCursorPos(2,a+2)
  51. for i=1, w-2 do
  52. mon.write(" ")
  53. end
  54.  
  55. --mon.setTextScale(1)
  56. mon.setCursorPos(w-1,a)
  57. mon.setBackgroundColor(colors.black)
  58.  
  59. end
  60.  
  61.  
  62. while true do
  63. --local event, side, xx, yy = os.pullEvent("monitor_touch")
  64. local event, p1, p2, p3 = os.pullEvent()
  65. if event=="rednet_message" then
  66.  
  67. rednet.receive(1) --ceka 1s na prijem
  68.  
  69. if p1==14 then --14 je id vysilace
  70. mon.clear()
  71. mon.setCursorPos(1,1)
  72. celkem = p2[2]
  73. kapacita = p2[1]
  74.     if kapacitapos == 0 then
  75.         kapacitapos = kapacita
  76.     end
  77. kapacitaroz = kapacita - kapacitapos
  78.  
  79. kapacitaroz = kapacitaroz/20
  80. proc = celkem/100
  81. kapacitaproc = kapacita/proc
  82. kapacitaproc = math.floor(kapacitaproc)
  83. kapacita = math.floor(kapacita)
  84. kapacitaroz = math.floor(kapacitaroz)
  85. --tik = kapacita - kapacitapos
  86. mon.setCursorPos(1,x)
  87. mon.write(nazev)
  88. mon.setCursorPos(1,x+1)
  89. mon.write("Kapacita: "..comma_value(math.floor(kapacita)).." Rf")
  90. mon.setCursorPos(1,x+2)
  91. mon.write("Kapacita: "..kapacitaproc.." %")
  92.  
  93. if kapacitaroz>0 then
  94.   mon.setCursorPos(1,x+3)
  95.   mon.setTextColor(colors.lime)
  96.   mon.write("RF/tik : "..comma_value(math.floor(kapacitaroz)).." Rf")
  97.   mon.setTextColor(colors.white)
  98. else
  99.   mon.setCursorPos(1,x+3)
  100.   mon.setTextColor(colors.red)
  101.   mon.write("RF/tik : "..comma_value(math.floor(kapacitaroz)).." Rf")
  102.   mon.setTextColor(colors.white)
  103. end
  104. bar(7)
  105. mon.setCursorPos(1,x+5)
  106. mon.write("Celkova kapacita: "..comma_value(math.floor(celkem)).." Rf")
  107. end
  108.  
  109. kapacitapos = tonumber(p2[1])
  110. --sleep(1)
  111.  
  112. end
  113. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement