Advertisement
TheProgrammer

Energy Checker with UHSLC

Aug 22nd, 2014
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 9.94 KB | None | 0 0
  1. local uk = "unknown"
  2. local p = peripheral
  3. local cname = "cofh_thermalexpansion_energycell_"
  4. local mname = "monitor_"
  5. local sm = "                                                                     "
  6. local k = 0 --X
  7. local l = 0 --X
  8. local m = 0 --X
  9. local n = 0 --X
  10. local o = 0 --X
  11. local q = 0
  12. local r = 0
  13. local s = 0
  14. local UHSLC = 0
  15. local num = 0
  16. local energy = 0
  17. local maxenergy = 0
  18. local monitors = {}
  19. local cells = {}
  20. local numbers = {}
  21. local timeINNum = 0
  22. local midnum = 0
  23. local cme
  24. local ce
  25. local mx = 0
  26. local inStartNum
  27. local inSumNum
  28. local inIDNum
  29. --local writeISNfile = fs.open("inSumNum","w")
  30. --local readISNfile = fs.open("inSumNum","r")
  31. --local writeIIDNfile = fs.open("inIDNum","w")
  32. --local readIIDNfile = fs.open("inIDNum","r")
  33. --local writeTINNfile = fs.open("timeINNum","w")
  34. --local readTINNfile = fs.open("timeINNum","r")
  35. --local writeCELLSfile = fs.open("CELLS","w")
  36. --local readCELLSfile = fs.open("CELLS","r")
  37. --local fileDataISN={}
  38. --local fileDataIIDN={}
  39. --local fileDataTINN={}
  40. --local fileDataCELLS={}
  41. --local ISNLine = readISNfile.readLine()
  42. --local IIDNLine = readIIDNfile.readLine()
  43. --local TINNLine = readIIDNfile.readLine()
  44. --local CELLSLine = readCELLSfile.readLine()
  45.  
  46. function initNumArray()
  47.  for i=0,500 do
  48.   numbers[i+1]=i
  49.  end
  50. end
  51.  
  52. function configMonitor()
  53.  term.clear()
  54.  term.setCursorPos(1,1)
  55.  local mid = 0
  56.  print("Bitte gebe die aktive(!) Rednet-ID des 3x2 (bxl) Monitors ein!")
  57.  print("Bitte beachte, dass das Programm abstürzt, wenn es keine Zahl erhält!")
  58.  mid = read()
  59.  mx = mid+midnum
  60.  mon = p.wrap(mname..tonumber(mx))
  61. end
  62.  
  63. function configCells()
  64.  while l==0 do
  65.   term.clear()
  66.   term.setCursorPos(1,1)
  67.   local cin = ""
  68.   local inStart = ""
  69.   --local inSum = ""
  70.   --local inID = ""
  71.   print("Willst du den automatischen oder den manuellen Modus für die Konfiguration deiner")
  72.   print("Energiezellen benutzen?")
  73.   print("Fuer den automatischen Modus, gebe 'auto' ein")
  74.   print("Fuer den manuellen Modus, gebe 'manu' ein")
  75.   print("Bitte beachte beim automatischen Modus, dass die IDs nacheinander folgen! (Wie z.B.: 1,2,3,4,5,...)")
  76.   print("(Der autom. Modus ist einfacher, der manuelle Modus ist auch nicht schlecht!)")
  77.   print("HINWEIS: Dieses Programm ist für die Energiezellen von Thermal Expansion 4 geschrieben worden!")
  78.   print("(Für PROs: Das bedeutet, dass für dieses Programm die Standardbezeichnung")
  79.   print("'cofh_thermalexpansion_energycell_' benutzt wird!)")
  80.   cin = read()
  81.   if cin=="auto" then
  82.    l=1
  83.    term.clear()
  84.    term.setCursorPos(1,1)
  85.    print("Du hast den automatischen Modus gewaehlt")
  86.    os.sleep(1)
  87.    print("Gebe nun die niedrigste ID deiner Energiezellen ein!")
  88.    inStart = read()
  89.    inStartNum = tonumber(inStart)
  90.    os.sleep(1)
  91.    print("Gebe nun die Gesamtanzahl deiner Energiezellen ein!")
  92.    local inSum = read()
  93.    local writeISNfile = fs.open("inSumNum","w")
  94.    writeISNfile.writeLine(inSum)
  95.    writeISNfile.close()
  96.    for i=0,500 do
  97.     if tonumber(inSum)==numbers[i+1] then
  98.      inSumNum=numbers[i+1]
  99.     end
  100.    end
  101.    --inSumNum = tonumber(inSum)
  102.    os.sleep(1)
  103.    print("Energiezellen werden nun konfiguriert...")
  104.    --local CELLSLine = writeCELLSfile.writeLine()
  105.    local writeCELLSfile = fs.open("CELLS","w")
  106.    for i=1,inSumNum do
  107.     x=inStartNum+inSumNum
  108.     cells[i] = peripheral.wrap(cname..x)
  109.     print("Energiezelle 'c"..(i).."' wurde erfolgreich konfiguriert!")
  110.    end
  111.    --ct = textutils.serialize(cells)
  112.    writeCELLSfile.write(cells)
  113.    --repeat
  114.    --table.insert(cells,CELLSLine)
  115.    --CELLSLine = writeCELLSfile.writeLine()
  116.    --until CELLSLine == nil
  117.    writeCELLSfile.close()
  118.    os.sleep(1)
  119.    print("Energiezellen sind nun konfiguriert!")
  120.   else
  121.    if cin=="manu" then
  122.     l=1
  123.     term.clear()
  124.     term.setCursorPos(1,1)
  125.     print("Du hast den manuellen Modus gewaehlt")
  126.     os.sleep(1)
  127.     print("Gebe nun die Gesamtanzahl deiner Energiezellen ein!")
  128.     local inSum = read()
  129.     local writeISNfile = fs.open("inSumNum","w")
  130.     writeISNfile.writeLine(inSum)
  131.     writeISNfile.close()
  132.     for i=0,500 do
  133.      if tonumber(inSum)==numbers[i+1] then
  134.       inSumNum=numbers[i+1]
  135.      end
  136.     end
  137.     --inSumNum = tonumber(inSum)
  138.     print("Gebe nun die(/alle) ID(s) deiner Energiezelle(n) nacheinander ein!")
  139.     for i=1,inSumNum do
  140.      local inID = read()
  141.      local writeIIDNfile = fs.open("inIDNum","w")
  142.      writeIIDNfile.writeLine(inID)
  143.      writeIIDNfile.close()
  144.      for i=0,500 do
  145.       if tonumber(inID)==numbers[i+1] then
  146.        inIDNum = numbers[i+1]    
  147.       end
  148.      end
  149.      --inIDNum = tonumber(inID)
  150.      cells[i] = p.wrap(cname..inIDNum)
  151.      print("Energiezelle 'c"..i.."' wurde erfolgreich konfiguriert!")
  152.     end
  153.    else
  154.     l=0
  155.     print(cin.." gibt es nicht!")
  156.    end
  157.   end
  158.  end
  159. end
  160.  
  161. function configComputer()
  162.  while m==0 do
  163.   term.clear()
  164.   term.setCursorPos(1,1)
  165.   local sideRN = ""
  166.   print("Dein Computer wird jetzt fuer Rednet konfiguriert!")
  167.   print("Gebe nun ein, an welcher Seite des PCs das (wireless) Modem für Rednet angeschlossen ist!")
  168.   print("Verfuegbare Seiten: oben('top'), unten('bottom'), rechts('right'), links('left'), hinten('back')")
  169.   print("Bitte beachte, dass das Programm abstuerzt, wenn an der angegebenen Seite kein Modem angeschlossen ist!")
  170.   sideRN = read()
  171.   if sideRN == "top" or sideRN == "bottom" or sideRN == "right" or sideRN == "left" or sideRN == "back" then
  172.    rednet.open(sideRN)
  173.    m=1
  174.   else
  175.    print(sideRN.." -Eingabe nicht akzeptabel!")
  176.    m=0
  177.   end  
  178.  end
  179.  while n==0 do
  180.   term.clear()
  181.   term.setCursorPos(1,1)
  182.   --local timeIN = ""
  183.   print("Gebe nun die Zeit in Sekunden ein, wie oft der Computer die Daten der Energiezelle(n) abfragen soll!")
  184.   print("0 ist nicht akzeptabel! Wenn du bspw. jede halbe Sekunde haben willst, dann gebe '0.5' ein!")
  185.   local timeIN = read()
  186.   local writeTINNfile = fs.open("timeINNum","w")
  187.   writeTINNfile.writeLine(timeIN)
  188.   writeTINNfile.close()
  189.   for i=0,500 do
  190.    if tonumber(timeIN)==numbers[i+1] then
  191.     timeINNum = numbers[i+1]    
  192.    end  
  193.   end
  194.   --timeINNum = tonumber(timeIN)
  195.   if tonumber(timeIN)==0 then
  196.    print("Bist du eigentlich behindert? Ich hab doch gesagt, dass '"..timeINNum.."' nicht akzeptiert wird -.-")
  197.    n=0
  198.   else
  199.    print("Updateintervall wurde erfolgreich auf '"..timeINNum.."'s gesetzt")
  200.    n=1
  201.   end
  202.  end
  203. end
  204.  
  205. function setupMonitor()
  206.  mon.setBackgroundColor(colors.lime)
  207.  mon.setTextColor(colors.blue)
  208.  for i=0,20 do
  209.    mon.setCursorPos(1,i+1)
  210.    mon.write(sm)
  211.  end
  212.   mon.setCursorPos(1,1)
  213.   mon.write("       ENERGIE-MONITOR"..sm)  
  214. end
  215.  
  216. function readEnergy()
  217.  local readISNfile = fs.open("inSumNum","r")
  218.  local readCELLSfile = fs.open("CELLS","r")
  219.  local fileDataISN={}
  220.  local fileDataCELLS={}
  221.  local ISNLine = readISNfile.readLine()
  222.  local CELLSLine = readCELLSfile.readLine()
  223.  repeat
  224.  table.insert(fileDataISN,ISNLine)
  225.  ISNLine = readISNfile.readLine()
  226.  until ISNLine == nil
  227.  --repeat
  228.  --table.insert(fileDataCELLS,CELLSLine)
  229.  --CELLSLine = readCELLSfile.readLine()
  230.  --until CELLSLine == nil
  231.  --cells = textutils.unserialize(fileDataCELLS.readAll())
  232.  --for i=1,(tonumber(fileDataISN[1])+0) do
  233.  for i=1,14 do
  234.   --local e = 0
  235.   --local me = 0
  236.   energy = cells[i].getEnergyStored("unknown")
  237.   maxenergy = cells[i].getMaxEnergyStored("unknown")
  238.   ce = ce+energy
  239.   cme = cme+maxenergy
  240.  end
  241.  readISNfile.close()
  242.  readCELLSfile.close()
  243. end
  244.  
  245. function writeEnergy()
  246.   local readTINNfile = fs.open("timeINNum","r")
  247.   local fileDataTINN={}
  248.   local TINNLine = readTINNfile.readLine()
  249.   repeat
  250.   table.insert(fileDataTINN,TINNLine)
  251.   TINNLine = readTINNfile.readLine()
  252.   until TINNLine == nil
  253.   readTINNfile.close()
  254.   mon.setCursorPos(1,2)
  255.   mon.clearLine()
  256.   mon.write("Energie: "..ce.."RF"..sm)
  257.   mon.setCursorPos(1,3)
  258.   local cen = ce
  259.   if cen>ceo then
  260.     mon.clearLine()
  261.     mon.write("Energiegewinn seit letztem"..sm)
  262.     mon.setCursorPos(1,4)
  263.     mon.clearLine()
  264.     mon.write("Check"..fileDataTINN[1].."s): +"..cen-ceo.."RF"..sm)
  265.   else
  266.     if cen==ceo then
  267.       mon.clearLine()
  268.       mon.write("Gleicher Energiestand"..sm)
  269.       mon.setCursorPos(1,4)
  270.       mon.clearLine()
  271.       mon.write(mm)
  272.     else
  273.       if c13n<c13o then
  274.         mon.clearLine()
  275.         mon.write("Energieverlust seit letztem"..sm)
  276.         mon.setCursorPos(1,4)
  277.         mon.clearLine()
  278.         mon.write("Check"..fileDataTINN[1].."s): -"..ceo-cen.."RF"..sm)
  279.       end
  280.     end
  281.   end  
  282.   local ep = cen/cme*100
  283.   mon.setCursorPos(1,6)
  284.   mon.clearLine()
  285.   mon.write(" (in '%'):"..sm)
  286.   mon.setCursorPos(1,7)
  287.   mon.clearLine()
  288.   mon.write(ep.."%"..sm)
  289. end
  290.  
  291. function calcEnergyA()
  292.   if o==0 then                             
  293.     ceo=0                              
  294.     o=1                                
  295.   end
  296. end
  297.  
  298. function calcEnergyB()
  299.   ceo = 0          
  300.   local readISNfile = fs.open("inSumNum","r")
  301.   local readCELLSfile = fs.open("CELLS","r")
  302.   local fileDataISN={}
  303.   local fileDataCELLS={}
  304.   local ISNLine = readISNfile.readLine()
  305.   local CELLSLine = readCELLSfile.readLine()
  306.   repeat
  307.   table.insert(fileDataISN,ISNLine)
  308.   ISNLine = readISNfile.readLine()
  309.   until ISNLine == nil
  310.   --repeat
  311.   --table.insert(fileDataCELLS,CELLSLine)
  312.   --CELLSLine = readCELLSfile.readLine()
  313.   --until CELLSLine == nil
  314.   --cells = textutils.unserialize(fileDataCELLS.readAll())
  315.   for i=1,(tonumber(fileDataISN[1])+0) do
  316.    local eo = 0
  317.    eo = cells[i].getEnergyStored("unknown")
  318.    ceo = ceo+eo
  319.   end  
  320.   readISNfile.close()
  321.   readCELLSfile.close()                        
  322. end
  323.  
  324. function rednetListener()
  325.  
  326. end
  327.  
  328. while true do
  329.  if k==0 then
  330.   initNumArray()
  331.   configComputer()
  332.   configMonitor()
  333.   configCells()
  334.   k=1
  335.  end
  336.  if m==0 then
  337.   setupMonitor()
  338.   m=1
  339.  end
  340.  calcEnergyA()
  341.  readEnergy()
  342.  writeEnergy()
  343.  calcEnergyB()
  344.  rednetListenet()
  345.  local readTINNfile = fs.open("timeINNum","r")
  346.  local fileDataTINN={}
  347.  local TINNLine = readTINNfile.readLine()
  348.  repeat
  349.  table.insert(fileDataTINN,TINNLine)
  350.  TINNLine = readTINNfile.readLine()
  351.  until TINNLine == nil
  352.  readTINNfile.close()
  353.  os.sleep((fileDataTINN[1]+0))
  354. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement