Guest User

startup

a guest
Apr 23rd, 2014
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.66 KB | None | 0 0
  1. --[[Settings]]--
  2. local redstoneOutputSide = "right"
  3. local rednetModemSide = "top"
  4. local energyCellLowName = "cofh_thermalexpansion_energycell_0"
  5. local energyCellHightName = "cofh_thermalexpansion_energycell_1"
  6. local lowStoragePercentage = 10
  7. local hightStoragePercentage = 90
  8.  
  9. --Don't edit from here on
  10.  
  11. --[[Variables]]--
  12. local debugSetting = true
  13. local modeFileLoc = "mode"
  14. local cellLow = peripheral.wrap(energyCellLowName)
  15. local cellHight = peripheral.wrap(energyCellHightName)
  16. rednet.open(rednetModemSide)
  17. local modeFile
  18.  
  19. --[[Functions]]--
  20. function printBoolean(boolean)
  21.     if term.isColor() then
  22.         if boolean then
  23.             term.setTextColor(colors.lime)
  24.         else
  25.             term.setTextColor(colors.red)
  26.         end
  27.     end
  28.     print(boolean)
  29.     if term.isColor() then
  30.         term.setTextColor(colors.white)
  31.     end
  32. end
  33.  
  34. function toBoolean(data)
  35.     return not not data
  36. end
  37.  
  38. function round(number)
  39.     return math.floor(tonumber(number)+0.5)
  40. end
  41.  
  42. --[[Code]]--
  43.  
  44. if fs.exists(modeFileLoc) then
  45.     modeFile = fs.open(modeFileLoc, "r")
  46.     mode = toBoolean(modeFile.readAll())
  47.     modeFile.close()
  48. else
  49.     modeFile = fs.open(modeFileLoc, "w")
  50.     modeFile.write("true")
  51.     modeFile.close()
  52.     shell.run("clear")
  53.     print([[Energy cell maintain program
  54. Disigned specifficly for Divey1130 ( https://www.youtube.com/channel/UCk0BV_fHvw791r-ReeRXhEA )
  55.  
  56. Yes I'm a big fan ;)
  57.  
  58. Press any key to continue...]])
  59.     os.pullEvent("key")
  60. end
  61.  
  62. while true do
  63.     local lowValue = cellLow.getEnergyStored("top")
  64.     local lowMax = cellLow.getMaxEnergyStored("top")
  65.     local lowPercentage = 100*lowValue/lowMax
  66.     local highValue = cellHight.getEnergyStored("top")
  67.     local highMax = cellHight.getMaxEnergyStored("top")
  68.     local highPercentage = 100*highValue/highMax
  69.     shell.run("clear")
  70.     print("Energy cell 1 (low) : "..lowValue.." / "..lowMax.." ("..round(lowPercentage).."%)")
  71.     print("Energy cell 2 (high): "..highValue.." / "..highMax.." ("..round(highPercentage).."%)")
  72.     print()
  73.     if lowPercentage < lowStoragePercentage then
  74.         mode = true
  75.     end
  76.     if highPercentage > hightStoragePercentage then
  77.         mode = false
  78.     end
  79.     modeFile = fs.open(modeFileLoc, "w")
  80.     modeFile.write(mode)
  81.     modeFile.close()
  82.     rs.setOutput(redstoneOutputSide, toBoolean(mode))
  83.     term.write("Redstone output: ")
  84.     printBoolean(rs.getOutput(redstoneOutputSide))
  85.     if debugSetting then
  86.         print("highPercentage: "..highPercentage)
  87.         print("highMax: "..highMax)
  88.         print("highValue : "..highValue)
  89.         print("hightStoragePercentage: "..hightStoragePercentage)
  90.         print("lowPercentage: "..lowPercentage)
  91.         print("lowMax: "..lowMax)
  92.         print("lowValue : "..lowValue)
  93.         print("lowStoragePercentage: "..lowStoragePercentage)
  94.         print("mode: "..tostring(mode))
  95.     end
  96. end
Advertisement
Add Comment
Please, Sign In to add comment