Guest User

ForceCoreControlV3

a guest
Oct 5th, 2013
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 17.67 KB | None | 0 0
  1. frequency = 2 --How many seconds before refreshing the program
  2. refreshCycle = 5 --How many cycles before measuring energy variation
  3. cycleCounter = 5 --Initial value for cycle counter
  4. pressedButton = 1 --Term button that is pressed initially
  5. termHeaderColor = colors.blue --Term headers Color
  6. headerColor = colors.lightGray --Header Color
  7. frameColor = colors.blue --Frame Color
  8. bottomCellsColor = colors.magenta --Color for top cells
  9. topCellsColor = colors.lightBlue --Color for bottom cells
  10. autoModeColor = colors.yellow --Color for Auto-Mode buttons
  11. manualModeColor = colors.orange --Color for Manual-mode buttons
  12. stateOnColor = colors.lime --Color for "On" state
  13. stateOffColor = colors.red --Color for "Off" state
  14. emptyBarColor = colors.gray --Color for empty bar spaces
  15. pressedButtonColor = colors.lightGray --Color for pressed button on term
  16. energyGainColor = colors.lime --Color for positive energy variation
  17. energyLossColor = colors.red --Color for negative energy variation
  18. energySameColor = colors.lightBlue --Color for no energy variation
  19. energyBarGaps = {21,51,71,91,101} --Energy % under wich the bar will have a specific color (Default => 0-20%, 21-50%, 51-70%, 71-90%,91-100%
  20. energyBarColors = {colors.red,colors.orange,colors.pink,colors.yellow,colors.lime} --Color for each energy quantity in the bar
  21. colorCode = {colors.white,colors.pink,colors.yellow,colors.magenta,colors.orange,colors.gray,colors.lime,colors.lightBlue} --Output color for each cell
  22. energyLevel = {0,0,0,0,0,0,0,0} --Default values for energy levels
  23. cellEnergy = {0,0,0,0,0,0,0,0} --Default values for energy levels
  24. curState = {0,0,0,0,0,0,0,0} --Default values for energy levels
  25. buttonStates = {0,0,0,0,0,0,0,0} --Default values for energy levels
  26. energyVariation = {0,0,0,0,0,0,0,0}
  27. legacyEnergy1 = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}
  28. legacyEnergy2 = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}
  29. legacyEnergy3 = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}
  30. legacyEnergy4 = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}
  31. legacyEnergy5 = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}
  32. legacyEnergy6 = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}
  33. legacyEnergy7 = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}
  34. legacyEnergy8 = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}
  35.  
  36. cell0Periph = peripheral.wrap("redstone_energy_cell_0")
  37. cell1Periph = peripheral.wrap("redstone_energy_cell_1")
  38. cell2Periph = peripheral.wrap("redstone_energy_cell_2")
  39. cell3Periph = peripheral.wrap("redstone_energy_cell_3")
  40. cell4Periph = peripheral.wrap("redstone_energy_cell_4")
  41. cell5Periph = peripheral.wrap("redstone_energy_cell_5")
  42. cell6Periph = peripheral.wrap("redstone_energy_cell_6")
  43. cell7Periph = peripheral.wrap("redstone_energy_cell_7")
  44.  
  45. function chooseBarColor(energy)
  46.  for i=1,5 do
  47.   if energy < energyBarGaps[i] then
  48.    return energyBarColors[i]
  49.   end
  50.  end
  51. end
  52.  
  53. function getProviders()
  54.   cell0 = cell0Periph.getPowerProvider()
  55.   cell1 = cell1Periph.getPowerProvider()
  56.   cell2 = cell2Periph.getPowerProvider()
  57.   cell3 = cell3Periph.getPowerProvider()
  58.   cell4 = cell4Periph.getPowerProvider()
  59.   cell5 = cell5Periph.getPowerProvider()
  60.   cell6 = cell6Periph.getPowerProvider()
  61.   cell7 = cell7Periph.getPowerProvider()
  62. end
  63.  
  64. function drawTermTitles() --Writes headers on terminal
  65.  term.setBackgroundColor(termHeaderColor)
  66.  term.setCursorPos(1,1)
  67.  term.write(" Energy Cell Charge"..string.rep(" ",32))
  68.  term.setCursorPos(1,10)
  69.  term.write(" Energy Variation")
  70.  refreshTime = frequency * refreshCycle
  71.  str = ("(For every "..refreshTime.." seconds) ")
  72.  strCount = string.len(str)
  73.  emptySpaces = 34-strCount
  74.  term.write(string.rep(" ",emptySpaces))
  75.  term.write(str)
  76.  term.setBackgroundColor(colors.black)
  77. end
  78.  
  79. function writeBarGraph(cellNum, energyValue, state)
  80.  
  81.    term.setTextColor(colorCode[cellNum])
  82.    term.write("   Cell "..cellNum..": [")
  83.  
  84.    w,h = term.getCursorPos()
  85.    term.setBackgroundColor(emptyBarColor)
  86.    term.write(string.rep(" ",25))
  87.    
  88.    term.setBackgroundColor(colors.black)
  89.    term.write("]  ")
  90.    if state == 0 then
  91.     term.setTextColor(stateOffColor)
  92.     term.write("Off")
  93.    else
  94.     term.setTextColor(stateOnColor)
  95.     term.write("On ")
  96.    end
  97.    term.setTextColor(colorCode[cellNum])
  98.    term.write("  "..energyLevel[cellNum].."%")
  99.    term.setTextColor(colors.white)
  100.    
  101.    term.setCursorPos(w,h)
  102.    color = chooseBarColor(energyValue)
  103.    term.setBackgroundColor(color)
  104.    term.write(string.rep(" ",energyValue/4))
  105.    term.setBackgroundColor(colors.black)
  106.  
  107. end
  108.  
  109. function writeStatus()
  110.  
  111.   for x=1,8 do
  112.    term.setCursorPos(1,x+1)
  113.    writeBarGraph(x, energyLevel[x], curState[x])
  114.   end
  115.  
  116. end
  117.  
  118. function writeEnergyVariation() --Write energy variation for each cell (on terminal)
  119.  for n=1,8 do
  120.   if pressedButton == n then
  121.    term.setBackgroundColor(pressedButtonColor)
  122.   end
  123.   term.setTextColor(colorCode[n])
  124.   if n > 4 then
  125.    y = 12
  126.   else
  127.    y = 11
  128.   end
  129.   xpos = n
  130.   if n > 4 then
  131.    xpos = xpos - 4
  132.   end
  133.   x = (xpos*10+3*xpos)-12
  134.   term.setCursorPos(x,y)
  135.   term.write("[C"..n..":")
  136.   value = energyVariation[n]
  137.   if value > 0 then --Decides color and signal
  138.    term.setTextColor(energyGainColor)
  139.    signal = "+"
  140.    writeValue = value
  141.   else
  142.    if value < 0 then
  143.     term.setTextColor(energyLossColor)
  144.     signal = "-"
  145.     writeValue = value * (-1)
  146.    else
  147.     term.setTextColor(energySameColor)
  148.     signal = " "
  149.     writeValue = value
  150.    end
  151.   end
  152.   if writeValue > 999 then --Converts to GJ if needed
  153.    writeValue = math.ceil(writeValue/1000)
  154.    size = "GJ"
  155.   else
  156.    size = "MJ"
  157.   end
  158.   valueString = tostring(signal..writeValue..size)
  159.   chars = string.len(valueString)
  160.   spaces = 7 - chars
  161.   for i=1,spaces do
  162.    term.write(" ") --Keeps format for smaller numbers
  163.   end
  164.   term.write(valueString)
  165.   term.setTextColor(colorCode[n])
  166.   term.write("]")
  167.   term.setBackgroundColor(colors.black)
  168.   term.setTextColor(colors.white)
  169.  end
  170. end
  171.  
  172. function drawChartGrid() --Writes chart grid
  173.  term.setBackgroundColor(colorCode[pressedButton]) --Use color of current power line
  174.  term.setTextColor(colors.black)
  175.  for o=1,7 do
  176.   term.setCursorPos(5,12+o)
  177.   term.write("#")
  178.  end
  179.  term.setCursorPos(1,18)
  180.  term.write(string.rep("#",51))
  181.  for p=1,3 do
  182.   term.setCursorPos(5,p*2+11)
  183.   term.write("_")
  184.  end
  185.  for q=1,10 do
  186.   term.setCursorPos(q*5+1,18)
  187.   term.write("|")
  188.  end
  189.  term.setBackgroundColor(colors.black)
  190. end
  191.  
  192. function writeChartTitles() --Write guide numbers on chart
  193.  term.setTextColor(colorCode[pressedButton])
  194.  for r=1,3 do
  195.   term.setCursorPos(1,r*2+11)
  196.   quant = 240*(3-r)
  197.   if quant < 100 then
  198.    if quant < 10 then
  199.     term.write ("  ")
  200.    else
  201.     term.write(" ")
  202.    end
  203.   end
  204.   term.write(quant.."G")
  205.  end
  206.  term.setCursorPos(51,19)
  207.  term.write("0")
  208.  for g=1,9 do
  209.   secs = tostring(g*50)
  210.   xpos = (51-5*g)
  211.   term.setCursorPos(xpos,19)
  212.   term.write(secs)
  213.  end
  214.  term.setCursorPos(1,19)
  215.  term.write("SxJ")
  216.  term.setTextColor(colors.white)
  217. end
  218.  
  219. function drawChartData() --Draws data on chart
  220.  if pressedButton == 1 then
  221.   legacyEnergy = legacyEnergy1
  222.  else
  223.   if pressedButton == 2 then
  224.    legacyEnergy = legacyEnergy2
  225.   else
  226.    if pressedButton == 3 then
  227.     legacyEnergy = legacyEnergy3
  228.    else
  229.     if pressedButton == 4 then
  230.      legacyEnergy = legacyEnergy4
  231.     else
  232.      if pressedButton == 5 then
  233.       legacyEnergy = legacyEnergy5
  234.      else
  235.       if pressedButton == 6 then
  236.        legacyEnergy = legacyEnergy6
  237.       else
  238.        if pressedButton == 7 then
  239.         legacyEnergy = legacyEnergy7
  240.        else
  241.         legacyEnergy = legacyEnergy8
  242.        end
  243.       end
  244.      end
  245.     end
  246.    end
  247.   end
  248.  end
  249.  for a=1,46 do
  250.   xpos = 52-a
  251.   val = legacyEnergy[a]
  252.   if val > 0 then
  253.    posVal = math.ceil(val/120000)
  254.   else
  255.    posVal = 1
  256.   end
  257.   ypos = 18-posVal
  258.   if legacyEnergy[a] > legacyEnergy[a+1] then
  259.    term.setBackgroundColor(energyGainColor)
  260.   else
  261.    if legacyEnergy[a] < legacyEnergy[a+1] then
  262.     term.setBackgroundColor(energyLossColor)
  263.    else
  264.     term.setBackgroundColor(energySameColor)
  265.    end
  266.   end
  267.   term.setCursorPos(xpos,ypos)
  268.   term.write(" ")
  269.  end
  270.  term.setBackgroundColor(colors.black)
  271. end
  272.  
  273. function drawChart() --Merges function related to legacy energy chart
  274.  drawChartGrid()
  275.  writeChartTitles()
  276.  drawChartData()
  277. end
  278.  
  279. function drawTerminalScreen() --Merges functions relatet to the terminal screen
  280.  term.clear()
  281.  drawTermTitles()
  282.  writeStatus()
  283.  writeEnergyVariation()
  284.  drawChart()
  285. end
  286.  
  287. function setOutput()
  288.   curColors = 0
  289.  
  290.   for v=1,8 do
  291.    if buttonStates[v] == 0 then
  292.     if energyLevel[v] < 50 then
  293.       curState[v] = 1
  294.     else
  295.      if energyLevel[v] > 90 then
  296.       curState[v] = 0
  297.      end
  298.     end
  299.    end
  300.   end
  301.  
  302.   curColors = curState[1] * colors.white + curState[2] * colors.pink + curState[3] * colors.yellow + curState[4] * colors.magenta + curState[5] * colors.orange + curState[6] * colors.gray + curState[7] * colors.lime + curState[8] * colors.lightBlue
  303.   rs.setBundledOutput("right", curColors)
  304.  
  305. end
  306.  
  307. monitor = peripheral.wrap("monitor_0")
  308.  
  309. function getEnergy() --Gets % of energy on each cell
  310.  energyLevel[1] = math.floor((cell0.energyStored/cell0.maxEnergyStored)*100)
  311.  energyLevel[2] = math.floor((cell1.energyStored/cell1.maxEnergyStored)*100)
  312.  energyLevel[3] = math.floor((cell2.energyStored/cell2.maxEnergyStored)*100)
  313.  energyLevel[4] = math.floor((cell3.energyStored/cell3.maxEnergyStored)*100)
  314.  energyLevel[5] = math.floor((cell4.energyStored/cell4.maxEnergyStored)*100)
  315.  energyLevel[6] = math.floor((cell5.energyStored/cell5.maxEnergyStored)*100)
  316.  energyLevel[7] = math.floor((cell6.energyStored/cell6.maxEnergyStored)*100)
  317.  energyLevel[8] = math.floor((cell7.energyStored/cell7.maxEnergyStored)*100)
  318. end
  319.  
  320. function getCellEnergy() --Gets amount of energy stored in each cell
  321.  cellEnergy[1] = cell0.energyStored
  322.  cellEnergy[2] = cell1.energyStored
  323.  cellEnergy[3] = cell2.energyStored
  324.  cellEnergy[4] = cell3.energyStored
  325.  cellEnergy[5] = cell4.energyStored
  326.  cellEnergy[6] = cell5.energyStored
  327.  cellEnergy[7] = cell6.energyStored
  328.  cellEnergy[8] = cell7.energyStored
  329. end
  330.  
  331. function refreshLegacyEnergy() --Updates energy history
  332.  table.insert(legacyEnergy1,1,cellEnergy[1])
  333.  table.remove(legacyEnergy1,48)
  334.  table.insert(legacyEnergy2,1,cellEnergy[2])
  335.  table.remove(legacyEnergy2,48)
  336.  table.insert(legacyEnergy3,1,cellEnergy[3])
  337.  table.remove(legacyEnergy3,48)
  338.  table.insert(legacyEnergy4,1,cellEnergy[4])
  339.  table.remove(legacyEnergy4,48)
  340.  table.insert(legacyEnergy5,1,cellEnergy[5])
  341.  table.remove(legacyEnergy5,48)
  342.  table.insert(legacyEnergy6,1,cellEnergy[6])
  343.  table.remove(legacyEnergy6,48)
  344.  table.insert(legacyEnergy7,1,cellEnergy[7])
  345.  table.remove(legacyEnergy7,48)
  346.  table.insert(legacyEnergy8,1,cellEnergy[8])
  347.  table.remove(legacyEnergy8,48)
  348. end
  349.  
  350. function getEnergyVariation() --Calculates energy variation
  351.  energyVariation[1] = legacyEnergy1[1] - legacyEnergy1[2]
  352.  energyVariation[2] = legacyEnergy2[1] - legacyEnergy2[2]
  353.  energyVariation[3] = legacyEnergy3[1] - legacyEnergy3[2]
  354.  energyVariation[4] = legacyEnergy4[1] - legacyEnergy4[2]
  355.  energyVariation[5] = legacyEnergy5[1] - legacyEnergy5[2]
  356.  energyVariation[6] = legacyEnergy6[1] - legacyEnergy6[2]
  357.  energyVariation[7] = legacyEnergy7[1] - legacyEnergy7[2]
  358.  energyVariation[8] = legacyEnergy8[1] - legacyEnergy8[2]
  359. end
  360.  
  361. function calculateEnergy() --Merges functions related with energy calculation
  362.  getEnergy()
  363.  if cycleCounter == refreshCycle then --Refresh legacy if enough cycles have passed
  364.   getCellEnergy()
  365.   refreshLegacyEnergy()
  366.   getEnergyVariation()
  367.  end
  368. end
  369.  
  370. function drawGrid() --Draws Grid
  371.  monitor.setBackgroundColor(headerColor)
  372.  monitor.setTextColor(frameColor)
  373.  monitor.setCursorPos(1,1)
  374.  monitor.write(string.rep("#",19).."Energy Charge"..string.rep("#",18)) --Draws Top Row
  375.  monitor.setBackgroundColor(colors.black)
  376.  for i=1,18 do --Draw 2-18th rows
  377.   monitor.setCursorPos(1,i+1)
  378.   monitor.write("#"..string.rep(" ",48).."#")
  379.  end
  380.  monitor.setCursorPos(1,19)
  381.  monitor.write(string.rep("#",50)) --Draw 19th row
  382.  monitor.setTextColor(colors.white)
  383. end
  384.  
  385. function drawColorGuide() --Draw the guide for color-codes
  386.  monitor.setCursorPos(4,19)
  387.  monitor.setTextColor(bottomCellsColor)
  388.  monitor.write("#")
  389.  monitor.setTextColor(colors.white)
  390.  monitor.write("=Bottom Cell ")
  391.  monitor.setTextColor(topCellsColor)
  392.  monitor.write("#")
  393.  monitor.setTextColor(colors.white)
  394.  monitor.write("=Top Cell")
  395.  monitor.setCursorPos(32,19)
  396.  monitor.setBackgroundColor(autoModeColor)
  397.  monitor.write(" ")
  398.  monitor.setBackgroundColor(colors.black)
  399.  monitor.write("=Auto  ")
  400.  monitor.setBackgroundColor(manualModeColor)
  401.  monitor.write(" ")
  402.  monitor.setBackgroundColor(colors.black)
  403.  monitor.write("=Manual")
  404. end
  405.  
  406. function drawButtons() --Draws override buttons and
  407.  for m=1,8 do
  408.   monitor.setCursorPos(36,m*2+1)
  409.   if buttonStates[m] == 0 then --Sees if button is Auto or Manual mode
  410.    monitor.setBackgroundColor(autoModeColor)
  411.   else
  412.    monitor.setBackgroundColor(manualModeColor)
  413.   end
  414.   if curState[m] == 0 then --Sees if on or off
  415.    monitor.setTextColor(stateOffColor)
  416.    monitor.write(" Off ")
  417.   else
  418.    monitor.setTextColor(stateOnColor)
  419.    monitor.write(" On  ")
  420.   end
  421.   monitor.setTextColor(colors.white) --Resets colors
  422.   monitor.setBackgroundColor(colors.black)
  423.  end
  424. end
  425.  
  426. function drawEnergyGrid() --Draws base grid for bars
  427.  monitor.setBackgroundColor(emptyBarColor)
  428.  for q=1,8 do
  429.   monitor.setCursorPos(9,q*2+1)
  430.   monitor.write(string.rep(" ",20))
  431.  end
  432.  monitor.setBackgroundColor(colors.black)
  433. end
  434.  
  435. function drawEnergyTitles() --Draws titles for energy graph
  436.  monitor.setTextColor(bottomCellsColor)
  437.  for o=1,4 do
  438.   monitor.setCursorPos(2,2*o+1)
  439.   monitor.write("Cell "..o)
  440.  end
  441.  monitor.setTextColor(topCellsColor)
  442.  for p=1,4 do
  443.   monitor.setCursorPos(2,2*p+9)
  444.   monitor.write("Cell "..p+4)
  445.  end
  446.  monitor.setTextColor(colors.white) --Resets text color
  447. end
  448.  
  449. function writeEnergy() --Writes energy % for each cell
  450.  for u=1,8 do
  451.   monitor.setTextColor(colorCode[u]) --Color each level for corresponding output
  452.   monitor.setCursorPos(31,2*u+1)
  453.   monitor.write(energyLevel[u].."%")
  454.  end
  455.  monitor.setTextColor(colors.white) --Resets text color
  456. end
  457.  
  458. function drawEnergyVariation()
  459.  for b=1,8 do
  460.   monitor.setCursorPos(42,b*2+1)
  461.   value = energyVariation[b]
  462.   if value > 0 then --Decides color and signal
  463.    monitor.setTextColor(energyGainColor)
  464.    signal = "+"
  465.    writeValue = value
  466.   else
  467.    if value < 0 then
  468.     monitor.setTextColor(energyLossColor)
  469.     signal = "-"
  470.     writeValue = value * (-1)
  471.    else
  472.     monitor.setTextColor(energySameColor)
  473.     signal = " "
  474.     writeValue = value
  475.    end
  476.   end
  477.   if writeValue > 999 then --Converts to GJ if needed
  478.    writeValue = math.ceil(writeValue/1000)
  479.    size = "GJ"
  480.   else
  481.    size = "MJ"
  482.   end
  483.   valueString = tostring(signal..writeValue..size)
  484.   chars = string.len(valueString)
  485.   spaces = 7 - chars
  486.   for i=1,spaces do
  487.    monitor.write(" ") --Keeps format for smaller numbers
  488.   end
  489.   monitor.write(valueString)
  490.  end
  491. end
  492.  
  493. function drawEnergyBar() --Draw energy bars
  494.  for y=1,8 do
  495.   monitor.setCursorPos(9,2*y+1)
  496.   h = energyLevel[y]
  497.   color = chooseBarColor(h)
  498.   monitor.setBackgroundColor(color)
  499.   g = h/5 --How many spaces need to be filled
  500.   monitor.write(string.rep(" ",g)) --Draw bar
  501.  end
  502.  monitor.setBackgroundColor(colors.black) --Resets background color
  503. end
  504.  
  505. function drawEnergyGraph() --Merge functions related to the energy graph
  506.  drawEnergyGrid()
  507.  drawEnergyTitles()
  508.  writeEnergy()
  509.  drawEnergyBar()
  510. end
  511.  
  512. function drawMonitor() --Merges monitor-related functions
  513.  monitor.clear()
  514.  drawGrid()
  515.  drawColorGuide()
  516.  drawButtons()
  517.  drawEnergyGraph()
  518.  drawEnergyVariation()
  519. end
  520.  
  521. function buttonPress(x,y) --Detects wich button was pressed
  522.  if x > 35 and x < 41 then
  523.   y = (y-1)/2
  524.   if y > 0 and y < 9 then
  525.    overrideButton(y)
  526.    os.queueEvent("timer") --Forces refresh
  527.   end
  528.  end
  529. end
  530.  
  531. function overrideButton(button) --Apply button press
  532.  f = button
  533.  if buttonStates[f] == 0 then
  534.   curState[f] = 1
  535.   buttonStates[f] = 1
  536.  else
  537.   if buttonStates[f] == 1 then
  538.    curState[f] = 0
  539.    buttonStates[f] = 2
  540.   else
  541.    buttonStates[f] = 0
  542.   end
  543.  end
  544. end
  545.  
  546. function termClick(x,y)
  547.  if y == 11 or y == 12 then
  548.   row = y-10
  549.   if x < 13 then
  550.    col = 1
  551.   else
  552.    if x > 13 and x < 26 then
  553.     col = 2
  554.    else
  555.     if x > 26 and x < 39 then
  556.      col = 3
  557.     else
  558.      if x > 39 then
  559.       col = 4
  560.      end
  561.     end
  562.    end
  563.   end
  564.   button = (row-1)*4+col
  565.   pressedButton = button
  566.   os.queueEvent("timer") --Forces refresh
  567.  end
  568. end
  569.  
  570. function countCycle()
  571.  
  572. end
  573.  
  574. while true do
  575.  
  576.  getProviders()
  577.  
  578.  calculateEnergy()
  579.  
  580.  drawTerminalScreen()
  581.  
  582.  drawMonitor()
  583.  
  584.  setOutput()
  585.  
  586.  term.setCursorPos(7,15) --Debug lines
  587.  term.write(cycleCounter)
  588.  term.setCursorPos(15,15)
  589.  term.write(refreshCycle)
  590.  term.setCursorPos(23,15)
  591.  term.write(frequency)
  592.  
  593.  os.startTimer(frequency-0.4)
  594.  repeat
  595.   event, p1, clickx, clicky = os.pullEvent()
  596.   if event == "monitor_touch" then --Detects monitor touch
  597.    buttonPress(clickx,clicky)
  598.   else
  599.    if event == "mouse_click" and p1 == 1 then --Detects term click
  600.     termClick(clickx,clicky)
  601.    end
  602.   end
  603.  until event == "timer" --Wait until refreshing
  604.  
  605.  if cycleCounter == refreshCycle then
  606.   cycleCounter = 0 --Resets counter if max cycle is reached
  607.  else
  608.   cycleCounter = cycleCounter + 1 --Otherwise increment it by 1
  609.  end
  610.  
  611. end
Advertisement
Add Comment
Please, Sign In to add comment