Home AMX User Forum AMX General Discussion

Code-changeable touchpanel icons?

What is the best approach to take for icons that will change based on button selection? I've gotten to the point in my weather parsing where I want to make the icons change based on the conditions found in the webpage. I have copied the necessary icons into TPD4 and I am assuming that I should load them into the touchpanel file for quick access. Should I create popup pages the size of each icon, and then just do a page flip based on my find_string command? What other ways are there to make this happen, and are these other ways more efficient or reliable? thanks.

Comments

  • Spire_JeffSpire_Jeff Posts: 1,917
    There are two ways that come to mind right now. You could either do a multi-state button tied to a level andjust send a level that corresponds to the appropriate icon, or you could use the ^BMF command to change the icon via code.

    Jeff

    P.S.
    I'm sure there are other ways as well :)
  • TurnipTruckTurnipTruck Posts: 1,485
    I use multi-state buttons with send_levels. I have seen this method used by many other programmers as well. Be sure to set your number of virtual levels if virtual devices are involved.
  • jjamesjjames Posts: 2,908
    ^BMP

    I worked what you asked last night and here is what I'm doing. I've got all of DirecTV's logos loaded in each panel (include R4s), and simply send the ^BMP command. The command is about as simple as the ^TXT.

    ^BMP-<variable text address>,<state>,<image name>

    I've heard of people loading them onto their master and using dynamic imaging - an idea I will entertain this Monday to check on how quick they load.
  • viningvining Posts: 4,368
    It may depend on your icon image names. Sometimes they are numbered 1-3x and other times they have names like "npartlycldy in which case you would need a look up table to match the icon name to an index position to use the send level method. In that case it may be easier to use the ^BMP- command and just change the image by name.

    Of course send level has some advantages since the master tracks levels and won't resend the command if it already has while the ^BMP- command can't really be tracked automatically by the master so depending on your feedback structure you may repeat the command, sending it to the panels 100's or 1,000's of times and subsequently bogging down the system.

    The module I wrote a few years back used the ^BMP- method and at that time my feedback methodology was much different than it is today so I would track everything sent in a duplicate structure or array for comparison & verification.

    Ex.
    if (sRSSsent.icon != sRSS.icon)                             
    	  {
    	  SEND_COMMAND dvTPWeatherArray,"'^BMP-',itoa(nFeedback[WeatherIcon_Btn]),',1 & 2,',sRSS.icon,'.png'"
    	  SEND_COMMAND dvTPWeatherArray,"'!T',nFeedback[VT_icon],sRSS.icon"
    	  sRSSsent.icon = sRSS.icon
    	  }     
    
    You can swee here that I'm sending directly to an array of panels which I wouldn't do today and since I now tend to send feedback only when it changes or a tp comes "on page" I wouldn't use the duplicate "sent" structure or array either.
  • I use multi-state buttons with send_levels. I have seen this method used by many other programmers as well. Be sure to set your number of virtual levels if virtual devices are involved.

    That works - although if it's a multi-state button you would need to use the ^ani command; send_level for a multi-state bargraph button type.
  • vegastechvegastech Posts: 369
    I have started a Select...Active statement for the icon changing, but you guys made me wonder - is there an additional benefit to using a multi-state button with levels, instead of what I'm doing?
    DEFINE_FUNCTION fcnWeatherIcon()
    {
    	SELECT
    	{
    			ACTIVE (FIND_STRING(cCurrCondition, 'Fair',1)):
    			{    
    					SEND_COMMAND dvJVCLT37X898Tp, "'^BMP-31,1,32.png'"
    			}
    	    	       ACTIVE (FIND_STRING(cCurrCondition, 'Fog',1)):
    		       {
    					SEND_COMMAND dvJVCLT37X898Tp, "'^BMP-31,1,19.png'"
    		       }
    	
    	}
    }
    

    Like maybe...once the icon is created, it can be imported into additional panels easily, or something like that?
  • vegastech wrote: »
    Like maybe...once the icon is created, it can be imported into additional panels easily, or something like that?

    Bingo - copy and paste a single button aot a button and a "resources" page. With specific regards to the weather thing, the Yahoo api provides a unique integer value for each condition so if your button states are in the same order the code is pretty easy too.
  • viningvining Posts: 4,368
    vegastech wrote:
    Like maybe...once the icon is created
    You're not actually making these yourself are ya? Usually you just copy them from the weather info source. That way the icon name they specify is what you show and they've already made all the images necassary often including an N/A icon for when they don't even have an image to display for a name they give.

    If you create a constant array of icon names and the just put a for loop in your function that does a find string or == string for each index postion until a match is found and then just return the index number. If no match return 0 and send the N/A.png or similar.

    It's really a matter of preference as to which method you use and each method has advantages and disadvantages depending on how you work your code. With the look up table/send level method you can forget a long select active in lieu of a constant array which you can put into it's own define constant section so that it stays neatly folded out of the way. Then your working code appears shorter and easier to navigate up & down.
  • vegastechvegastech Posts: 369
    No...another programmer friend of mine had a set that he created specifically for yahoo weather and 7" panels. I have created my multi-state button with the states each reflecting a different icon. I added this to my programming, but the icon doesn't appear to be changing...any thoughts?
    
    DEFINE_FUNCTION fcnWeatherCurr()  //Current Conditions Text and Icon
    
    {
    	STACK_VAR nCurrStart
    	STACK_VAR nCurrEnd
    	//STACK_VAR nCodeStart
    	//STACK_VAR nCodeEnd
    	//STACK_VAR nCondCode
    	//STACK_VAR CHAR cCurrCondition[30]
    	IF (FIND_STRING(dvIPWeatherBuff, 'yweather:condition',1))
    		{
    			nCurrStart = (FIND_STRING(dvIPWeatherBuff, 'yweather:condition',1)+26)
    			nCurrEnd   = (FIND_STRING(dvIPWeatherBuff, '"', nCurrStart))
    			nCodeStart = (FIND_STRING(dvIPWeatherBuff, 'yweather:condition',1)+39)
    			nCodeEnd   = (FIND_STRING(dvIPWeatherBuff, '"', nCodeStart))
    			cCurrCondition = MID_STRING(dvIPWeatherBuff, nCurrStart, (nCurrEnd-nCurrStart))
    			nCondCode  = atoi(MID_STRING(dvIPWeatherBuff, nCodeStart, (nCodeEnd-nCodeStart)))
    		}
    	SEND_COMMAND dvJVCLT37X898Tp, "'^TXT-25,0,',cCurrCondition"
    	SEND_COMMAND dvJVCLT37X898Tp, "'^ANI-31,0,',nCondCode,',1'"
    }
    

    It compiles fine. I currently have the local variables commented out so that I can verify their operability in the debugger, and so far, the nCondCode variable is populating with a value of 34, which is "fair". However, my button never leaves the first state. I believe what I have added for the button animation is for it to start at its current state (the zero), and change to the state referenced by the variable.
  • viningvining Posts: 4,368
    I would make the button a multi-state bargraph, range low 1, range high = the number of pics and use send level instead of the ^ani command. The ^ani command requires an address port & code to work on the button. It's just easier w/ levels especially if the image name your weather source is a number or they give you a numeric code. You probably don't need any other levels for your weather mod so create a multi-state bargraph button w/ a level port that coincides w/ channels and use level code 1.
    SEND_LEVEL dvJVCLT37X898Tp,1,nCondCode ; 
    

    FYI, in the code you posted you need ITOA(nCondCode) in the string for it to work.
    SEND_COMMAND dvJVCLT37X898Tp, "'^ANI-31,0,',ITOA(nCondCode),',1'" ;
    
  • vegastechvegastech Posts: 369
    That worked great. Multi-State Bargraph, states equal to number of images, SEND_LEVEL command. Thanks Guys! I'm going to see if I can do this for channel favorites also!
Sign In or Register to comment.