Home AMX User Forum AMX Technical Discussion

Mutually Exclusive With Arrays

rolorolo Junior MemberPosts: 51
I have a button array and a device array.

In this particular case , these buttons are for navigation between rooms.

Obviously I cannot have 2 rooms selected at once on a panel.

My statement will read something like this...


DEFINE_DEVICE
dvTP_1=128:1:1

DEFINE_CONSTANT

INTEGER nBtnArray_RoomNav[]={3001,3002} //Array For Navigation Button Numbers
DEV dvAllTP[]={dvTP_1} //Array For Touchpanels

DEFINE_EVENT

BUTTON_EVENT [dvAllTP,nBtnArray_RoomNav]
{
Push:
{
Do Whatever
}

}


How do I define the arrays' buttons as mutually exclusive?


Thanks

Rolo

Comments

  • jjamesjjames Just another dude Posts: 2,906
    One way:
    BUTTON_EVENT [dvAllTP,nBtnArray_RoomNav]
    {
      Push:
      {
        STACK_VAR INTEGER nIND
        STACK_VAR INTEGER nBTN
        nIND = GET_LAST(dvAllTP)
        nBTN = GET_LAST(nBtnArray_RoomNav)
        ON[dvAllTP[nIND],nBtnArray_RoomNav[nBTN]]
      }
    }
    
    And then set up your MUTUALLY_EXCLUSIVE.
    DEFINE_MUTUALLY_EXCLUSIVE
    ([dvAllTP[1],nBtnArray_RoomNav[1]]..[dvAllTP[1],nBtnArray_RoomNav[LENGTH_ARRAY(nBtnArray_RoomNav)]])
    
    But I personally wouldn't even go that route. I would set up a variable that kept track of which room the panel was on, then set the feedback down in DEFINE_PROGRAM. You could easily do something like this:
    DEFINE_VARIABLE
    nCUR_ROOM[x] // x = THE NUMBER OF TOUCH PANELS
    
    DEFINE_EVENT
    BUTTON_EVENT [dvAllTP,nBtnArray_RoomNav]
    {
      Push:
      {
        STACK_VAR INTEGER nIND
        STACK_VAR INTEGER nBTN
        nIND = GET_LAST(dvAllTP)
        nBTN = GET_LAST(nBtnArray_RoomNav)
        
        nCUR_ROOM[nIND] = nBTN
        // DO REST OF BUTTON PUSH STUFF
      }
    }
    
    DEFINE_PROGRAM
    [dvAllTP[1],nBtnArray_RoomNav[1]] = (nCUR_ROOM = 1)
    [dvAllTP[1],nBtnArray_RoomNav[2]] = (nCUR_ROOM = 2)
    

    This way, if you ever need to know which room a panel is controlling, you can run conditionals / evaluations, etc. on this information.
  • This also works, using the buttons themselves as feedback:
    BUTTON_EVENT[dvaTPs,nNavBtns]					// Navigation
    {
    	PUSH:
    	{
    		STACK_VAR INTEGER nPnlIdx ;
    		STACK_VAR INTEGER nBtnIdx ;
    		STACK_VAR INTEGER nLoop ;
    		
    		nPnlIdx = GET_LAST( dvaTPs )
    		nBtnIdx = GET_LAST( nNavBtns )
    		
    		FOR(nLoop = 1; nLoop <= LENGTH_STRING( nNavBtns ); nLoop++)
    			OFF[dvaTPs[nPnlIdx],nNavBtns[nLoop]]
    		
    		ON[dvaTPs[nPnlIdx],nNavBtns[nBtnIdx]]
    	}
    }
    

    But like James said it's nice to have a var tracking your selections because the buttons will turn off if the panel goes offline (which is actually a benefit in some situations).
Sign In or Register to comment.