Jump to content
  • Sky
  • Blueberry
  • Slate
  • Blackcurrant
  • Watermelon
  • Strawberry
  • Orange
  • Banana
  • Apple
  • Emerald
  • Chocolate
  • Charcoal
  • 0
Luanub

Multiple Screens / Switching Screens

Question

Hello, I am fairly new to OC but have a fair amount of experience coding. I am working on setting up a Server to start familiarizing myself with the addon. I have the server configured, installed in the rack, OS installed, powered up and running no problems. I would like to have a screen/keyboard setup at the server itself, as well as having another setup elsewhere in the world and be able to use them both to interface with the server.

 

I was hoping to do this using RC and a little service listening for "touch" signals from the monitors to use as the trigger to rebind the GPU/Screen.

 

I have tried several things and can not get this to work as desired. Here is a code example to try and visualize what I am doing. Is this the best approach? What am I doing wrong?

local event = require("event")
local term = require("term")
local component = require("component")

local gpu1 = component.proxy("gpu1's addy")
local gpu2 = component.proxy("gpu2's addy")

local screen1 = component.proxy("screen1's addy")
local screen2 = component.proxy("screen2's addy")

local function handleEvent(name, address)
   if address ~= term.screen() then
      if address == screen1.address then
        gpu1.bind(screen1.address)
        component.setPrimary("gpu",gpu1.address)
      elseif address == screen2.address then
        gpu2.bind(screen2.address)
        component.setPrimary("gpu",gpu2.address)
      end
   end
end

event.listen("touch",handleEvent)

I have tried to use term.bind() and have not had any luck with it either. Sometimes nothing will happen, sometimes just the gpu will change over but not the keyboard(have tried to setPrimary on the keyboard with no luck).

 

Any help would be greatly appreciated.

Link to post
Share on other sites

1 answer to this question

Recommended Posts

  • 0
  • Solution

So I figured it out. I was over complicating things by trying to use a 2nd GPU. After cutting back to 1 GPU it worked, but the keyboard would intermittently not swap over. A couple 1 tick sleeps fixed that. Here is what I ended up with, just got a couple things to add for handling the content of the screens and will be good to go.

local event = require("event")
local term = require("term")
local component = require("component")

local gpu = component.gpu

local screen = component.list("screen")
local screen1 = component.proxy(screen())
local screen2 = component.proxy(screen())

local kb1 = screen1.getKeyboards() --To ensure the correct keyboard goes with the correct screen.
local kb2 = screen2.getKeyboards()

local function touched(name, address, x, y, button, player)
  if address ~= term.screen() then --Check to see if screen touched is the active terminal.
    if address == screen1.address then 
      component.setPrimary("keyboard",kb1[1])
      os.sleep(.05)
      gpu.bind(screen1.address,true)
      os.sleep(.05)
    elseif address == screen2.address then
      component.setPrimary("keyboard",kb2[1])
      os.sleep(.05)
      gpu.bind(screen2.address,true)
      os.sleep(.05)
    end
  end
end

event.listen("touch",touched)
Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use and Privacy Policy.