Get_Last Panel # to a variable...

Hi there,

I am hoping to convert a Get_Last panel number to a variable to be used within a Define_Call but cannot seem to get it right..
I am using Get_Last to carry out page flips etc. on the panel that initiates the button press but want to then take
the Get_Last value and store it in a variable to be used within the Define_Call..
So effectively if 10010:1:1 presses the button the page-flipping within the Case 1: below gets carried out on 10010 for all steps within the Call, based on a variable..
BUTTON_EVENT [dvTP_Kitchen,BUTTON.INPUT.CHANNEL]
{
PUSH:
    {
    nDeviceKitchen = GET_LAST(dvTP_Kitchen);
    SWITCH(BUTTON.INPUT.CHANNEL)
	{
	CASE  1:  CALL 'KITCHEN WATCH SKY1'
	CASE  2:  CALL 'KITCHEN WATCH FREEVIEW'
	CASE  3:  CALL 'KITCHEN WATCH LOUNGE BD'
	CASE  4:  CALL 'KITCHEN WATCH ROKU'
	CASE  6:  CALL 'KITCHEN AIRPLAY'
	CASE  7:  CALL 'KITCHEN MUSIC SERVER 1'
	CASE  8:  CALL 'KITCHEN MUSIC SERVER 2'
	CASE  9:  CALL 'KITCHEN RADIO'
	CASE  10: CALL 'KITCHEN WATCH CINEMA BD'
	CASE  11: CALL 'KITCHEN WATCH BEDROOM BD'
	CASE  13: CALL 'KITCHEN WATCH CCTV'
	CASE  20: SEND_COMMAND dvTP_Kitchen[nDeviceKitchen].NUMBER:1:0,"'@PPN-Shutdown_Kitchen'"
	CASE  21: SEND_COMMAND dvTP_Kitchen[nDeviceKitchen].NUMBER:1:0,"'PAGE-Src_Kitchen_1'"
	CASE  22: SEND_COMMAND dvTP_Kitchen[nDeviceKitchen].NUMBER:1:0,"'PAGE-Src_Kitchen_2'"
	CASE  23: SEND_COMMAND dvTP_Kitchen[nDeviceKitchen].NUMBER:1:0,"'PAGE-Src_Kitchen_3'"
	CASE  24: SEND_COMMAND dvTP_Kitchen[nDeviceKitchen].NUMBER:1:0,"'PAGE-Src_Kitchen_4'"
	CASE  98: SEND_COMMAND dvTP_Kitchen[nDeviceKitchen].NUMBER:1:0,"'@PPN-Lighting_Kitchen'"
	CASE  99: SEND_COMMAND dvTP_Kitchen[nDeviceKitchen].NUMBER:1:0,"'@PPN-Shutdown_Kitchen'"
	CASE  100: CALL 'TURN KITCHEN OFF'
	}
    }
}

What I am trying to do is to lock the TP number down to all actions within the Define_Call so that if someone
initiates another button press in the same room, it doesn't get confused..

Is there a way of writing something like...

cTempPanelNo = dvTP_Kitchen[nDeviceKitchen].NUMBER

and then SEND_COMMAND cTempPanelNo:1:0, "'Blah Blah.....'"

I have tried what I am capable of and keep getting dimension mismatch and array errors...

