Advertisement
Clorith

Untitled

Dec 18th, 2014
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.93 KB | None | 0 0
  1. -- Load and configure dependencies, don't touch!
  2. os.loadAPI( "ProgressBar" )
  3.  
  4. -- Configurable settings go here
  5. monitorLocation = "front"
  6. rednetLocation = "right"
  7. monitorFontSize = 1.5
  8. -- Configurable settings end
  9.  
  10. -- Prepare dependencies
  11. monitor = peripheral.wrap( monitorLocation )
  12. monitor.clear()
  13. monitor.setTextScale( monitorFontSize )
  14.  
  15. local monitorSize = monitor.getSize()
  16. barWidth = ( monitorSize / monitorFontSize ) + 15
  17. textPosition = barWidth + 15
  18.  
  19. ProgressBar.SetPeripheral( monitorLocation )
  20.  
  21. monitor.setCursorPos( 5, 4 )
  22. monitor.write( "Energy storage (0/0)" )
  23. ProgressBar.SetTable( "Power", 100, 0, 5, barWidth, 5 )
  24. ProgressBar.DrawToPeripheral()
  25.  
  26. monitor.setCursorPos( 5, 7 )
  27. monitor.write( "AE Storage (0/0)" )
  28. ProgressBar.SetTable( "AEBytes", 100, 0, 5, barWidth, 8 )
  29. ProgressBar.DrawToPeripheral()
  30. --
  31.  
  32. function stringSplit( str )
  33. local t = {}
  34.  
  35. local function helper( word )
  36. table.insert( t, word )
  37. return ""
  38. end
  39.  
  40. if not str:gsub( "%w+", helper ):find"%S" then
  41. return t
  42. end
  43. end
  44.  
  45. function parseMsg( id, msg )
  46. local incomingLine = stringSplit( msg )
  47. if "power" == incomingLine[1] then
  48. local used = incomingLine[2]
  49. local available = incomingLine[3]
  50. local remainder = ( used / available ) * 100
  51.  
  52. ProgressBar.SetCurValue( "Power", remainder )
  53. monitor.setCursorPos( 5, 4 )
  54. monitor.write( "Energy storage (" .. used .. " / " .. available .. ")" )
  55. end
  56.  
  57. if "ae" == incomingLine[1] then
  58. local used = incomingLine[2]
  59. local available = incomingLine[3]
  60. local remainder = ( used / available ) * 100
  61.  
  62. ProgressBar.SetCurValue( "AEBytes", remainder )
  63. monitor.setCursorPos( 5, 4 )
  64. monitor.write( "AE Storage (" .. used .. " / " .. available .. ")" )
  65. end
  66.  
  67. ProgressBar.DrawToPeripheral()
  68. end
  69.  
  70.  
  71.  
  72. rednet.open( rednetLocation )
  73.  
  74. while true do
  75. id, msg, time = rednet.receive()
  76. print( msg )
  77. print( id )
  78.  
  79. parseMsg( id, msg )
  80. end
  81.  
  82. rednet.close( rednetLocation )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement