Home AMX User Forum NetLinx Studio
Options

OFFing an Array of Buttons

I would like to do something like this as a means of mutual exclusivity for the sake of feedback:
INTEGER cnFEEDBACKS[10]={1,2,3,4,5,6,7,8,9,10}

OFF [dvTP,cnFEEDBCAKS]

However this does not work. Does anyone have a suggested alternative for a one-line button-feedback-array killer? I don't want to define as mutually exclusive.

Thanks!

Comments

  • Options
    czhouczhou Posts: 4
    Is your 'dvTP' an array? It should work if it's a DEV but won't work for an array.
  • Options
    HedbergHedberg Posts: 671
    I can't see an easy way to do it with out a loop.
    The following function seems to work::
    define_function funBtnArrayKill(dev dvDevice,integer nArrayIn[])
    {
    	stack_var integer i
    	for(i = 1; i < length_array(nArrayIn) +1; i++)
    	{
    		off[dvDevice,nArrayIn[i]]
    	}
    }
    
  • Options
    viningvining Posts: 4,368
    This is basically the same code I posted yesterday on a different thread but this version uses a function in the button event to give the appearance of one line of code but of course it requires the added block of code with in the function. This handles ON as well as OFF in the same manner as Mutually Exclusive probably does.


    DEFINE_DEVICE
    
    dvTPSwitcher  	= 10001:1:0 ;
    dvSwitcher 	=  5001:1:0 ;
    
    DEFINE_FUNCTION fnHandleSwitcherBtnFBack(INTEGER iStartingINdex,INTEGER iBtn)
    
         {
         stack_var integer i ;
         
         for (i = iStartingINdex ; i <= iStartingINdex + 7 ; i ++)//handle  feedback
    	  {
    	  if (iBtn == i)
    	       {
    	       ON [dvTPSwitcher,nSwitcherBtnArry[i]] ;
    	       }
    	  else
    	       {
    	       OFF [dvTPSwitcher,nSwitcherBtnArry[i]] ;
    	       }
    	  }
         }
    
    DEFINE_VARIABLE
    
    volatile integer nSwitcherBtnArry[] = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17} ;
    
    BUTTON_EVENT [dvTPSwitcher,nSwitcherBtnArry]
    
         {
         PUSH:
    	  {
    	  stack_var integer nSwitcherIN ;
    	  stack_var integer nSwitcherOUT ;
    	  stack_var integer nBtn ;
    	  
    	  nBtn = get_last(nSwitcherBtnArry) ;
    	  
    	  Select
    	       {
    	       ACTIVE (nBtn >= 1 && nBtn <= 8)://select switcher input
    		    {
    		    nSwitcherIN = nBtn ;
    		    fnHandleSwitcherBtnFBack(1,nBtn)
    		    }
    	       ACTIVE (nBtn >= 9 && nBtn <= 16)://select switcher output
    		    {
    		    nSwitcherOUT = nBtn ;
    		    fnHandleSwitcherBtnFBack(9,nBtn)
    		    }     
    	       ACTIVE (nBtn == 17)://take in & out
    		    {
    		    TO [dvTPSwitcher,nSwitcherBtnArry[17]] ;
    		    send_string dvSwitcher,"ITOA(nSwitcherIN),'*',ITOA(nSwitcherOUT),'!',13,10" ;
    		    }
    	       }
    	  }
         }
    
    
  • Options
    dchristodchristo Posts: 177
    I haven't had a chance to test it, but shouldn't a DevChan array do the trick?
    DEVCHAN dcFeedback[]  = {{device,1}, {device,2}, {device,3}, {device,4}}
    
    
    OFF[dcFeedback]
    

    --D
  • Options
    TurnipTruckTurnipTruck Posts: 1,485
    dchristo wrote:
    I haven't had a chance to test it, but shouldn't a DevChan array do the trick?

    --D

    That will work, but I don't like DEVCHANs. I just array the button channel numbers and reference the array. Makes for less code.
Sign In or Register to comment.