Advertisement
Agent_Silence

tesseract calib

Mar 26th, 2015 (edited)
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.77 KB | None | 0 0
  1. local sides = {
  2. ["top"] = " ",
  3. ["bottom"] = " ",
  4. ["right"] = " ",
  5. ["left"] = " ",
  6. ["back"] = " ",
  7. ["front"] = " "}
  8.  
  9. local function calibrateSide(sSide, pSide)
  10.   if #sides[sSide] == 1 then
  11.     return false
  12.   else
  13.     peripheral.call(pSide,"setBackgroundColor",colors.white)
  14.     peripheral.call(pSide,"setTextColor",colors.black)
  15.     peripheral.call(pSide,"clear")
  16.     sides[sSide] = pSide
  17.     return true
  18.   end
  19. end
  20.  
  21. function calibrate()
  22.   local monitors = {}
  23.   for i,v in pairs(peripheral.getNames()) do
  24.     if peripheral.getType(v) == "monitor" then
  25.       table.insert(monitors, v)
  26.     end
  27.   end
  28.   for i,val in pairs(sides) do
  29.     for k,v in pairs(monitors) do
  30.       peripheral.call(v,"setBackgroundColor",colors.lightBlue)
  31.       peripheral.call(v,"setTextColor",colors.black)
  32.       peripheral.call(v,"clear")
  33.       local w,h = peripheral.call(v,"getSize")
  34.       peripheral.call(v,"setCursorPos",math.floor(w / 2 - string.len("Click the "..i.." monitor.") / 2 + .5), math.floor(h / 2 + .5))
  35.       peripheral.call(v,"write","Click the "..i.." monitor.")
  36.     end
  37.     repeat
  38.       local event, side, x, y = os.pullEventRaw("monitor_touch")
  39.       local isCalibrated = calibrateSide(i,side)
  40.       if isCalibrated == true then
  41.         for k,v in ipairs(monitors) do
  42.           if side == v then
  43.             table.remove(monitors, k)
  44.           end
  45.         end
  46.       end
  47.     until isCalibrated == true
  48.   end
  49.   local monitors = {}
  50.   monitors.top = peripheral.wrap(sides["top"])
  51.   monitors.bottom = peripheral.wrap(sides["bottom"])
  52.   monitors.front = peripheral.wrap(sides["front"])
  53.   monitors.back = peripheral.wrap(sides["back"])
  54.   monitors.left = peripheral.wrap(sides["left"])
  55.   monitors.right = peripheral.wrap(sides["right"])
  56.   return monitors
  57. end
  58. mnitrs = calibrate()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement