Guest User

Screen

a guest
Jul 11th, 2014
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.08 KB | None | 0 0
  1. --Modem Communication Numbering
  2. -- 1/2 Screen to Server 1
  3. -- 2/1 Server 1 to Screen
  4. --3/4 Screen to Power Emergency PC
  5. -- 4/3 Pwr Em. PC to Screen
  6.  
  7. local modem = peripheral.wrap('back')
  8. local screen = peripheral.wrap('top')
  9.  
  10. function ps(n) --similar to print
  11. screen.write(n)
  12. x,y=screen.getCursorPos()
  13. y=y+1
  14. screen.setCursorPos(1,y)
  15. end
  16.  
  17. function w(n) --write same line
  18. x1,y1=screen.getCursorPos()
  19. screen.setCursorPos(1,y1)
  20. screen.clearLine()
  21. screen.write(n)
  22. end
  23.  
  24. function reset() --places cursor to left again
  25. x1,y1=screen.getCursorPos()
  26. screen.setCursorPos(1,y1)
  27. end
  28.  
  29. function send(chan,reply,m) --transmits a message
  30.         modem.transmit(chan,reply,m)
  31. end
  32.  
  33. function get(chan,tmout)--listener
  34.     if tmout==nil then
  35.     tmout=100000000000000000000000000000 --change to call event w/o timer
  36.     end
  37.     modem.open(chan) --opens port
  38.     chk=modem.isOpen(chan) --checks to make sure it is open
  39.         if chk==true then --will set listener
  40.         --mm = os.pullEvent("modem_message")
  41.         timeout = os.startTimer(tmout)
  42.         while true do
  43.             event = {os.pullEvent()}
  44.             if event[1] == "modem_message" then
  45.                 --print'Worked'
  46.                 --print(event[1].." "..event[2].." "..event[3].." "..event[4].." "..event[5].." "..event[6])
  47.                 msg=event[5]
  48.                 returnchan=event[4]
  49.                 chan=event[3]
  50.                 success=1
  51.                 break
  52.                 elseif event[1] == "timer" and event[2] == timeout then
  53.                 success=0
  54.                 break
  55.             end
  56.         end
  57.  
  58.     end
  59.     if chk==false then
  60.         --send error# to screen
  61.         print('Error 100: Failed to Bind Port '..chan..'.')
  62.     end
  63. end
  64.  
  65. function chksvr(sendchan,svrnum,gettmout)
  66. send(sendchan,2,"ping")
  67. get(2,gettmout)
  68. if success==1 then
  69. screen.setCursorPos(1,svrnum+2)
  70. w("Server "..svrnum..": Online")
  71. end
  72. if success==0 then
  73. screen.setCursorPos(1,svrnum+2)
  74. w("Server "..svrnum..": DOWN")
  75. end
  76. --sleep(5)
  77. end
  78.  
  79. --main
  80. screen.clear()
  81. screen.setCursorPos(1,1)
  82. ps("Kizz Tower Control: ONLINE")
  83. ps("")
  84.  
  85.  
  86.  
  87. --MAIN LOOP for REFRESH
  88. function main()
  89. key=1
  90.     while true do
  91.    
  92.     if key==1 then
  93.     timeout2 = os.startTimer(2)
  94.     end
  95.     eventData = {os.pullEvent()}
  96.         if eventData[1] == "stop_main" then
  97.             key=0
  98.             return
  99.             elseif eventData[1] == "timer" and eventData[2] == timeout2 then
  100.             --Server Checks/Screen
  101.             chksvr(1,1,.5)
  102.             chksvr(3,2,.5)
  103.             chksvr(5,3,.5)
  104.             --Power system checks/screen
  105.            
  106.            
  107.            
  108.             --Screen choice chk
  109.         end      
  110.     end
  111. end
  112.  
  113. function scch()
  114. while true do
  115. print'Welcome to the Screen Server'
  116. print'Please select an option:'
  117. print'1: Server Monitor'
  118. print'2: Power Systems Monitor'
  119. print'3: System Control Touch Monitor'
  120. print'4: System Shutdown'
  121.  
  122. sel=io.read()
  123. sel=sel+1-1
  124.  
  125. if sel==1 then
  126. print'Currently active.'
  127. end
  128. if sel==2 then
  129. print'Coming soon.'
  130. end
  131. if sel==3 then
  132. print'Coming soon.'
  133. end
  134. if sel==4 then
  135. print'Shutting down!'
  136. os.queueEvent("stop_main")
  137. --os.pullEvent("stop_main")
  138. --sleep()
  139. screen.clear()
  140. screen.setCursorPos(1,1)
  141. ps("Warning! System Shutting Down!")
  142. sleep(5)
  143. screen.clear()
  144. os.shutdown()
  145. end
  146.  
  147. term.clear()
  148. term.setCursorPos(1,1)
  149. end
  150. end
  151.  
  152. parallel.waitForAll(scch, main)
  153. --end main
Advertisement
Add Comment
Please, Sign In to add comment