Comments

  • ericmedleyericmedley Senior Member - 3709 Posts Posts: 4,159
    Why not use define_function instead and pass the TP ID in that way?

    Then you can do the switch case there.
  • RaphayoRaphayo Junior Member Posts: 111
    are you assign a button array instead of using [dvtp,button.input.channel]

    the way I will do it is creating a device for the GUI logic. using function to process you page logic (switch,case,send_command
  • JasonSJasonS If I had known it was going to be that kind of party... Posts: 228
    I may not be understanding what you are trying to do, but it seems like this would work:
    SEND_COMMAND dvTP_Kitchen[nDeviceKitchen],"'@PPN-Shutdown_Kitchen'"
    

    As I understand it you are just trying to get the device number from the index that triggered the event? In your define call just specify a DEV type parameter and pass it dvTP_Kitchen[nDeviceKitchen].
  • GregGGregG Just some guy... Posts: 249
    I expanded some on your example and took it toward the direction I would go. This is just to demo some concepts, it's not really how I would have done it if starting from scratch.
    DEFINE_CONSTANT
    
    DEV dvTP_AllPanels[] =
    {
        dvTP_Kitchen1,
        dvTP_Kitchen2,
        dvTP_FamilyRoom,
        dvTP_Bedroom // etc...
    }
    
    KITCHEN_PANEL1 = 1
    KITCHEN_PANEL2 = 2
    FAMILY_PANEL = 3
    BED_PANEL = 4
    
    // Code driven flips for all rooms
    Integer nMenuButtons[] =
    {
    	20,
    	21,
    	22,
    	23,
    	24,
    	98,
    	99
    }
    
    Char cMenuFlips[][][80] =
    {
    	{	//	KITCHEN_PANEL1
    		{"'@PPN-Shutdown_Kitchen'"},
    		{"'PAGE-Src_Kitchen_1'"},
    		{"'PAGE-Src_Kitchen_2'"},
    		{"'PAGE-Src_Kitchen_3'"},
    		{"'PAGE-Src_Kitchen_4'"},
    		{"'@PPN-Lighting_Kitchen'"},
    		{"'@PPN-Shutdown_Kitchen'"}
    	},
    	{	//	KITCHEN_PANEL2
    		{"'@PPN-Shutdown_Kitchen'"},
    		{"'PAGE-Src_Kitchen_1'"},
    		{"'PAGE-Src_Kitchen_2'"},
    		{"'PAGE-Src_Kitchen_3'"},
    		{"'PAGE-Src_Kitchen_4'"},
    		{"'@PPN-Lighting_Kitchen'"},
    		{"'@PPN-Shutdown_Kitchen'"}
    	},
    	{	//	FAMILY_PANEL
    		{"'@PPN-Shutdown_Family'"},
    		{"'PAGE-Src_Family_1'"},
    		{"'PAGE-Src_Family_2'"},
    		{"'PAGE-Src_Family_3'"},
    		{"'PAGE-Src_Family_4'"},
    		{"'@PPN-Lighting_Family'"},
    		{"'@PPN-Shutdown_Family'"}
    	},
    	{	//	BED_PANEL
    		{"'@PPN-Shutdown_Bed'"},
    		{"'PAGE-Src_Bed_1'"},
    		{"'PAGE-Src_Bed_2'"},
    		{"'PAGE-Src_Bed_3'"},
    		{"'PAGE-Src_Bed_4'"},
    		{"'@PPN-Lighting_Bed'"},
    		{"'@PPN-Shutdown_Bed'"}
    	}
    }
    
    DEFINE_VARIABLE
    Integer nCurrentPanelSource[4]
    
    // I'd break out the define calls like this...
    // (I'd also use functions instead, but it doesn't look much different)
    DEFINE_CALL 'WATCH' (Integer nWhichPanel, Char cFunction[])
    {
    	Switch(nWhichPanel)
    	{
    		Case KITCHEN_PANEL1:
    		Case KITCHEN_PANEL2: // for panels in the same area, stack the cases
    		{
    			Switch cFunction
    			{
    				Case 'SKY1':
    				{
    					//Init Sky1 in the kitchen
    				}
    				// etc...
    			}
    		}
    		Case FAMILY_PANEL:
    		{
    			Switch cFunction
    			{
    				Case 'SKY1':
    				{
    					//Init Sky1 in the family room
    				}
    				// etc...
    			}
    		}
    		Case BED_PANEL:
    		{
    				// etc...
    		}
    	}
    }
    // Similar to above
    DEFINE_CALL 'LISTEN' (Integer nWhichPanel, Char cFunction[])
    {}
    DEFINE_CALL 'ROOM OFF' (Integer nWhichPanel)
    {}
    
    
    DEFINE_EVENT
    
    // Panel navigation (created by moving the button numbers into the integer array above)
    BUTTON_EVENT[dvTP_AllPanels,nMenuButtons]
    {
    	Push:
    	{
    	Stack_Var Integer nRoom
    	Stack_Var Integer nMenuBtn
    		nRoom = Get_Last(dvTP_AllPanels)
    		nMenuBtn = Get_Last(nMenuButtons)
    		Send_Command dvTP_AllPanels[nRoom],"cMenuFlips[nRoom][nMenuBtn]"
    	}
    }
    
    // Source select buttons
    // (I would define an integer array of the specific buttons for this also)
    BUTTON_EVENT [dvTP_AllPanels,BUTTON.INPUT.CHANNEL]
    {
    	PUSH:
    	{
    	Stack_Var Integer nRoom
    		nRoom = GET_LAST(dvTP_AllPanels)
    		
    		// Can use something like this for source tracking
    		nCurrentPanelSource[nRoom] = BUTTON.INPUT.CHANNEL
    		
    		SWITCH(BUTTON.INPUT.CHANNEL)
    		{
    			CASE  1:  CALL 'WATCH' (nRoom, 'SKY1')
    			CASE  2:  CALL 'WATCH' (nRoom, 'FREEVIEW')
    			CASE  3:  CALL 'WATCH' (nRoom, 'LOUNGE BD')
    			CASE  4:  CALL 'WATCH' (nRoom, 'ROKU')
    			CASE  6:  CALL 'LISTEN' (nRoom, 'AIRPLAY')
    			CASE  7:  CALL 'LISTEN' (nRoom, 'MUSIC SERVER 1')
    			CASE  8:  CALL 'LISTEN' (nRoom, 'MUSIC SERVER 2')
    			CASE  9:  CALL 'LISTEN' (nRoom, 'RADIO')
    			CASE  10: CALL 'WATCH' (nRoom, 'CINEMA BD')
    			CASE  11: CALL 'WATCH' (nRoom, 'BEDROOM BD')
    			CASE  13: CALL 'WATCH' (nRoom, 'CCTV')
    			CASE  100: CALL 'ROOM OFF' (nRoom)
    		}
    	}
    }
    
  • a_riot42a_riot42 AMX Wizard Posts: 1,619
    You're usually better off not using magic numbers like device.input.channel and using indexes into an array. That way the array contents can change depending on your needs, but the index is always the same so your code doesn't change if your channels do.
    Paul
  • mkleynhansmkleynhans Junior Member Posts: 76
    Thanks guys, as always, amazing response and advice. Greg, huge thanks to you for going to that effort mate. Really appreciated. Unfortunately have been on the site desperately trying to implement what I had posted above.
    Its working well - BUT - I am waiting for two panels that have chosen the same zone to have a problem eventually when two calls are called and the Get_Last panel number changes half way through the call.
    This is the reason I was trying to convert my Dev no to a variable and then keep sending the different steps of the get call to the Panel number that was converted at the beginning of the call so to speak.

    Greg, I will go through this in detail to see if I can convert my code... The include for all of these panels is 5k lines long so it could be a nightmare but I desperately want to do this the right way and get better at doing this =)
  • GregGGregG Just some guy... Posts: 249
    To get rid of the button.input.channel in the last bit of my example, it ends up more like this:
    DEFINE_CONSTANT
    Integer nSourceSelectButtons[] =
    {
    	100,	//	OFF  - Made this the first item in the array, you'll see why below
    	1,	// 'SKY1'
    	2,	// 'FREEVIEW'
    	3,	// 'LOUNGE BD'
    	4,	// 'ROKU'
    	6,	// 'AIRPLAY'
    	7,	// 'MUSIC SERVER 1'
    	8,	// 'MUSIC SERVER 2'
    	9,	// 'RADIO'
    	10,	// 'CINEMA BD'
    	11,	// 'BEDROOM BD'
    	13	// 'CCTV'
    }
    
    DEFINE_EVENT
    BUTTON_EVENT [dvTP_AllPanels,nSourceSelectButtons]
    {
    	PUSH:
    	{
    	Stack_Var Integer nRoom
    		nRoom = GET_LAST(dvTP_AllPanels)
    
    		nCurrentPanelSource[nRoom] = GET_LAST(nSourceSelectButtons)-1
                                                     // NOTE, I subtracted 1 here
    
    		// The cases are now in sequence based on the array order, not the button numbers
    		SWITCH(nCurrentPanelSource[nRoom])
    		{
    			CASE  0:  CALL 'ROOM OFF' (nRoom)  // Since I subtracted 1 above, Off is now 0
    			CASE  1:  CALL 'WATCH' (nRoom, 'SKY1')
    			CASE  2:  CALL 'WATCH' (nRoom, 'FREEVIEW')
    			CASE  3:  CALL 'WATCH' (nRoom, 'LOUNGE BD')
    			CASE  4:  CALL 'WATCH' (nRoom, 'ROKU')
    			CASE  5:  CALL 'LISTEN' (nRoom, 'AIRPLAY')
    			CASE  6:  CALL 'LISTEN' (nRoom, 'MUSIC SERVER 1')
    			CASE  7:  CALL 'LISTEN' (nRoom, 'MUSIC SERVER 2')
    			CASE  8:  CALL 'LISTEN' (nRoom, 'RADIO')
    			CASE  9:  CALL 'WATCH' (nRoom, 'CINEMA BD')
    			CASE  10: CALL 'WATCH' (nRoom, 'BEDROOM BD')
    			CASE  11: CALL 'WATCH' (nRoom, 'CCTV')
    		}
    	}
    }
    
    A trick I sometimes use is putting the off button first and subtracting 1 from get_last() so that off's value is 0.
    You can use that like a usage flag... any value >0 means we are "in use".
Sign In or Register to comment.