Home AMX User Forum NetLinx Studio

Use of arrays to control similar devices

Hi All,

I just finished the Programmer II class and started working on an AV project. I have been a programmer, but new to AV control world and NetLinx Programming Language. As part of the project I need to control 8 NEC E552 TVs. I found the duet module for it and used in my code. The TVs are located in different rooms and are connected using DXLink Receivers.

I have one TP screen to control all of them (volume +/-, mute on/off, power on/off) really simple stuff.

I ended up creating separate TP ports for each TV and used the same channel numbers, but could not figure out how to simplify my code. So, I wrote the below code block for each TV (only one of them is shown):
DEFINE_DEVICE

dvNEC_BLDGENGRG22_1   	=	6008:1:0;

dvTP_NEC_BLDGENGRG22_1  =	10001:18:0;

vdvNEC_BLDGENGRG22_1   	=	41008:1:0;

DEFINE_VARIABLE

 VOLATILE DEVCHAN dcTP_NEC_BLDGENGRG22_1[]=
{
    {dvTP_NEC_BLDGENGRG22_1, 24},
    {dvTP_NEC_BLDGENGRG22_1, 25},
    {dvTP_NEC_BLDGENGRG22_1, 199},
    {dvTP_NEC_BLDGENGRG22_1, 27},
    {dvTP_NEC_BLDGENGRG22_1, 28}
}

DEFINE_START

DEFINE_MODULE 'NEC_E552_Comm_dr1_0_0' tv8(vdvNEC_BLDGENGRG22_1, dvNEC_BLDGENGRG22_1);

DEFINE_EVENT

BUTTON_EVENT [dcTP_NEC_BLDGENGRG22_1] 
{ 
    PUSH: 
    {
    	if (button.input.channel != 199)
	{
	    IF (BUTTON.INPUT.CHANNEL == VOL_UP OR BUTTON.INPUT.CHANNEL == VOL_DN)
	    {	
		ON [vdvNEC_BLDGENGRG22_1, BUTTON.INPUT.CHANNEL];
	    }
	    ELSE
	    {
		PULSE [vdvNEC_BLDGENGRG22_1, BUTTON.INPUT.CHANNEL];
	    }
	}
	else
	{
	    [vdvNEC_BLDGENGRG22_1, VOL_MUTE_ON] = ![vdvNEC_BLDGENGRG22_1, VOL_MUTE_FB];
	}
    }
    
    RELEASE:
    {
	IF (BUTTON.INPUT.CHANNEL == VOL_UP OR BUTTON.INPUT.CHANNEL == VOL_DN)
	{	
	    ON [vdvNEC_BLDGENGRG22_1, BUTTON.INPUT.CHANNEL];
	}
    }
}

My question is, how can I simplify my code? My not directly related, but I also have an issue with volume ramp up event, in which somehow the TV does not go above Volume level 13. On the TP I only have volume ramp up and down buttons no bargraph for level event. Any ideas?

Thanks,
Sinan

