Muzze77

Switch Terminal Bundled Cable

Sep 6th, 2016
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.25 KB | None | 0 0
  1. shell.run("clear")
  2. mon = peripheral.wrap("back")
  3. mon.setBackgroundColor(colors.black)
  4. mon.clear()
  5.  
  6.  
  7. mon.setTextScale(2)
  8.  
  9.  
  10. function cbut(cx,cy,text, tcol, bcol)
  11. mon.setCursorPos(cx,cy)
  12. mon.setBackgroundColor(bcol)
  13. mon.setTextColor(tcol)
  14. mon.write(text)
  15. mon.setBackgroundColor(colors.black)
  16. mon.setTextColor(colors.white)
  17. end
  18.  
  19. function save()
  20. shell.run("delete config")
  21. qsFile = fs.open("config","w")
  22. qsFile.writeLine(textutils.serialize(status))
  23. qsFile.close()
  24.  
  25. end
  26.  
  27. if fs.exists("config") == false then
  28.     status = {}
  29.     status[1] = {["Name"] = "Extruder Turm I  " , ["Stats"] = "OFF",["Col"] = colors.cyan}
  30.     status[2] = {["Name"] = "Extruder Turm II " , ["Stats"] = "OFF",["Col"] = colors.black}
  31.     status[3] = {["Name"] = "Extruder Turm III" , ["Stats"] = "OFF",["Col"] = colors.blue}
  32.     status[4] = {["Name"] = "Extruder Turm IV " , ["Stats"] = "OFF",["Col"] = colors.green}
  33.     status[5] = {["Name"] = "Extruder Turm V  " , ["Stats"] = "OFF",["Col"] = colors.red}
  34.     status[6] = {["Name"] = "Extruder Turm VI " , ["Stats"] = "OFF",["Col"] = colors.lime}
  35.     save()
  36. else
  37.     rFile = fs.open("config","r")
  38.     status = rFile.readLine(1)
  39.     status = textutils.unserialize(status)
  40.     rFile.close()
  41. end
  42.    
  43.  
  44.  
  45.  
  46. function writeScreen()
  47. cbut(2,1,status[1].Name .. ": " .. status[1].Stats, colors.black, colors.cyan)
  48. cbut(2,2,status[2].Name .. ": " .. status[2].Stats, colors.black, colors.gray)
  49. cbut(2,3,status[3].Name .. ": " .. status[3].Stats, colors.black, colors.blue)
  50. cbut(2,4,status[4].Name .. ": " .. status[4].Stats, colors.black, colors.green)
  51. cbut(2,5,status[5].Name .. ": " .. status[5].Stats, colors.black, colors.red)
  52. cbut(2,6,status[6].Name .. ": " .. status[6].Stats, colors.black, colors.lime)
  53. end
  54.  
  55.  
  56. while true do
  57. writeScreen()
  58. evt, side, x, y = os.pullEvent("monitor_touch")
  59. if x > 20 and x < 25 then
  60.     if status[y].Stats == "OFF" then
  61.         status[y].Stats = "ON "
  62.         r = rs.getBundledOutput("front") + status[y].Col
  63.        
  64.         rs.setBundledOutput("front",r)
  65.         save()
  66.        
  67.     elseif status[y].Stats == "ON " then
  68.         status[y].Stats = "OFF"
  69.         r = rs.getBundledOutput("front") - status[y].Col
  70.         rs.setBundledOutput("front",r)
  71.         save()
  72.        
  73.     end
  74.  
  75. end
  76. end
Add Comment
Please, Sign In to add comment