Home AMX User Forum AMX General Discussion
Options

DEFINE_MUTUALLY_EXCLUSIVE Section

Anyone know if there is anyway to use FOR() Loops in the DEFINE_MUTUALLY_EXCLUSIVE section of a module? I am passing an array of touch panels to the module, but I never know how many touch panels are in the array. I need to make some of the buttons mutually exclusive and it would be nice if I could do something like:

DEFINE_MUTUALLY_EXCLUSIVE

FOR(x=1;x<=LENGTH_ARRAY(dvTPS);x++)
{
([dvTPs[x],nUSER_SELECT_BTNS[1]],
[dvTPs[x],nUSER_SELECT_BTNS[2]],
[dvTPs[x],nUSER_SELECT_BTNS[3]],
[dvTPs[x],nUSER_SELECT_BTNS[4]],
[dvTPs[x],nUSER_SELECT_BTNS[5]])
}


I have a feeling that I will just have to turn OFF/ON all buttons accordingly to handle this properly, but it the season of hope, so if anyone has any thoughts or ideas on the situation, I'd appreciate them. I am going to try the FOR loop and see if it will even compile.

Jeff

Comments

  • Options
    Spire_JeffSpire_Jeff Posts: 1,917
    Well, as I expected, the FOR loop seems to throw the compiler into a tizzy. Hmm, maybe I can write a little function to do this.... I will post it if I come up with something interesting.

    Ok, here it is. This will only work when the mutually exclusive set is contained in an array, but I think this should work. I will edit it if needed after I finish the module that uses this.
    DEFINE_CALL 'EXCLUSIVE ON' (DEV dvTP,INTEGER nBTNS[],INTEGER nON_INDEX)
    {
    	STACK_VAR INTEGER x;
    	STACK_VAR INTEGER y;
    	y = LENGTH_ARRAY(nBTNS);
    	FOR(x=1;x<=y;x++)
    	{
    		IF(x == nON_INDEX)
    			ON[dvTP,nBTNS[x]]
    		ELSE
    			OFF[dvTP,nBTNS[x]]
    	};
    }
    

    Oh, I also did a quick test between using the y variable and just putting LENGTH_ARRAY in the FOR statement. Using an array of 10 buttons, it took an average of 1ms for the call to execute using the y variable and an average of 2ms for it to execute with the LENGTH_ARRAY. Obviously this isn't a big difference, but eventually it could add up to a bigger fraction of a second :P


    Jeff
  • Options
    jazzwyldjazzwyld Posts: 199
    No where near NetLinx

    I'm not even opening up my NetLinx, but what if you kept it in mutually exculsive, use the length array outside of the for loop...say in the constants? so # of touch panels = length array then just in your mutually exclusive reference that variable?
  • Options
    In Programmer II the instructor told us not to use Mutually Exclusive for feedback purposes. Is he wrong?
  • Options
    Joe HebertJoe Hebert Posts: 2,159
    Spire_Jeff wrote:
    DEFINE_CALL 'EXCLUSIVE ON' (DEV dvTP,INTEGER nBTNS[],INTEGER nON_INDEX)
    {
    	STACK_VAR INTEGER x;
    	STACK_VAR INTEGER y;
    	y = LENGTH_ARRAY(nBTNS);
    	FOR(x=1;x<=y;x++)
    	{
    		IF(x == nON_INDEX)
    			ON[dvTP,nBTNS[x]]
    		ELSE
    			OFF[dvTP,nBTNS[x]]
    	};
    }
    
    I?ve still got the towel handy from my last post in case I need to use it again but you should just be able to do this.
    DEFINE_CALL 'EXCLUSIVE ON' (DEV dvTP,INTEGER nBTNS[],INTEGER nON_INDEX)
    {
    
       OFF[dvTP,nBTNS]
       ON[dvTP,nBTNS[nON_INDEX]]
       
    }
    

    Also as small aside, I believe a true mutually exclusive set is a break before make and your original code doesn?t do that (it?s possible for two buttons to be on for a split second). I?m sure it doesn?t matter for your case since it?s TP buttons, however, it were relays it could make a difference.
  • Options
    Joe HebertJoe Hebert Posts: 2,159
    TonyAngelo wrote:
    In Programmer II the instructor told us not to use Mutually Exclusive for feedback purposes. Is he wrong?
    I was told the same but I don't recall the reasoning behind it.
  • Options
    Spire_JeffSpire_Jeff Posts: 1,917
    As I recall, the reason for not using the Mutually Exclusive section was related to relays controlling electrical devices, but it has been a while. I can tell you that the DEFINE_MUTUALLY_EXCLUSIVE section has not caused any problems for me, but I only use it for button feedback. The only thing is that when dealing with an array of touch panels, you have to use the individual touch panels, or you will have problems.

    Good call Joe. I will try to switch it to that. I do tend to hesitate when manipulating arrays that deal with touch panels, because early on I recall having some problems with it functioning properly, but I wouldn't be surprised if it was just my coding that caused the problems :)

    Thanks for the ideas.

    Jeff
  • Options
    Spire_JeffSpire_Jeff Posts: 1,917
    Joe,

    DEFINE_CALL 'EXCLUSIVE ON' (DEV dvTP,INTEGER nBTNS[],INTEGER nON_INDEX)
    {

    OFF[dvTP,nBTNS]
    ON[dvTP,nBTNS[nON_INDEX]]

    }
    Works like a champ.

    Thanks,
    Jeff
  • Options
    Joe HebertJoe Hebert Posts: 2,159
    Glad to hear it.
  • Options
    ericmedleyericmedley Posts: 4,177
    TonyAngelo wrote:
    In Programmer II the instructor told us not to use Mutually Exclusive for feedback purposes. Is he wrong?

    I still use it. Seems to work fine. There are other ways to get it done. I suppose if it ever fails me, I'll make the switch.
  • Options
    DHawthorneDHawthorne Posts: 4,584
    The problem with DEFINE_MUTALLY_EXCLUSIVE is it causes some weird effects due to the rather murky interaction between output channels and feedback channels, which aren't necessarily the same thing, especially with relay outputs. The workaround is use the keyword TOTAL_OFF instead of just OFF on the channel, or your feedback may not reflect the actual output. As far as I know, only hardware channels like relays are really affected, but it's just arcane enough that I'm not certain.
Sign In or Register to comment.