SD_Ecliptica

Nick OpenPeripheral

Nov 23rd, 2013
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.18 KB | None | 0 0
  1. local bridge = peripheral.wrap("bottom")
  2. local m = peripheral.wrap("right")
  3. m.setTextScale(.5)
  4. m.clear()
  5.  
  6. local nCol = {}
  7. nCol.red = 0xff0000
  8. nCol.blue = 0x7dd2e4
  9. nCol.yellow = 0xffff4d
  10. nCol.green = 0x4dff4d
  11. nCol.gray = 0xe0e0e0
  12. nCol.grey = 0x909090
  13. nCol.night = 0x2020e0
  14. nCol.lime = 0x55ff55
  15. nCol.black = 0x000000
  16. nCol.white = 0xffffff
  17. nCol.dusk = 0x902090
  18.  
  19. local power = 0
  20. local light = 0
  21. local line = 1
  22. local comMessage = "No news to report."
  23.  
  24. rednet.open("top")
  25.  
  26. m.setCursorPos(1,5)
  27. m.setTextColor(colors.purple)
  28. m.write("----------------------------------------------------")
  29.  
  30. print("Ecliptica OS Loaded...")
  31.  
  32. while true do
  33.  
  34.   -- clear the display
  35.   bridge.clear()
  36.  
  37.   -- display welcome message
  38.   welcome = "Ecliptica OS Loaded"
  39.   text = bridge.addText(5, 5, welcome, nCol.white)
  40.   m.setCursorPos(5,7)
  41.   m.setTextColor(colors.yellow)
  42.   m.write(welcome)
  43.  
  44.   -- display current time
  45.   time = "IGT: " .. textutils.formatTime(os.time(), true)
  46.   bridge.addText(5, 15, time, nCol.lime)
  47.   m.setCursorPos(5,9)
  48.   m.setTextColor(colors.lime)
  49.   m.write("          ")
  50.   m.setCursorPos(5,9)
  51.   m.write(time)
  52.  
  53.   -- display current day
  54.   day = "Day: " .. os.day()
  55.   bridge.addText(55, 15, day, nCol.blue)
  56.   m.setCursorPos(5,11)
  57.   m.setTextColor(colors.cyan)
  58.   m.write("           ")
  59.   m.setCursorPos(5,11)
  60.   m.write(day)
  61.  
  62.   -- display power information
  63.   local powerLabel = "Power "
  64.   bridge.addText(5, 25, powerLabel, nCol.red)
  65.   barLength = 58 * power
  66.   bridge.addBox(42, 26, barLength, 5, nCol.white, .5)
  67.   bridge.addBox(42 + barLength, 26, 58 - barLength, 5, nCol.red, .5)
  68.   m.setCursorPos(5,13)
  69.   m.setTextColor(colors.red)
  70.   m.write("                                             ")
  71.   m.setCursorPos(5,13)
  72.   m.write("Power: " .. math.floor(power * 600000) .. "/600,000")
  73.  
  74.   -- display light information
  75.   barLength = 58 * light
  76.   bridge.addBox(42, 36, barLength, 5, nCol.yellow, .5)
  77.   bridge.addBox(42 + barLength, 36, 58 - barLength, 5, nCol.black, .5)
  78.   m.setCursorPos(5,15)
  79.   m.setTextColor(colors.yellow)
  80.   m.write("                        ")
  81.   m.setCursorPos(5,15)
  82.   m.write("Light: " .. light * 15 .. "/15")
  83.  
  84.   -- calculate weather from time and light levels
  85.   if os.time() < 6 or os.time() > 20 then
  86.     bridge.addText(5, 35, "Night", nCol.night)
  87.   elseif os.time() > 17 then
  88.     bridge.addText(5, 35, "Dusk", nCol.dusk)
  89.   elseif light * 15 <= 9  then
  90.     bridge.addText(5, 35, "Stormy", nCol.gray)
  91.   elseif light * 15 <= 11 then
  92.     bridge.addText(5, 35, "Dreary", nCol.blue)
  93.   else
  94.     bridge.addText(5, 35, "Clear", nCol.yellow)
  95.   end
  96.  
  97.   -- clear connected users
  98.   m.setCursorPos(5,18)
  99.   m.write("                       ")
  100.   m.setCursorPos(5,19)
  101.   m.write("                       ")
  102.   m.setCursorPos(5,20)
  103.   m.write("                       ")
  104.   m.setCursorPos(5,21)
  105.   m.write("                       ")
  106.   m.setCursorPos(5,22)
  107.   m.write("                       ")
  108.   m.setCursorPos(5,23)
  109.   m.write("                       ")
  110.   m.setCursorPos(5,24)
  111.   m.write("                       ")
  112.  
  113.   -- display connected users
  114.   bridge.addText(5, 45, "Connections:", nCol.white)
  115.   local users = bridge.getUsers()
  116.   yLoc = 55
  117.   m.setTextColor(colors.white)
  118.   m.setCursorPos(5,17)
  119.   m.write("Connections:")
  120.   monitorLine = 18
  121.   for key, value in pairs(users) do
  122.     bridge.addText(5, yLoc, "- " .. value, nCol.blue)
  123.     m.setCursorPos(5,monitorLine)
  124.     m.write("- " .. value)
  125.     monitorLine = monitorLine + 1
  126.     yLoc = yLoc + 10
  127.   end
  128.  
  129.   -- display com message
  130.   --bridge.addText(350, 230, comMessage, nCol.gray)
  131.  
  132.   -- check rednet for notifications
  133.   local sender, message, distance = rednet.receive()
  134.   line = line + 1
  135.   if line == 5 then
  136.     line = 1
  137.   end
  138.   m.setCursorPos(1,line)
  139.   m.write("                                          ")
  140.   m.setCursorPos(1, line)
  141.   m.setTextColor(colors.cyan)
  142.   m.write("[" .. textutils.formatTime(os.time(), true) .. "]")
  143.   m.setTextColor(colors.white)
  144.   m.setCursorPos(8,line)
  145.   m.write(" (" .. math.floor(distance) .. "m) " .. message .. " from " .. sender)
  146.   if sender == 507 then
  147.     power = tonumber(message) / 600000
  148.   elseif sender == 508 then
  149.     light = tonumber(message) / 15
  150.   end
  151. end
Advertisement
Add Comment
Please, Sign In to add comment