Advertisement
m0nstar

base_status_display

Jul 28th, 2016
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.89 KB | None | 0 0
  1. --[[
  2.  
  3. Base Status Display
  4.  
  5. Listens on base power channel and reactor status channel
  6. Displays stats on connected screen
  7.  
  8. ]]--
  9.  
  10. local base_power_status_channel = 1
  11. local reactor_status_channel = 2
  12.  
  13. local wlan = peripheral.wrap('right')
  14. local mon = peripheral.wrap('top')
  15.  
  16. -- Init monitor
  17. mon.setBackgroundColor(colors.black)
  18. mon.setTextColor(colors.white)
  19. mon.setCursorPos(1,1)
  20. mon.setTextScale(1)
  21. mon.clear()
  22.  
  23. -- Returns YYY if given XXX=YYY
  24. function splitaftereq(s)
  25.   return string.sub(s,string.find(s,'=')+1,-1)
  26. end
  27.  
  28. wlan.open(base_power_status_channel)
  29. wlan.open(reactor_status_channel)
  30. print("Loop..")
  31.  
  32. while true do
  33.   local event, modemSide, senderChan, replyChan, msg, senderDist = os.pullEvent("modem_message")
  34.  
  35.   if string.match (msg,"^datetime") then
  36.     datetime=splitaftereq(msg)
  37.     mon.setCursorPos(1,1)
  38.     mon.write(datetime..'               ')
  39.   end
  40.  
  41.   if string.match (msg,"^power_percent") then
  42.     power_percent=splitaftereq(msg)
  43.     mon.setCursorPos(1,3)
  44.     mon.write('Base Power   : '..power_percent..'%         ')
  45.   end
  46.  
  47.   if string.match (msg,"^state") then
  48.     state=splitaftereq(msg)
  49.     mon.setCursorPos(1,4)
  50.     mon.write('Reactor State: '..state..'                  ')
  51.   end
  52.  
  53.   if string.match (msg,"^rods") then
  54.     rods=splitaftereq(msg)
  55.     mon.setCursorPos(1,5)
  56.     mon.write('Control Rods : '..rods..'%                  ')
  57.   end
  58.  
  59.   if string.match (msg,"^heat") then
  60.     heat=splitaftereq(msg)
  61.     mon.setCursorPos(1,6)
  62.     mon.write('Core Heat    : '..heat..'C                  ')
  63.   end
  64.  
  65.   if string.match (msg,"^fueltick") then
  66.     fueltick=splitaftereq(msg)
  67.     mon.setCursorPos(1,7)
  68.     mon.write('Fuel Usage   : '..fueltick..' mB/t          ')
  69.   end
  70.  
  71.   if string.match (msg,"^rftick") then
  72.     rftick=splitaftereq(msg)
  73.     mon.setCursorPos(1,8)
  74.     mon.write('Generating   : '..rftick..' KRF/t            ')
  75.   end
  76.  
  77. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement