Advertisement
Guest User

BaseControl

a guest
Sep 21st, 2013
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.13 KB | None | 0 0
  1. --Program for base control and HUD display.
  2. --Master program
  3.  
  4. --Functions
  5. function clearBoiler()
  6.     boilerInfo.setOpacity(0)
  7.     boilerTitle.setText(" ")
  8.     boilerTemp.setText(" ")
  9. end
  10.  
  11. function clearTurbine()
  12.     turbineInfo.setOpacity(0)
  13.     turbineTitle.setText(" ")
  14.     turbineMaintenence.setText(" ")
  15. end
  16.  
  17. function clearEngergyCell1()
  18.     energyCell1Info.setOpacity(0)
  19.     energyCell1Title.setText(" ")
  20.     energyCell1Text.setText(" ")
  21. end
  22.  
  23. function clearEngergyCell2()
  24.     energyCell2Info.setOpacity(0)
  25.     energyCell2Title.setText(" ")
  26.     energyCell2Text.setText(" ")
  27. end
  28.  
  29. --Peripherals
  30. glass = peripheral.wrap("left")
  31. modem = peripheral.wrap("top")
  32.  
  33. --Variable definitions
  34. --      y           : Starting yPos for user names.
  35. --      usertitle   : Title text in user box. Configurable.
  36. name1 = "Liquid Fueled Boiler  "
  37. name2 = "Steam Turbine   "
  38. name3 = "Energy Cell  "
  39.  
  40. --HUD Object Initialization (None display)
  41. glass.clear()
  42.  
  43. boilerInfo = glass.addBox( 12, 195, glass.getStringWidth( name1 )+7, 34, 0xfb0000, 0)
  44. boilerTitle = glass.addText( 15, 200, " ", 0 )
  45. boilerTemp = glass.addText( 20, 210, " ", 0 )
  46.  
  47. turbineInfo = glass.addBox( 12, 95, glass.getStringWidth( name2 )+7, 34, 0xfb0000, 0)
  48. turbineTitle = glass.addText( 15, 100, " ", 0 )
  49. turbineMaintenance = glass.addText( 15, 110, " ", 0 )
  50.  
  51. energyCell1Info = glass.addBox( 23, 15, glass.getStringWidth( name3 )+7, 24, 0x17c92c, 0)
  52. energyCell1Title = glass.addText( 25, 20, " ", 0 )
  53. energyCell1Text = glass.addText( 25, 30, " ", 0 )
  54.  
  55. energyCell2Info = glass.addBox( 23, 25, glass.getStringWidth( name3 )+7, 24, 0x17c92c, 0)
  56. energyCell2Title = glass.addText( 25, 30, " ", 0 )
  57. energyCell2Text = glass.addText( 25, 40, " ", 0 )
  58.  
  59. --Wireless Channel Documentation
  60. boilerChannel = 10
  61. turbineChannel = 20
  62. mfsu1Channel = 30
  63. mfsu2Channel = 31
  64. energyCell1Channel = 40
  65. energyCell2Channel = 41
  66.  
  67. --Program
  68.  
  69. while true do
  70.  
  71. local usertitle = glass.addText( 15, 42, "Connected Users:", 0xffffff )
  72. users = glass.getUsers()
  73. local y = 50
  74.  
  75. for k, v in pairs(users) do                         --Updating User list
  76.     glass.addText(25, y, tostring(v), 0xffffff )
  77.     y = y + 10
  78. end
  79.  
  80.  
  81. modem.open(boilerChannel)
  82. modem.transmit( boilerChannel, boilerChannel, "Go" ) --Tells slave it's listening
  83. event, modemSide, sendCh, rplyCh, message, dist = os.pullEvent("modem_message") --Waits for slave to respond.
  84. if message == "High" then
  85.     boilerInfo.setOpacity(0)
  86.     boilerTitle.setText(" ")
  87.     boilerTemp.setText(" ")
  88.     else
  89.     boilerInfo.setOpacity(.15)
  90.     boilerTitle.setText( name1 )
  91.     boilerTemp.setText( message )
  92. end
  93. modem.close(boilerChannel)
  94.  
  95. modem.open(turbineChannel)
  96. modem.transmit( turbineChannel, turbineChannel, "Go" ) --Tells slave it's listening
  97. event, modemSide, sendCh, rplyCh, message, dist = os.pullEvent("modem_message") --Waits for slave to respond.
  98. if message == "TurbineBad" then
  99.     turbineInfo.setOpacity(.15)
  100.     turbineTitle.setText( name2 )
  101.     turbineMaintenance.setText("Needs Maintenance!")
  102.     elseif message == "TurbineGood" then
  103.     turbineInfo.setOpacity(0)
  104.     turbineTitle.setText(" ")
  105.     turbineMaintenance.setText(" ")
  106. end
  107. modem.close(turbineChannel)
  108.  
  109. modem.open(energyCell1Channel)
  110. modem.transmit( energyCell1Channel, energyCell1Channel, "Go" ) --Tells slave it's listening
  111. event, modemSide, sendCh, rplyCh, message, dist = os.pullEvent("modem_message") --Waits for slave to respond.
  112. if message == "Low" then
  113.     energyCell1Info.setOpacity(.15)
  114.     energyCell1Title.setText( name2 )
  115.     energyCell1Text.setText("Energy Low!")
  116.     elseif message == "Good" then
  117.     energyCell1Info.setOpacity(0)
  118.     energyCell1Title.setText(" ")
  119.     energyCell1Text.setText(" ")
  120. end
  121. modem.close(energyCell1Channel)
  122.  
  123. modem.open(energyCell2Channel)
  124. modem.transmit( energyCell2Channel, energyCell2Channel, "Go" ) --Tells slave it's listening
  125. event, modemSide, sendCh, rplyCh, message, dist = os.pullEvent("modem_message") --Waits for slave to respond.
  126. if message == "Low" then
  127.     energyCell2Info.setOpacity(.15)
  128.     energyCell2Title.setText( name2 )
  129.     energyCell2Text.setText("Energy Low!")
  130.     elseif message == "Good" then
  131.     energyCell2Info.setOpacity(0)
  132.     energyCell2Title.setText(" ")
  133.     energyCell2Text.setText(" ")
  134. end
  135. modem.close(energyCell2Channel)
  136.  
  137.  
  138.  
  139. sleep(.1)
  140. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement