Guest User

powermgr.lua

a guest
Apr 14th, 2017
60
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. gpu = component.proxy(component.list("gpu")());
  2. modem = component.proxy(component.list("modem")());
  3. mfe = component.proxy(component.list("mfsu")());
  4. red = component.proxy(component.list("redstone")());
  5. chest = component.proxy(component.list("iron")());
  6. boiler = component.proxy(component.list("boiler_firebox")());
  7. turbine = component.proxy(component.list("steam_turbine")());
  8. cenergy = 0;
  9. fenergy = 0;
  10. level = 0;
  11. bmode = "AUTO";
  12. bmin = 20;
  13. bmax = 80;
  14. bstate = 0;
  15. pstate = 1;
  16. msg = {};
  17. preen = 0;
  18. coalres = 0;
  19. flCoal = 0;
  20. flEnergy = 0;
  21. flTurbine = 0;
  22.  
  23. modem.open(451);
  24.  
  25. while true do
  26.   gpu.setResolution(25, 8);
  27.  
  28.   cenergy = mfe.getEUStored();
  29.   fenergy = mfe.getEUCapacity();
  30.   level = cenergy/fenergy*100;
  31.   if level == nil then level = 0; end
  32.   gpu.fill(1, 1, 25, 8, " ");
  33.   gpu.set(1, 1, "STORED: "..tostring(cenergy));
  34.   gpu.set(1, 2, "TOTAL:  "..tostring(fenergy));
  35.   gpu.set(9, 3, tostring(math.floor(level)).."%");
  36.   gpu.set(2, 4, "|");
  37.   gpu.set(23, 4, "|");
  38.   gpu.fill(3, 4, level/5, 1, "*");
  39.   gpu.set(1, 5, "eU/s:");
  40.   gpu.set(9, 5, tostring(cenergy-preen));
  41.   preen = cenergy;
  42.  
  43.   gpu.set(1, 6, "BOILER MODE:");
  44.   gpu.set(15, 6, bmode);
  45.  
  46.   if pstate == 1 then
  47.     red.setOutput(4, 15);
  48.     pstate=2;
  49.   elseif pstate == -1 then
  50.     red.setOutput(4, 0);
  51.     pstate = -2;
  52.   end
  53.  
  54.   if bmode == "AUTO" then
  55.     if bstate == 0 and level < bmin then
  56.       red.setOutput(5, 0);
  57.       bstate = 1;
  58.     elseif bstate == 1 and level > bmax then
  59.       red.setOutput(5, 15);
  60.       bstate = 0;
  61.     end
  62.   elseif bmode == "ON" and bstate == 0 then
  63.     red.setOutput(5, 0);
  64.     bstate = 1;
  65.   elseif bmode == "OFF" and bstate == 1 then
  66.     red.setOutput(5, 15);
  67.     bstate = 0;
  68.   else bmode = "AUTO";
  69.   end
  70.  
  71.   if bstate == 1 then
  72.     gpu.set(1, 7, "BOILER: HEATING UP");
  73.   else
  74.     gpu.set(1, 7, "BOILER: COOLING DOWN");
  75.   end
  76.  
  77.   if pstate == 2 then
  78.     gpu.set(1, 8, "MASTER POWER ON");
  79.   elseif pstate == 2 then
  80.     gpu.set(1, 8, "MASTER POWER OFF");
  81.   end
  82.  
  83.   coalres = 0;
  84.   for i=1,chest.getInventorySize() do
  85.     if chest.getStackInSlot(i) ~= nil then
  86.       coalres = coalres + chest.getStackInSlot(i).qty;
  87.     end
  88.   end
  89.  
  90.   if level <= 1 and flEnergy < 1 then
  91.     modem.broadcast(911, 'eng', 'EMERG', 'ENERGY CRITICAL');
  92.     flEnergy = 1;
  93.   elseif flEnergy > 0 and level > 2 then
  94.     flEnergy = 0;
  95.   end
  96.  
  97.   if coalres <= 256 and flCoal < 1 then
  98.     modem.broadcast(911, 'eng', 'Prior', 'COAL LOW');
  99.     flCoal = 1;
  100.   elseif flCoal > 0 and coalres > 320 then
  101.     flCoal = 0;
  102.   end
  103.  
  104.   if turbine.getTurbineRotorStatus() < 3 and flTurbine < 1 then
  105.     modem.broadcast(911, 'eng', 'Prior', 'TURBINE LOW');
  106.     flTurbine = 1;
  107.   elseif flTurbine > 0 and turbine.getTurbineRotorStatus() > 3 then
  108.     flTurbine = 0;
  109.   end
  110.  
  111.   msg = {computer.pullSignal(1)};
  112.   if msg[1] == "modem_message" then
  113.     computer.beep(600, 0.5);
  114.     if msg[6] == "engineering" then
  115.       if msg[7] == "boiler" then
  116.         bmode = msg[8];
  117.         if tonumber(msg[9]) ~= nil then
  118.           bmin = tonumber(msg[9]);
  119.         end
  120.         if tonumber(msg[10]) ~= nil then
  121.           bmax = tonumber(msg[10]);
  122.         end
  123.         modem.send(msg[3], 451, "engreply", "boilerACK", bmode, bmin, bmax);
  124.         modem.broadcast(999, 'eng', '_log_', "New boiler mode: "..bmode);
  125.         computer.beep(800, 0.5);
  126.       elseif msg[7] == "power" then
  127.         pstate = tonumber(msg[8]);
  128.         modem.send(msg[3], 451, "engreply", "powerACK", pstate);
  129.         modem.broadcast(999, 'eng', 'log', "Power changed to: "..tostring(pstate));
  130.         computer.beep(800, 0.5);
  131.       elseif msg[7] == "rep1" then
  132.         modem.send(msg[3], 451, "engreply_rep1", cenergy, fenergy, pstate, coalres, turbine.getTurbineRotorStatus());
  133.         computer.beep(800, 0.5);
  134.       elseif msg[7] == "rep2" then
  135.         modem.send(msg[3], 451 , "engreply_rep2", bstate, bmode, bmin, bmax);
  136.         computer.beep(800, 0.5);
  137.       elseif msg[7] == "rep3" then
  138.         modem.send(msg[3], 451, "engreply_rep3", boiler.isBurning(), boiler.getTemperature(), turbine.getTurbineOutput());
  139.         computer.beep(800, 0.5);
  140.       end
  141.     end
  142.   end
  143. end
RAW Paste Data