Jump to content




how to use two monitors at the same time?

peripheral

12 replies to this topic

#1 DTM450

  • Members
  • 20 posts

Posted 18 May 2016 - 06:45 AM

Ok I'm writing up a reactor/turbine controller program and I want to have two monitors one in the reactor room and one in my main room for controlling settings and showing information.

How would I go about this?

I thought maybe I could have both monitors in an array but I don't know if this is possible.

#2 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 18 May 2016 - 08:02 AM

There are quite a few ways, but this here's a fairly short one.

#3 DTM450

  • Members
  • 20 posts

Posted 18 May 2016 - 08:14 AM

*snip*

Thanks I'll try this

Edited by DTM450, 18 May 2016 - 08:55 AM.


#4 DTM450

  • Members
  • 20 posts

Posted 18 May 2016 - 08:50 AM

Is there a way to take touchpoint button presses from the monitors as well?

Edited by DTM450, 18 May 2016 - 08:50 AM.


#5 Dragon53535

  • Members
  • 973 posts
  • LocationIn the Matrix

Posted 18 May 2016 - 10:55 AM

From both monitors? It's possible yeah. Difficult given that Lyqyd didn't create an in built way to do so.

If you just want to use the in built button function, the easiest way would be to create an array of touchpoint pointers, one for each monitor, and loop through this array and create an array of function pointers that are structured like:
function() return otherFunction(touch[i]) end
And then use unpack on this array inside a parallel.waitForAny() call.


os.loadAPI("touchpoint")
local function runButtons(t)
  while true do

   local event = {t:handleEvents()}

   if event == "button_click" then
	  
	 if t.buttonList[event[2]].func then
	
	   t.buttonList[event[2]].func()

	 end
   end
  end
end

--#Declare table monSides to contain either the side next to the computer, or the name of the monitor like "monitor_666"

local touch = {}

for a,v in ipairs(monSides) do
  touch[a] = touchpoint.new(v)
end

--#Define your buttons here. As well as any functions they should run

local runTable = {}

for a,v in ipairs(touch) do
  runTable[a] = function() return runButtons(touch[a]) end
end

parallel.waitForAny(unpack(runTable))
Coded it up on a whim because it was an interesting problem, mind you anything you want your buttons to do you have to code, but this 'should' allow for you to set up touchpoints on each monitor, as well as automatically handle buttons and running functions per buttons.

Edited by Dragon53535, 18 May 2016 - 11:00 AM.


#6 DTM450

  • Members
  • 20 posts

Posted 19 May 2016 - 04:19 AM

View PostDragon53535, on 18 May 2016 - 10:55 AM, said:

From both monitors? It's possible yeah. Difficult given that Lyqyd didn't create an in built way to do so.

yes from both

heres what I have so far but I'm having trouble wrapping my head around it
*snip*

--#Declare table monSides to contain either the side next to the computer, or the name of the monitor like "monitor_666"
monSides = {"monitor_0","monitor_1"}
local touch = {}

for a,v in ipairs(monSides) do
  touch[a] = touchpoint.new(v)
end

--#Define your buttons here. As well as any functions they should run

local runTable ={add("b1", t:flash(event[2]),1,1,4,1,colours.red,colours.lime)
				}

for a,v in ipairs(touch) do
  runTable[a] = function() return runButtons(touch[a]) end
end

parallel.waitForAny(unpack(runTable))

would I be able to populate the monSides table with peripheral.find("monitor")
and I'm not sure where I put the t:draw function and would I still need to use the t = touchpoint.new() declaration to be able to use the 't:'

#7 Dragon53535

  • Members
  • 973 posts
  • LocationIn the Matrix

Posted 19 May 2016 - 04:47 AM

No you wouldn't be able to populate it with peripheral.find as that automatically wraps the peripherals for you, you need the side/name because touchpoint wraps it as well.

Make monSides a local table.

Nono, you're not going to use t = touchpoint.new at all, that's what the first loop does, it create a new table and puts a touchpoint object (what touchpoint new gives) into that table for each monitor you tell it to. So touch[1] is going to be the touchpoint for "monitor_0"

Don't touch the runTable table. Moreso because you never actually closed it, and because it's going to be filled with funciton pointers.

As for adding buttons, you need to use touch[number]:add to add them. For your t:flash()

function() touch[number]:flash("b1") end

So the entire add for b1 would be.

touch[1]:add("b1",function() touch[1]:flash("b1") end,1,1,4,1,colors.red,colors.llime)

Edited by Dragon53535, 19 May 2016 - 04:48 AM.


#8 DTM450

  • Members
  • 20 posts

Posted 19 May 2016 - 05:50 AM

Ok I sort of understand it better but I cant get the button to flash when I press it on either monitor

also changing :flash("b1") to :flash(event[2]) should do the same thing. using event[2] simplifies the code so you don't have to edit multiple parts of the code

revised code
--#Declare table monSides to contain either the side next to the computer, or the name of the monitor like "monitor_666"

local monSides = {"monitor_0","monitor_1"}
local touch = {}

for a,v in ipairs(monSides) do
  touch[a] = touchpoint.new(v)
end

--#Define your buttons here. As well as any functions they should run

--#This loop adds and draws buttons to all screens
for a,v in ipairs(monSides) do
  touch[a]:add("b1",function() touch[a]:flash("b1") end,1,1,4,3,colors.red,colors.lime)
  touch[a]:draw()
end

local runTable ={}

for a,v in ipairs(touch) do
  runTable[a] = function() return runButtons(touch[a]) end
end

parallel.waitForAny(unpack(runTable))

Edited by DTM450, 19 May 2016 - 05:53 AM.


#9 Dragon53535

  • Members
  • 973 posts
  • LocationIn the Matrix

Posted 19 May 2016 - 08:32 AM

event[2] isn't defined at the time the function is written.

Revised2:

os.loadAPI("touchpoint")
local function runButtons(t)
  while true do

   local event = {t:handleEvents()}

   if event == "button_click" then

		 if t.buttonList[event[2]].func then

		   t.buttonList[event[2]].func(t,event[2])

		 end
   end
  end
end
--#Declare table monSides to contain either the side next to the computer, or the name of the monitor like "monitor_666"
local monSides = {"monitor_0","monitor_1"}
local touch = {}
for a,v in ipairs(monSides) do
  touch[a] = touchpoint.new(v)
end
--#Define your buttons here. As well as any functions they should run
--#This loop adds and draws buttons to all screens
for a,v in ipairs(monSides) do
  touch[a]:add("b1",function(self,param1) self:flash(param1) end,1,1,4,3,colors.red,colors.lime)
  touch[a]:draw()
end
local runTable ={}
for a,v in ipairs(touch) do
  runTable[a] = function() return runButtons(touch[a]) end
end
parallel.waitForAny(unpack(runTable))

Changed the function call to pass the touchpoint table to your button function, as well as the button name. Changed the function declaration of your flash to accept the arguments and use them for flash.

Edited by Dragon53535, 19 May 2016 - 08:33 AM.


#10 DTM450

  • Members
  • 20 posts

Posted 19 May 2016 - 09:57 AM

ok buttons aren't working they appear on the monitors and I've tried it using the term method but I cant press them for some reason
Spoiler

Edited by DTM450, 20 May 2016 - 12:39 AM.


#11 DTM450

  • Members
  • 20 posts

Posted 20 May 2016 - 12:41 AM

I updated the runButtons function to Revised2 because I forgot to do that last night but I still cant press the buttons and I have no idea why

also I'm running CC 1.75 but I dont think that should matter to much

#12 Dragon53535

  • Members
  • 973 posts
  • LocationIn the Matrix

Posted 20 May 2016 - 05:42 AM

Lol, I screwed up in the runButtons function.

On the if statement inside the runButtons function, add [1] after event.

if event[1] == "button_click" then


#13 DTM450

  • Members
  • 20 posts

Posted 20 May 2016 - 05:47 AM

View PostDragon53535, on 20 May 2016 - 05:42 AM, said:

Lol, I screwed up in the runButtons function.

On the if statement inside the runButtons function, add [1] after event.

if event[1] == "button_click" then

XD okey dokey

*edit*

WOOH its working thanks a ton for your help


Heres the full functioning code in the spoiler for anyone who wants it. Also on pastebin

Spoiler

Edited by DTM450, 20 May 2016 - 05:58 AM.






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users