Comments

  • You can use the get_last command inside an event handler to identify which item in a device array caused the handler to trigger.

    If I understand your example correctly, you have shown the DEVCHAN array and button event handler for only one TV and would replicate this for each TV you are controlling. You could instead gather the TP ports in to a DEV array, the devices being controlled in to a second dev array and the button channels in to an INTEGER array, then use a single button event handler for them all.

    For example:
    DEFINE_DEVICE
    // Touch panel device ports - one per TV
    dvTP1 = 10001:1:0;
    dvTP2 = 10001:2:0;
    // TVs
    dvTV1 = 6008:1:0;
    dvTV2 = 6009:1:0;
    // Virtual TVs
    vdvTV1 = 41008:1:0;
    vdvTV2 = 41009:1:0;
    
    DEFINE_VARIABLE
    dev dvTP_All[] = { dvTP1, dvTP2 };
    dev vdvTV_All[] = { vdvTV1, vdvTV2 };
    integer nButtonChannels = { 24, 25, 27, 28 };
    
    DEFINE_EVENT
    button_event[dvTP_All, nButtonChannels]
    {
        push:
        {
            stack_var integer nDeviceIndex, nButtonIndex;
            nDeviceIndex = get_last(dvTP_All);
            nButtonIndex = get_last(nButtonChannels);
            // Do something based on the particular TP port and button channel, for example...
            pulse[vdvTV_All[nDeviceIndex], nButtonChannels[nButtonIndex]];
        }
    }
    
    The single button event handler then deals with the defined button channels across all touch panel ports and sends the comand to the appropriate TV. Of course, this relies on the touch panel array and the virtual device array having their contents in the same order.

    Andy
  • viningvining Posts: 4,368
    I would scrub the idea of using a TP port for each TV, there's just no reason and do you really want to modify 10 page/popUp groups every time you want to make a change to your layout. I'd scrub the DEVCHAN's too.

    Just create another array to track what AV system / TV that any given TP should be controlling. Make the TP's index position match the corresponding index position of virtual dev of the controlled system.
    DEFINE_CONSTANT
    
    NUM_TPs		= 10;
    NUM_TVs		= 10;
    
    DEFINE_VARIABLE
    
    dev dvTP_TVs[NUM_TPs] = { dvTP1,dvTP2,dvTP3,dvTP3,dvTP5,dvTP6,dvTP7,dvTP8,dvTP9,dvTP10};
    dev vdvTV_All[NUM_TVs] = {vdvTV1,vdvTV2,vdvTV3,vdvTV4,vdvTV5,vdvTV6,vdvTV7,vdvTV8,vdvTV9,vdvTV10};
    //integer nButtonChannels = { 24, 25, 27, 28 };
    PERSISTENT INTEGER nTP_Sys_Controlled[NUM_TPs]={1,2,3,4,5,6,7,8,9,10};//could also write to file for better persistence.
    
    DEFINE_EVENT
    
    BUTTON_EVENT[dvTP_TVs,0]//if only TVs use this TP port 0 (catch all) is usually better than creating an array of channels.
         
         {
         push:
    	  {
    	  STACK_VAR INTEGER nTP;
    	  STACK_VAR INTEGER nBtn;
    	  
    	  nTP = GET_LAST(dvTP_TVs);
    	  nBtn = BUTTON.INPUT.CHANNEL;
    	  // control the TV of the system currently assigned to a particular TP
    	  pulse[vdvTV_All[nTP_Sys_Controlled[nTP]],nBtn];
    	  }
         }
    
  • stopuzstopuz Posts: 15
    Use of arrays to control similar devices

    Thank you guys. I will give these a try.

    Vining,

    In your example, what is the difference between the system and the TV? Why is another layer needed? Could you explain a liitle?

    Thanks,
    Sinan
  • viningvining Posts: 4,368
    The array for the TP system control would allow you to change which TP controls what TV/System. Just to populate the array I went sequential but the reality is TP 1 could be controlling TV/System 3 while TP 4 could be controlling TV/System 1. Give yourself some buttons to select what system a TP is to control and then set the TPs control array index to that system number. Ideally you want any TP to be able to control any TV/system even if you don't give the users that ability to change you'll want it yourself just in case a TP craps out.

    Your Dev and vDev arrays will usually be in a constant static order in most cases which is why I tend create them as constant arrays not variable arrays but your TP system control array could vary day to day.
  • stopuzstopuz Posts: 15
    Guys, thank you for clarifying this. I had another question that I posted in the forum regarding the use of duet module sample workspaces for multiple touch panels. I'd appreciate it if you could make some comments on that as well.

    http://www.amxforums.com/showthread.php?9546-Using-a-duet-module-sample-workspace-for-multiple-touch-panels

    Thanks,
    Sinan
Sign In or Register to comment.