Advertisement
electronx3

DraconicControl-1.0.2

Mar 19th, 2021 (edited)
6,231
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 18.65 KB | None | 0 0
  1. --peripheral config
  2. local sideGateOut = "right"
  3. local sideReactor = "back"
  4.  
  5. --output multiplier: set by modpack (default = 1.0), change this to the value of draconic evolution config (!!!not tested yet!!!)
  6. local outputMultiplier = 1.0
  7.  
  8.  
  9. --Do not change anything below
  10.  
  11.  
  12. local version = "1.0.2" --by electronx3
  13.  
  14. --constants
  15. local val_1div3 = 1.0/3.0
  16.  
  17.  
  18. --config
  19.  
  20. --emergency shutdown parameters
  21. local maxOvershoot = 200.0      --reactor will shutdown when temperature gets hotter than defaultTemp+maxOvershoot
  22. local minFuel = 0.05
  23.  
  24. --default parameters
  25. local defaultTemp = 8000.0
  26. local defaultField = 0.01
  27.  
  28. local maxTempInc = 400.0        --max. temperature increase per computer tick
  29. local maxOutflow = 16000000.0
  30.  
  31. local chargeInflow = 20000000
  32. local shutDownField = 0.1       --field strength while shutdown
  33.  
  34. local safeMode = true           --when set to false, the automatic emergency shutdown function is disabled
  35.  
  36.  
  37. --peripherals
  38. local reactor
  39. local gateIn
  40. local gateOut
  41. local mon
  42.  
  43. --info
  44. local info
  45.  
  46. local currentEmergency = false
  47. local currentField
  48. local currentFuel
  49.  
  50. local stableTicks = 0
  51. local screenPage = 0
  52. local openConfirmDialog = false
  53.  
  54. local manualStart = false
  55. local manualCharge = false
  56. local manualStop = false
  57.  
  58.  
  59. --the program
  60.  
  61. function updateInfo()
  62.     info = reactor.getReactorInfo()
  63.    
  64.     if info == nil or info == null then
  65.       error("Reactor has an invalid setup!")
  66.     end
  67.    
  68.     currentField = info.fieldStrength / info.maxFieldStrength
  69.     currentFuel = 1.0 - (info.fuelConversion / info.maxFuelConversion)
  70. end
  71.  
  72. function isEmergency()
  73.     currentEmergency = safeMode and not (info.temperature < 2000.0) and (info.status == "running" or info.status == "online" or info.status == "stopping") and (info.temperature > defaultTemp + maxOvershoot or currentField < 0.004 or currentFuel < minFuel)
  74.     return currentEmergency
  75. end
  76.  
  77. function calcInflow(targetStrength, fieldDrainRate)
  78.     return fieldDrainRate / (1.0 - targetStrength)
  79. end
  80.  
  81. --creators of the setupPeripherals function: https://github.com/acidjazz/drmon/blob/master/drmon.lua
  82. function setupPeripherals()
  83.     print("Setup peripherals...")
  84.     reactor = peripheral.wrap(sideReactor)
  85.     gateIn = periphSearch("flux_gate")
  86.     gateOut = peripheral.wrap(sideGateOut)
  87.    
  88.     if reactor == null then
  89.         error("No valid reactor was found!")
  90.     end
  91.     if gateIn == null then
  92.         error("No valid input fluxgate was found!")
  93.     end  
  94.     if gateOut == null then
  95.         error("No valid output fluxgate was found!")
  96.     end
  97.    
  98.     gateIn.setOverrideEnabled(true)
  99.     gateIn.setFlowOverride(0)
  100.     gateOut.setOverrideEnabled(true)
  101.     gateOut.setFlowOverride(0)
  102.    
  103.     local tmpMon = periphSearch("monitor")
  104.     if tmpMon == null then
  105.         mon = null
  106.         print("WARN: No valid monitor was found!")
  107.  
  108.     else
  109.         monX, monY = tmpMon.getSize()
  110.         mon = {}
  111.         mon.monitor, mon.x, mon.y = tmpMon, monX, monY
  112.     end
  113.    
  114.     print("Done!")
  115. end
  116.  
  117. function periphSearch(type)
  118.     local names = peripheral.getNames()
  119.     local i, name
  120.     for i, name in pairs(names) do
  121.         if peripheral.getType(name) == type then
  122.             return peripheral.wrap(name)
  123.         end
  124.     end
  125.     return null
  126. end
  127.  
  128. function clickListener()
  129.     if mon == null then
  130.         return
  131.     end
  132.    
  133.     while true do
  134.         event, side, xPos, yPos = os.pullEvent("monitor_touch")
  135.        
  136.         local cFlow = 0 --remove local later
  137.        
  138.         if yPos == mon.y and xPos >= 1 and xPos <= 4 then
  139.             openConfirmDialog = false
  140.             screenPage = (screenPage + 1) % 2
  141.         elseif screenPage == 1 then        
  142.             if yPos == 8 then
  143.                 local tmpTemp = defaultTemp
  144.            
  145.                 if xPos >= 2 and xPos <= 3 then
  146.                     tmpTemp = tmpTemp - 1.0
  147.                 elseif xPos >= 5 and xPos <= 6 then
  148.                     tmpTemp = tmpTemp - 10.0
  149.                 elseif xPos >= 9 and xPos <= 11 then
  150.                     tmpTemp = tmpTemp - 100.0
  151.                 elseif xPos >= 14 and xPos <= 16 then
  152.                     tmpTemp = 8000.0
  153.                 elseif xPos >= 19 and xPos <= 21 then
  154.                     tmpTemp = tmpTemp + 100.0
  155.                 elseif xPos >= 24 and xPos <= 25 then
  156.                     tmpTemp = tmpTemp + 10.0
  157.                 elseif xPos >= 27 and xPos <= 28 then
  158.                     tmpTemp = tmpTemp + 1.0
  159.                 end
  160.                
  161.                 if tmpTemp < 20.0 then
  162.                     tmpTemp = 20.0
  163.                 elseif tmpTemp > 20000.0 then
  164.                     tmpTemp = 20000.0
  165.                 end
  166.                
  167.                 defaultTemp = tmpTemp
  168.                 --print("new default temperature: " .. math.floor(defaultTemp) .. "°C")
  169.             elseif yPos == 12 then
  170.                 local tmpField = defaultField
  171.                
  172.                 if xPos >= 2 and xPos <= 3 then
  173.                     tmpField = tmpField - 0.001
  174.                 elseif xPos >= 5 and xPos <= 6 then
  175.                     tmpField = tmpField - 0.01
  176.                 elseif xPos >= 9 and xPos <= 11 then
  177.                     tmpField = tmpField - 0.1
  178.                 elseif xPos >= 14 and xPos <= 16 then
  179.                     tmpField = 0.01
  180.                 elseif xPos >= 19 and xPos <= 21 then
  181.                     tmpField = tmpField + 0.1
  182.                 elseif xPos >= 24 and xPos <= 25 then
  183.                     tmpField = tmpField + 0.01
  184.                 elseif xPos >= 27 and xPos <= 28 then
  185.                     tmpField = tmpField + 0.001
  186.                 end
  187.                
  188.                 if tmpField < 0.005 then
  189.                     tmpField = 0.005
  190.                 elseif tmpField > 0.6 then
  191.                     tmpField = 0.6
  192.                 end
  193.                
  194.                 defaultField = tmpField
  195.                 --print("new default field strength: " .. math.floor(defaultField*1000.0)/10.0 .. "%")
  196.             elseif yPos == 15 then             
  197.                 if openConfirmDialog then
  198.                     if xPos >= 25 and xPos <= 28 then
  199.                         openConfirmDialog = false
  200.                     elseif xPos >= 16 and xPos <= 22 then
  201.                         openConfirmDialog = false
  202.                         safeMode = false
  203.                         --print("WARN: Safe mode deactivated!")
  204.                     end
  205.                 elseif xPos >= 26 and xPos <= 28 then
  206.                     if safeMode then
  207.                         openConfirmDialog = true
  208.                     else
  209.                         safeMode = true
  210.                         --print("Safe mode activated!")
  211.                     end
  212.                 end
  213.             elseif yPos == 17 and info ~= null then
  214.                 if not currentEmergency then
  215.                     if (info.status == "running" or info.status == "online") and xPos >= 2 and xPos <= 5 then
  216.                         manualStop = true
  217.                     elseif (info.status == "cold" or info.status == "offline" or info.status == "cooling") and xPos >= 2 and xPos <= 7 then
  218.                         manualCharge = true
  219.                     elseif (info.status == "stopping" or info.status == "warming_up" or info.status == "charged") and xPos >= 2 and xPos <= 6 then
  220.                         manualStart = true
  221.                     elseif info.status == "warming_up" and xPos >= 9 and xPos <= 12 then
  222.                         manualStop = true
  223.                     end
  224.                 end
  225.                 if info.temperature < 2000.0 and xPos >= 26 and xPos <= 28 then
  226.                     print("Program stopped!")
  227.                     return
  228.                 end
  229.             end
  230.         end
  231.         saveConfig()
  232.     end
  233. end
  234.  
  235. --graphic stuff: inspired by https://github.com/acidjazz/drmon/blob/master/drmon.lua
  236. function gClear()
  237.   mon.monitor.setBackgroundColor(colors.black)
  238.   mon.monitor.clear()
  239.   mon.monitor.setCursorPos(1,1)
  240. end
  241. function gWrite(text, x, y, cl, clBg)
  242.     mon.monitor.setCursorPos(x, y)
  243.     mon.monitor.setTextColor(cl)
  244.     mon.monitor.setBackgroundColor(clBg)
  245.     mon.monitor.write(text)
  246. end
  247. function gWriteR(text, x, y, cl, clBg)
  248.     gWrite(text, mon.x - string.len(tostring(text)) - x, y, cl, clBg)
  249. end
  250. function gWriteLR(textL, textR, xL, xR, y, clL, clR, clBg)
  251.     gWrite(textL, xL, y, clL, clBg)
  252.     gWriteR(textR, xR, y, clR, clBg)
  253. end
  254. function gDrawLine(x, y, length, cl)
  255.     if length < 0 then
  256.         return
  257.     end
  258.     mon.monitor.setCursorPos(x, y)
  259.     mon.monitor.setBackgroundColor(cl)
  260.     mon.monitor.write(string.rep(" ", length))
  261. end
  262. function gDrawProgressBar(x, y, length, proportion, cl, clBg)
  263.     if proportion < 0.0 or proportion > 1.0 then
  264.         gDrawLine(x, y, length, cl)
  265.     else
  266.         gDrawLine(x, y, length, clBg)
  267.         gDrawLine(x, y, math.floor(proportion*length), cl)
  268.     end
  269. end
  270. function gDrawStandardProgressBar(y, proportion, cl)
  271.     gDrawProgressBar(2, y, mon.x-2, proportion, cl, colors.gray)
  272. end
  273.  
  274.  
  275. function update()
  276.     local newInflow = 0.0
  277.     local newOutflow = 0.0 
  278.    
  279.     while true do  
  280.         updateInfo()       
  281.         local isStable = false
  282.         local tmpShutDownField = math.max(shutDownField, defaultField)
  283.    
  284.         if peripheral.wrap(sideGateOut) == null then
  285.             reactor.stopReactor()
  286.             newInflow = calcInflow(tmpShutDownField, info.fieldDrainRate)
  287.             error("Output gate missing!")
  288.         end
  289.        
  290.         if manualStop then
  291.             manualStart = false
  292.             manualStop = false
  293.             manualCharge = false
  294.             reactor.stopReactor()
  295.         end
  296.        
  297.         if isEmergency() == true then
  298.             reactor.stopReactor()
  299.             newInflow = calcInflow(0.8, info.fieldDrainRate)
  300.             newOutflow = 0.0
  301.             manualStart = false
  302.             manualCharge = false
  303.         elseif info.status == "cold" or info.status == "offline" or info.status == "cooling" then
  304.             newInflow = 0.0
  305.             newOutflow = 0.0
  306.             if manualCharge then
  307.                 manualStart = false
  308.                 manualCharge = false
  309.                 reactor.chargeReactor()
  310.             end
  311.         elseif info.status == "charging" then
  312.             newInflow = chargeInflow
  313.             newOutflow = 0.0
  314.             manualStart = false
  315.             manualCharge = false
  316.         elseif info.status == "warming_up" or info.status == "charged" then
  317.             newInflow = chargeInflow
  318.             newOutflow = 0.0
  319.             if manualStart then
  320.                 manualStart = false
  321.                 manualCharge = false
  322.                 reactor.activateReactor()
  323.             end
  324.         elseif info.status == "running" or info.status == "online" then
  325.             manualStart = false
  326.             manualCharge = false
  327.             local temp = info.temperature
  328.            
  329.             if temp > defaultTemp - 6.0 and temp < defaultTemp + 5.0 then
  330.                 stableTicks = stableTicks + 1
  331.                 if stableTicks > 100 then
  332.                     isStable = true
  333.                 end
  334.             else
  335.                 stableTicks = 0
  336.             end
  337.        
  338.             if temp < defaultTemp then             
  339.                 local tempInc
  340.                 if temp < defaultTemp - 50.0 then
  341.                     tempInc = math.sqrt(defaultTemp - temp)
  342.                 elseif temp < defaultTemp - 0.5 then
  343.                     tempInc = math.sqrt(defaultTemp - temp)/2.0
  344.                 end
  345.            
  346.                 if tempInc == nil or tempInc < 0.0 then
  347.                     tempInc = 0
  348.                 elseif tempInc > maxTempInc then
  349.                     tempInc = maxTempInc
  350.                 end
  351.                
  352.                
  353.                 local t50 = temp/200.0
  354.                 local convLvl = (info.fuelConversion / info.maxFuelConversion)*1.3 - 0.3
  355.                
  356.                 local y = (t50^4)/(100.0-t50)*(1-convLvl) + 1000.0*(tempInc-convLvl) - 444.7
  357.                 local dSqrt = math.sqrt((50.0*y)^2 + (y/3.0)^3)
  358.                
  359.                 local x            
  360.                 local tmpValRoot = dSqrt - 50.0*y
  361.                 if tmpValRoot > 0.0 then
  362.                     x = math.pow(dSqrt + 50.0*y, val_1div3) - math.pow(tmpValRoot, val_1div3)
  363.                 else
  364.                     x = math.pow(dSqrt + 50.0*y, val_1div3) + math.pow(0.0-tmpValRoot, val_1div3)
  365.                 end
  366.                
  367.                 newOutflow = info.maxEnergySaturation*x/99.0 + info.energySaturation - info.maxEnergySaturation
  368.                 if newOutflow > maxOutflow then
  369.                     newOutflow = maxOutflow
  370.                 end
  371.             else
  372.                 newOutflow = 0.0
  373.             end
  374.        
  375.             if isStable == true then
  376.                 if currentField > defaultField + 0.05 then
  377.                     newInflow = 0.0
  378.                 elseif currentField > defaultField*1.2 then
  379.                     newInflow = calcInflow(defaultField*0.98, info.fieldDrainRate)
  380.                 elseif currentField > defaultField*0.97 then
  381.                     newInflow = calcInflow(defaultField, info.fieldDrainRate)
  382.                 else
  383.                     newInflow = calcInflow(defaultField*1.5, info.fieldDrainRate)
  384.                 end
  385.             else
  386.                 if currentField > tmpShutDownField then
  387.                     newInflow = calcInflow(tmpShutDownField, info.fieldDrainRate)
  388.                 else
  389.                     newInflow = calcInflow(tmpShutDownField*1.2, info.fieldDrainRate)
  390.                 end
  391.             end
  392.         elseif info.status == "stopping" then
  393.             if currentField > tmpShutDownField then
  394.                 newInflow = calcInflow(tmpShutDownField, info.fieldDrainRate)
  395.             else
  396.                 newInflow = calcInflow(tmpShutDownField*1.2, info.fieldDrainRate)
  397.             end
  398.             newOutflow = 0.0
  399.            
  400.             if manualStart then
  401.                 manualStart = false
  402.                 manualCharge = false
  403.                 reactor.activateReactor()
  404.             end
  405.         end
  406.        
  407.         if newInflow < 0.0 then
  408.             newInflow = 0.0
  409.         end
  410.         if newOutflow < 0.0 then
  411.             newOutflow = 0.0
  412.         end
  413.        
  414.         if newInflow > 0.0 then
  415.             newInflow = math.floor(newInflow)
  416.         else
  417.             newInflow = 0
  418.         end
  419.         local outflowMultiplied = 0
  420.         if newOutflow > 0.0 then
  421.             outflowMultiplied = math.floor(newOutflow*outputMultiplier)
  422.         else
  423.             newOutflow = 0.0
  424.         end
  425.         gateIn.setFlowOverride(newInflow)
  426.         gateOut.setFlowOverride(outflowMultiplied)
  427.        
  428.        
  429.         if mon ~= null then
  430.             gClear()
  431.            
  432.             if screenPage == 0 then
  433.                 local clTemp
  434.                 if info.temperature < defaultTemp*0.95 then
  435.                     clTemp = colors.green
  436.                 elseif info.temperature < defaultTemp + 1.0 then
  437.                     clTemp = colors.yellow
  438.                 elseif info.temperature < defaultTemp + maxOvershoot then
  439.                     clTemp = colors.orange
  440.                 else
  441.                     clTemp = colors.red
  442.                 end
  443.                
  444.                 gWriteLR("temperature:", math.floor(info.temperature*10.0)/10.0 .. "°C", 2, 0, 7, colors.white, clTemp, colors.black)
  445.                 gWriteLR("set: " .. math.floor(defaultTemp) .. "°C", "max: " .. math.floor(defaultTemp + maxOvershoot) .. "°C", 2, 0, 8, colors.white, colors.white, colors.black)
  446.                 gDrawStandardProgressBar(9, info.temperature/16000.0, clTemp)              
  447.                
  448.                 local clField
  449.                 if currentField > defaultField*1.05 then
  450.                     clField = colors.green
  451.                 elseif currentField > defaultField*0.95 then
  452.                     clField = colors.yellow
  453.                 else
  454.                     clField = colors.red
  455.                 end
  456.                
  457.                 gWriteLR("field strength:", math.floor(currentField*10000.0)/100.0 .. "%", 2, 0, 11, colors.white, clField, colors.black)
  458.                 gWriteLR("set: " .. math.floor(defaultField*1000)/10.0 .. "%", "min: 0.4%", 2, 0, 12, colors.white, colors.white, colors.black)
  459.                 gDrawStandardProgressBar(13, currentField, clField)
  460.                
  461.                 gWriteLR("status", info.status:upper(), 2, 0, 15, colors.white, colors.white, colors.black)
  462.                
  463.                 local clFuel
  464.                 if currentFuel > 0.15 then
  465.                     clFuel = colors.green
  466.                 elseif currentFuel > 0.05 then
  467.                     clFuel = colors.yellow
  468.                 elseif currentFuel > 0.01 then
  469.                     clFuel = colors.orange
  470.                 else
  471.                     clFuel = colors.red
  472.                 end
  473.                 gWriteLR("fuel:", math.floor(currentFuel*10000.0)/100.0 .. "%", 2, 0, 16, colors.white, clFuel, colors.black)
  474.             elseif screenPage == 1 then
  475.                 local clTemp
  476.                 if info.temperature < defaultTemp*0.95 then
  477.                     clTemp = colors.green
  478.                 elseif info.temperature < defaultTemp + 1.0 then
  479.                     clTemp = colors.yellow
  480.                 elseif info.temperature < defaultTemp + maxOvershoot then
  481.                     clTemp = colors.orange
  482.                 else
  483.                     clTemp = colors.red
  484.                 end
  485.                
  486.                 gWriteLR("temp: " .. math.floor(defaultTemp) .. " (" .. math.floor(defaultTemp + maxOvershoot) .. ")", math.floor(info.temperature*10.0)/10.0 .. "°C", 2, 0, 7, colors.white, clTemp, colors.black)
  487.                 gDrawStandardProgressBar(9, info.temperature/16000.0, clTemp)
  488.                
  489.                 gWrite("<", 2, 8, colors.white, colors.blue)
  490.                 gWrite("<<", 5, 8, colors.white, colors.blue)
  491.                 gWrite("<<<", 9, 8, colors.white, colors.blue)
  492.                 gWrite("res", 14, 8, colors.white, colors.blue)
  493.                 gWrite(">>>", 19, 8, colors.white, colors.blue)
  494.                 gWrite(">>", 24, 8, colors.white, colors.blue)
  495.                 gWrite(">", 28, 8, colors.white, colors.blue)              
  496.                
  497.                 local clField
  498.                 if currentField > defaultField*1.05 then
  499.                     clField = colors.green
  500.                 elseif currentField > defaultField*0.95 then
  501.                     clField = colors.yellow
  502.                 else
  503.                     clField = colors.red
  504.                 end
  505.                
  506.                 gWriteLR("field: " .. math.floor(defaultField*1000)/10.0 .. "% (0.4%)", math.floor(currentField*10000.0)/100.0 .. "%", 2, 0, 11, colors.white, clField, colors.black)
  507.                 gDrawStandardProgressBar(13, currentField, clField)
  508.                
  509.                 gWrite("<", 2, 12, colors.white, colors.blue)
  510.                 gWrite("<<", 5, 12, colors.white, colors.blue)
  511.                 gWrite("<<<", 9, 12, colors.white, colors.blue)
  512.                 gWrite("res", 14, 12, colors.white, colors.blue)
  513.                 gWrite(">>>", 19, 12, colors.white, colors.blue)
  514.                 gWrite(">>", 24, 12, colors.white, colors.blue)
  515.                 gWrite(">", 28, 12, colors.white, colors.blue)
  516.                
  517.                 if safeMode then
  518.                     if openConfirmDialog then
  519.                         gWrite("DISABLE?", 2, 15, colors.white, colors.black)
  520.                         gWrite("CONFIRM", 16, 15, colors.white, colors.green)
  521.                         gWrite("EXIT", 25, 15, colors.white, colors.red)
  522.                     else
  523.                         gWrite("safe mode:", 2, 15, colors.white, colors.black)
  524.                         gWrite("ON", 27, 15, colors.green, colors.black)
  525.                     end
  526.                 else
  527.                     gWrite("safe mode:", 2, 15, colors.white, colors.black)
  528.                     gWrite("OFF", 26, 15, colors.red, colors.black)
  529.                 end
  530.                
  531.                 if not currentEmergency then
  532.                     if info.status == "running" or info.status == "online" then
  533.                         gWrite("STOP", 2, 17, colors.white, colors.red)
  534.                     elseif info.status == "cold" or info.status == "offline" or info.status == "cooling" then
  535.                         gWrite("CHARGE", 2, 17, colors.white, colors.blue)
  536.                     elseif info.status == "stopping" or info.status == "charged" then
  537.                         gWrite("START", 2, 17, colors.white, colors.green)
  538.                     elseif info.status == "warming_up" then
  539.                         gWrite("START", 2, 17, colors.white, colors.green)
  540.                         gWrite("STOP", 9, 17, colors.white, colors.red)
  541.                     end
  542.                 end
  543.                
  544.                 if info.temperature < 2000.0 then
  545.                     gWrite("END", 26, 17, colors.white, colors.red)
  546.                 end
  547.             end
  548.            
  549.             gWriteLR("Draconic Control", "v" .. version, 2, 0, 1, colors.white, colors.white, colors.black)        
  550.            
  551.             gWriteLR("inflow:", newInflow .. " RF/t", 2, 0, 3, colors.white, colors.white, colors.black)
  552.             gWriteLR("outflow:", outflowMultiplied .. " RF/t", 2, 0, 4, colors.white, colors.white, colors.black)      
  553.             local gain = outflowMultiplied - newInflow
  554.             if gain > 0.0 then
  555.                 gWriteLR("-> gain:", gain .. " RF/t", 2, 0, 5, colors.white, colors.green, colors.black)
  556.             elseif gain < 0.0 then
  557.                 gWriteLR("-> gain:", gain .. " RF/t", 2, 0, 5, colors.white, colors.red, colors.black)
  558.             elseif gain == 0.0 then
  559.                 gWriteLR("-> gain:", "0 RF/t", 2, 0, 5, colors.white, colors.white, colors.black)
  560.             end
  561.            
  562.             gDrawLine(1, mon.y, 4, colors.gray)
  563.         end
  564.        
  565.         sleep(0.02)
  566.     end
  567. end
  568.  
  569. function setup()
  570.     term.clear()
  571.     print("Starting program...")   
  572.    
  573.     if fs.exists("config.txt") then
  574.         print("Loading config...")
  575.         loadConfig()
  576.         print("Done!")
  577.     else
  578.         print("Creating config...")
  579.         saveConfig()
  580.         print("Done!")
  581.     end
  582.  
  583.     if chargeInflow < 0 then
  584.         chargeInflow = 0
  585.     end
  586.    
  587.     stableTicks = 0
  588.    
  589.     setupPeripherals()
  590.     print("Started!")
  591. end
  592.  
  593. function saveConfig()
  594.     local config = fs.open("config.txt", "w")
  595.     config.writeLine(outputMultiplier*1000000.0)
  596.     config.writeLine(maxOvershoot)
  597.     config.writeLine(minFuel*100.0)
  598.     config.writeLine(defaultTemp)
  599.     config.writeLine(defaultField*1000.0)
  600.     config.writeLine(maxTempInc)
  601.     config.writeLine(maxOutflow)
  602.     config.writeLine(chargeInflow)
  603.     config.writeLine(shutDownField*1000.0)
  604.     config.close()
  605. end
  606. function loadConfig()
  607.     local config = fs.open("config.txt", "r")
  608.     outputMultiplier = tonumber(config.readLine())/1000000.0
  609.     maxOvershoot = tonumber(config.readLine())
  610.     minFuel = tonumber(config.readLine())/100.0
  611.     defaultTemp = tonumber(config.readLine())
  612.     defaultField = tonumber(config.readLine())/1000.0
  613.     maxTempInc = tonumber(config.readLine())
  614.     maxOutflow = tonumber(config.readLine())
  615.     chargeInflow = tonumber(config.readLine())
  616.     shutDownField = tonumber(config.readLine())/1000.0
  617.     config.close()
  618. end
  619.  
  620. function main()
  621.     setup()
  622.     if mon == null then
  623.         update()
  624.     else
  625.         parallel.waitForAny(update, clickListener)
  626.         gClear()
  627.         gWrite("Program stopped!", 1, 1, colors.white, colors.black)
  628.     end
  629. end
  630.  
  631. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement