Advertisement
Marikc0

[DL] ComputerCraft OpenPeripherals Base Monitoring Program

Nov 15th, 2013
5,486
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 10.11 KB | None | 0 0
  1. -- ComputerCraft/OpenPeripherals Base Monitoring Program for MC 1.6.4
  2. -- Thanks: Fogger, @EsperNet: #OpenMods, #computercraft @Freenode: #lua
  3.  
  4. -- The color palette. You can add more.
  5. local palette = {["white"] = 1, ["orange"] = 2, ["magenta"] = 4, ["lightBlue"] = 8, ["yellow"] = 16,
  6. ["lime"] = 32, ["pink"] = 64, ["gray"] = 128, ["lightGray"] = 256, ["cyan"] = 512, ["purple"] = 1024,
  7. ["blue"] = 2048, ["brown"] = 4096, ["green"] = 8192, ["red"] = 16384, ["black"] = 32768}
  8.  
  9. -- *** CONFIG SECTION **
  10. -- MONITORS (the only required config change)
  11. local left = "monitor_0" -- first main display monitor
  12. local right = "monitor_1" -- second main display monitor
  13. local aux_1 = "monitor_5" -- auxiliary monitor for total power/capacity reading
  14. -- VARIOUS
  15. local activeMsg, inactiveMsg, pendingMsg = "USING", "INACT", "PENDI"
  16. local textSize = 1 -- increments of 0.5
  17. local isGPS = true -- should we look for and display a nearby GPS?
  18. -- MACHINE and PERIPHERAL NAMES --
  19. -- Use the same # of characters for each so that formatting is aligned
  20. local name_comp = "CMPRESR" -- compressor
  21. local name_furnace = "FURNACE" -- electric furnace
  22. local name_ext = "EXTRCTR" -- extractor
  23. local name_mace = "MACERTR" -- macerator
  24. local name_washer = "ORWASHR" -- ore washer
  25. local name_centrifuge = "THR_CTR" -- thermal centrifuge
  26. local name_former = "MTL_FRM" -- metal former
  27. local name_recycler = "RECYCLR" -- recycler
  28. local name_canning = "CAN_MCN" -- canning machine
  29. -- Name these whatever you wish, but it may not fit or alter alignment of other items
  30. local name_mfsu = "MFSU"
  31. -- COLORS
  32. local hc = palette.lightBlue -- default heading color
  33. local tc = palette.white -- default text color
  34. local color_reading = palette.lime -- power readings for example
  35. local color_inactive = palette.gray -- inactive reading for machines
  36. local color_active = palette.red -- active reading for machines
  37. local color_machines = palette.orange -- machine names
  38. local color_ores = palette.pink -- ore name color
  39. -- TEXT POSITIONS
  40. local pwrX_Reading = 20 -- X pos to display power readings
  41. local machineDisplayXPos = 6 -- X pos to start displaying machines
  42. local offsetPos = 2 -- left margin offset for text
  43. local mStatusPos = 11
  44. local orePos = 18
  45. -- SPECIAL CHARACTERS
  46. local separator = " | "
  47. local spacer = " : "
  48. -----------------------------------------------
  49.  
  50. local pversion = "1.3.5.1b"
  51.  
  52. local waitTime = {9,13}
  53. local timer = {0,0,0,0,0,0,0,0,0,0,0}
  54. local supported_Power = {"mfsu","cesu","mfe","batbox"}
  55. local supported_Machines = {"macerator","furnace","orewashing","thermalcentrifuge", "extractor",
  56. "compressor", "canning", "recycler", "metalformer"}
  57. local sleepAmt = 0.2
  58. local numFormat = 1 -- don't use it (yet) for multiple formatting types
  59. -- MACHINE SLOTS --
  60. local ic2ItemUsed = 7 -- input slot for most ic2 machines
  61. local ic2ItemCreated = 2 -- output slot for most ic2 machines
  62. local oreWashItemUsed = 9 -- input slot for orewasher
  63. local thermCentrItemUsed = 9 -- input slot for thermal centrifuge
  64.  
  65. -- Load API ---
  66. if fs.exists("marik") then shell.run("rm marik") end
  67. print("Updating API...")
  68. shell.run("pastebin get Th8tne6p marik")
  69. os.loadAPI("marik")
  70. ---------------
  71.  
  72. term.clear()
  73. print("Base Monitoring Program v" .. pversion)
  74. print("Starting...")
  75.  
  76. machines = peripheral.getNames() -- load a list of peripherals into a table
  77. table.sort(machines) -- so it displays in non-random manner
  78.  
  79. n,count = marik.numOfMachines()
  80. print("Total peripherals detected: " .. count)
  81. print("Power storage devices: " .. n)
  82. print("Checking peripheral connections...")
  83.  
  84. -- Monitors
  85. local mon = peripheral.wrap(left)
  86. local mon2 = peripheral.wrap(right)
  87. mon.clear()
  88. mon2.clear()
  89. mon.setTextScale(textSize)
  90. mon2.setTextScale(textSize)
  91.  
  92. -- MONITOR 1 x,y Positions
  93. local machinesInfoCol = 6 -- machines info HEADING
  94. local GPS_x = 25 -- right side GPS info
  95. local GPS_y = 58
  96.  
  97. -- MONITOR 2 x,y Positions
  98. local tankPosStart = 1 -- to replace the rest of these
  99.  
  100. -- MONITOR 1 - Write lines that won't be cleared
  101. marik.cString(offsetPos, 1, hc, left, "-- Main Power --")
  102. marik.cString(offsetPos, machinesInfoCol, hc, left, "-- Machines Info --")
  103.  
  104. -- MONITOR 2 - Write lines that won't be cleared
  105. marik.cString(offsetPos, 1, hc, right, "-- RailCraft Tank Information --")
  106.  
  107. function dispAE()
  108.  
  109.     -- AE TERMINAL (not working yet)
  110.     mon2.setTextColor(tc)
  111.     mon2.setCursorPos(offsetPos,aeCraftCol)
  112.    
  113.     beingCrafted = aeController.getJobList()
  114.     if beingCrafted.name ~= nil then
  115.         timer[1] = os.clock()
  116.         mon2.clearLine()
  117.         mon2.write("Currently Crafting: " .. beingCrafted.name)
  118.     elseif beingCrafted.name == nil then
  119.             mon2.clearLine()
  120.             mon2.write("Currently Crafting: Nothing")
  121.     else
  122.             mon2.clearLine()
  123.             mon2.write("Currently Crafting: Unknown")
  124.     end
  125. end
  126.  
  127. function pFormat(pName)
  128. -- Renames peripherals for formatting purposes
  129.  
  130.     if string.find(pName, "compressor") then
  131.         pName = name_comp
  132.     elseif string.find(pName, "electric_furnace") then
  133.         pName = name_furnace
  134.     elseif string.find(pName, "extractor") then
  135.         pName = name_ext
  136.     elseif string.find(pName, "macerator") then
  137.         pName = name_mace
  138.     elseif string.find(pName, "orewashing") then
  139.         pName = name_washer
  140.     elseif string.find(pName, "thermalcentrifuge") then
  141.         pName = name_centrifuge
  142.     elseif string.find(pName, "canning") then
  143.         pName = name_canning
  144.     elseif string.find(pName, "recycler") then
  145.         pName = name_recycler
  146.     elseif string.find(pName, "former") then
  147.         pName = name_former
  148.     elseif string.find(pName, "mfsu") then
  149.         pName = name_mfsu
  150.     end
  151. return pName
  152. end
  153.  
  154. function dispTanks()
  155. mon.setCursorPos(offsetPos, 1)
  156. mon2.setCursorPos(offsetPos,1)
  157.  
  158.     for i=1, #machines do
  159.     -- RC Tanks --------------------------------------------
  160.         if string.find(machines[i], "rcirontankvalvetile")
  161.             or string.find(machines[i], "rcsteeltankvalvetile") then                       
  162.            
  163.             if peripheral.isPresent(machines[i]) then
  164.                 periph = peripheral.wrap(machines[i])
  165.            
  166.                 fluidRaw, fluidName, fluidAmount, fluidCapacity, fluidID = marik.getTank(periph)                           
  167.            
  168.                 if fluidName == nil then
  169.                 -- does not display empty tanks
  170.                 elseif fluidName ~= nil then
  171.                     mon2.setTextColor(tc)
  172.                     x,y = mon2.getCursorPos()
  173.                     mon2.setCursorPos(offsetPos, (y+1))
  174.                     mon2.clearLine()
  175.             -- marik.cString(offsetPos,(y+1), tc, right, " ")
  176.             mon2.write("Tank (" .. marik.comma(fluidName) .. ") : " .. marik.comma(fluidAmount) .. " / " .. marik.comma(fluidCapacity) .. " mb (" .. marik.getBuckets(fluidAmount) .. " buckets)")
  177.         end
  178.         end
  179.     end
  180.     end
  181. end
  182.  
  183. function dispPower()
  184.  
  185.     for i=1, #machines do
  186.   -- IC2 Power -------------------------------------------
  187.     for s=1, #supported_Power do
  188.         if string.find(machines[i], supported_Power[s]) then
  189.  
  190.             periph = peripheral.wrap(machines[i])              
  191.             local storedEU = periph.getEUStored()
  192.             local capacity = periph.getEUCapacity()
  193.  
  194.                 -- modify these later for multiple storage peripherals
  195.                 local totalStorage = storedEU
  196.                 local totalCapacity = capacity
  197.  
  198.                 marik.appendString(left, tc, "Total EU       " .. separator, true, offsetPos, 2)
  199.                 marik.appendString(left, color_reading, (marik.comma(totalStorage)), false, pwrX_Reading, 2)
  200.                
  201.                 marik.appendString(left, tc, "Total Capacity " .. separator, true, offsetPos, 3)
  202.                 marik.appendString(left, color_reading, (marik.comma(totalCapacity)), false, pwrX_Reading, 3)
  203.  
  204.                 marik.appendString(left, tc, pFormat(machines[i]) .. " Storage   " .. separator, true, offsetPos, 4)
  205.                 marik.appendString(left, color_reading, (marik.comma(storedEU)), false, pwrX_Reading, 4)
  206.  
  207.             end
  208.         end
  209.     end
  210. end
  211.  
  212.  
  213. function dispIC2()
  214.  
  215. machineDispStart = machineDisplayXPos -- screen start positon
  216.    
  217.     for i=1, #machines do
  218.     -- IC2 Machines -----------------------------------------
  219.         local m
  220.         for m=1, #supported_Machines do
  221.             -- check if the machine is a supported machine
  222.             if string.find(machines[i], supported_Machines[m]) then
  223.            
  224.                 -- check if the peripheral is connected
  225.                 -- if peripheral.isPresent(machines[i]) then
  226.                     periph = peripheral.wrap(machines[i])
  227.  
  228.                         -- determine what slot to use for the machines' input                              
  229.                         if string.find(machines[i], "thermalcentrifuge") then itemStackUsed = periph.getStackInSlot(thermCentrItemUsed)
  230.                         elseif string.find(machines[i], "orewashing") then itemStackUsed = periph.getStackInSlot(oreWashItemUsed)
  231.                         else itemStackUsed = periph.getStackInSlot(ic2ItemUsed)
  232.                         end
  233.                        
  234.                         machineDispStart = machineDispStart + 1 -- move this down?
  235.  
  236.                         -- if there's something in the input slot
  237.                         if itemStackUsed ~= nil then
  238.                             itemName = marik.itemRename(itemStackUsed.name)
  239.                             timer[2] = os.clock()
  240.                        
  241.                             -- display machine, active message and itemName
  242.                             marik.appendString(left, color_ores, itemName, true, orePos, machineDispStart) -- append the itemName
  243.                             str = (pFormat(peripheral.getType(machines[i])))
  244.                             marik.appendString(left, tc, str, false, offsetPos, machineDispStart) -- append the [      ] that contains the itemName
  245.                             marik.appendString(left, color_active, activeMsg, false, 11, machineDispStart) -- append the activeMsg                         
  246.  
  247.                         -- if there is nothing in the input slot
  248.                         elseif itemStackUsed == nil then       
  249.                             if os.clock() - timer[2] > waitTime[1] then -- clear the message only if it has been waitTime[1] seconds
  250.                                
  251.                                 --display machine and inactive message
  252.                                 marik.appendString(left, color_inactive, inactiveMsg, true, mStatusPos, machineDispStart) -- append INACTIVE
  253.                                 str = (pFormat(peripheral.getType(machines[i])))
  254.                                 marik.appendString(left, tc, str, false, offsetPos, machineDispStart) -- append the [      ] that contains the itemName
  255.                                
  256.                             end
  257.            
  258.                         else
  259.                             -- marik.appendString(left, color_active, "***TEST CASE***", false, offsetPos, machineDispStart)
  260.                     end
  261.                 -- end
  262.             end
  263.         end
  264.     end
  265. end
  266.  
  267.  
  268. -- Loop Start
  269. while true do
  270.  
  271. mon.setTextColor(tc)
  272. if marik.GPSinfo() then
  273.     mon.setCursorPos(GPS_y, GPS_x)
  274.     mon.write("GPS: Online")
  275. else
  276.     mon.setCursorPos(GPS_y, GPS_x)
  277.     mon.write("GPS: Offline")
  278. end
  279.  
  280. dispTanks()
  281. dispPower()
  282. dispIC2()
  283.  
  284. sleep(sleepAmt)
  285.  
  286. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement