Home AMX User Forum AMXForums Archive Threads Tips and Tricks

Get_last

jjamesjjames Just another dudePosts: 2,906
Okay,

I've seen several threads regarding and posts suggesting the use of GET_LAST. I've found this technique to work wonderful (for me), so for anyone that's not familiar with it, here's how I use it (as I'm sure most of you do.)

First, an array (usually a constant) ...
INTEGER TRANSPORT_BTNS[] = // TRANSPORT BUTTONS (71-79)
{
	71, //  1 - Play
	72, //  2 - Stop
	73, //  3 - Pause
	74, //  4 - FFWD - Next
	75, //  5 - REW  - Prev
	76, //  6 - SFWD
	77, //  7 - SREV
	78, //  8 - Record
	79  //  9
}
Then a button event ...
BUTTON_EVENT[dv_TP,TRANSPORT_BTNS] (* BUTTONS 71-80 *)
{
	PUSH:
	{
		STACK_VAR INTEGER nBTN
		nBTN = GET_LAST(TRANSPORT_BTNS)
		SEND_COMMAND dvCABLE,"'SP',nBTN"
	}
}
So what's happening here is nBTN becomes the index of which button was hit. If button 71 was hit, nBTN becomes 1, and the SEND_COMMAND would send the 1st IR for the cable box. If 72 was hit, nBTN becomes 2, and so forth.

Now, as coders, we want to get things done quickly, and with the least amount of lines. Let's face it - we hate typing. So, here's a little trick I picked up on. Since we'll never use that STACK_VAR again, and cannot see it in diagnostices, let's take out the declaration of the STACK_VAR and the assignment of nBTN, resulting in this.
BUTTON_EVENT[dv_TP,TRANSPORT_BTNS] (* BUTTONS 71-80 *)
{
	PUSH:
		SEND_COMMAND dvCABLE,"'SP',GET_LAST(TRANSPORT_BTNS)"
}
And since we have only one "event" or "command" under push, the braces are not required, but I would assume that's not best practice.

Comments

  • DHawthorneDHawthorne Old Timer Posts: 4,584
    I use GET_LAST extensively. Having a lot of experience in the Axcent3 world, I found it a ready replacement for the PUSH_CHANNEL keyword, only quite a bit more flexible. A caution though, it only works properly in an event; you can't quite use it like PUSH_CHANNEL in mainline. I imagine it will return the last time the operand had an associated event, so it might work, but wouldn't be very reliable.
  • Joe HebertJoe Hebert Junior Member Posts: 2,159
    Let?s take it one step farther. Let?s say we want to add channel up and down to the list of transports. We can modify the original example by adding these two buttons in:
    INTEGER TRANSPORT_BTNS[] = // TRANSPORT BUTTONS (71-80)
    {
    	71, //  1 - Play
    	72, //  2 - Stop
    	73, //  3 - Pause
    	74, //  4 - FFWD - Next
    	75, //  5 - REW  - Prev
    	76, //  6 - SFWD
    	77, //  7 - SREV
    	78, //  8 - Record
    	[b]79, //  22 - Channel +
    	80  //  23 - Channel ? [/b]
    }
    

    But now we don?t have a one to one correlation of button index to IR code so we?ll add an array to map the desired IR code to be sent to the button that was pushed.
    INTEGER TRANSPORT_MAP[] = {  //IR channel codes
    
    	1, //   Play
    	2, //  Stop
    	3, //  Pause
    	4, //  FFWD - Next
    	5, //  REW  - Prev
    	6, //  SFWD
    	7, //  SREV
    	8, //  Record
    	[b]22, //  Channel +
    	23  //   Channel ? [/b]
    
    }
    
    Then when we do the button push we can grab the IR channel that matches the button index and if doing simple remote mimicking we can send the IR by doing something like:
    BUTTON_EVENT[dv_TP,TRANSPORT_BTNS] (* BUTTONS 71-80 *)
    {
    
       PUSH: {
          TO[dvCable,TRANSPORT_MAP[GET_LAST(TRANSPORT_BTNS)]]
       }
    }
    
  • HARMAN_icraigieHARMAN_icraigie Technical Trainer II, Harman Professional University Posts: 600
    DHawthorne wrote:
    I use GET_LAST extensively. Having a lot of experience in the Axcent3 world, I found it a ready replacement for the PUSH_CHANNEL keyword, only quite a bit more flexible. A caution though, it only works properly in an event; you can't quite use it like PUSH_CHANNEL in mainline. I imagine it will return the last time the operand had an associated event, so it might work, but wouldn't be very reliable.


    In a BUTTON_EVENT, GET_LAST is not valid for the HOLD only the PUSH and RELEASE - one of the bigger errors found in the DESIGN EXPRESS generated code is the GET_LAST function iterated under several BUTTON_EVENT:HOLD triggers. And the last time I checked, it also is not valid on an array of TIMELINE_EVENTs - which would be great to have implimented!
  • jjamesjjames Just another dude Posts: 2,906
    Great example. Maps are excellent especially when using GET_LAST operations. I'll do that with my strings for any of my RS-232 devices. I usually make a huge array containing all of the strings, and then make several maps likes you just did. On top of that, if you line up your maps good enough, you can do something like this...

    Add touch panel array.
    DEV dv_TP[] = 
    {
    	dvTP1,	// GREAT ROOM TP
    	dvTP2,	// LIVING ROOM TP
    	dvTP3,	// FLORIDA ROOM TP
    	dvTP4,	// MASTER BEDROOM TP
    	dvTP5	// EXERCISE RM TP
    }
    
    Match up your cable boxes, DVDs, CD players, etc.
    DEV dv_CABLE[] =
    {
    	dvCABLE1,   // GREAT ROOM CAB BOX
    	dvCABLE2,   // LIVING ROOM CAB BOX
    	dvCABLE3,   // FLORIDA ROOM CAB BOX
    	dvCABLE4,   // MASTER BEDROOM CAB BOX
    	dvCABLE5,   // EXERCISE RM CAB BOX
    
    }
    
    And construct your button even like so ...
    BUTTON_EVENT[dv_TP,KEYPAD_BTNS]	// 80-90 (0-10)
    {
    	PUSH:
    	{
    		LOCAL_VAR nPANEL
    		LOCAL_VAR nBTN
    		
    		nPANEL = GET_LAST(dv_TP)
    		nBTN = GET_LAST(KEYPAD_BTNS)
    		
    		SWITCH(nCUR_SRC[nPANEL])
    		{
    			CASE SRC_CAB:
    				SEND_COMMAND dv_CABLE[nPANEL],"'SP',CAB_NUMBERS[nBTN]"
    			CASE SRC_CDC:
    				SEND_STRING dv_CDC[nPANEL],"CD_NUMBERS[nBTN],13"
    			CASE SRC_DVD:
    				SEND_STRING dv_DVD[nPANEL],"DVD_NUMBERS[nBTN],13"
    		}
    	}
    }
    
    And there you have it, one event to be controlled by 5 touch panels to control 5 seperate DVD players, cable boxes and CD players.

    I know I posted earlier by not having the nBTN = GET_LAST(WHATEVER), but with mulitple cases like this, I'll use it the "normal" way.

    Regarding not being able to use GET_LAST in a HOLD event, I'll disagree with you on that. I've used them in two programs / projects so far, and they work fine. You do have to declare the variables and GET_LAST in the HOLD part, but it works fine for me.
  • jjamesjjames Just another dude Posts: 2,906
    jjames wrote:
    You do have to declare the variables and GET_LAST in the HOLD part, but it works fine for me.

    Sorry - you don't have to declare variables. Here's a little example I whipped up really quick to show you can use them in holds. Hold the button down for at least 2 seconds and it will light up.
  • HARMAN_icraigieHARMAN_icraigie Technical Trainer II, Harman Professional University Posts: 600
    jjames wrote:
    Regarding not being able to use GET_LAST in a HOLD event, I'll disagree with you on that. I've used them in two programs / projects so far, and they work fine. You do have to declare the variables and GET_LAST in the HOLD part, but it works fine for me.

    Here is an observed example:
    An array of button channels for channel presets where a RELEASE does the recall and a PUSH/HOLD brings up the keypad (or keyboard) for editing the value. If while one touchpanel has a preset button held for editing and another touchpanel has a preset button pushed for a preset recall before the HOLD time of the first has elapsed, the GET_LAST under the first button will now point to the second button index as it was the last active value in that array. I know we are talking about fractions of seconds and the supposed low probabilities of coinciding events - and if you are just dealing with a single room/single interface not an issue - but get more than a few well used interfaces in a system and it will happen.
  • jjamesjjames Just another dude Posts: 2,906
    Okay - thought you were saying GET_LAST will not work AT ALL under the HOLD. I'm wrong again in my assumptions (see above avatar.)

    In your example, wouldn't a multi-demensional GET_LAST variable do the trick for that coupled with an array of touchpanels? Something like this:

    nPANEL = GET_LAST(dv_TP)
    nBTN[nPANEL] = GET_LAST(CHANNEL_PRESETS)
Sign In or Register to comment.