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):
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
                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
0          
            
Comments
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
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]; } }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
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.
http://www.amxforums.com/showthread.php?9546-Using-a-duet-module-sample-workspace-for-multiple-touch-panels
Thanks,
Sinan