Home AMX User Forum AMX Technical Discussion

ON SITE - Sending variable value to buttons - Alignment issue

Hi Guys,

I am parsing a Denon tuner for station info and have written a bit of code that saves the current station
as a preset on a button and pops the station name on the button label.

The parsed value for a Denon station short name is 8 chars long but some stations have less characters
in the name such as 'XFM'.
What I am finding is that the labels on the buttons look a bit wierd as the shorter character stations are
off to the left. Is there anything that I can do about adjusting the storage variable length based on the
actual size of the preset name? (Hoping that this would then centre the channel name in the middle of
the button...)

The variable for preset 1 starts off as NON_VOLATILE CHAR cDabPreset1[]='Preset 1'

On the present button holdpress, I giving cDabPreset1 the same value as DAB_STATION_NAME which
starts off as CHAR DAB_STATION_NAME[8]. I have tried changing the dab station name variable to
CHAR DAB_STATION_NAME[] this is the same and removing brackets brings up warnings that I am trying
to convert string to char...

Are there any ways to adjust the variable length or at least adjust the value being sent?
(Sorry reading this it sound pretty confusing...)

Comments

  • champchamp Posts: 261
    Just set the text justification as centered in the TP4 file.
  • ericmedleyericmedley Posts: 4,177
    Firstly, you will need to leave CHAR DAB_STATION_NAME[8] as having a size of 8.

    If you are centering the text as suggested but are still seeing alignment issues it might be that your Staion ID data has some other non-Alpha chars in it like spaces or whatnot. You can see this in debug by looking at the variable value while you have the shorter name in.

    So what you may have for example is really

    [SPACE][SPACE]XFM[SPACE][SPACE][SPACE]

    so the button is dutifully centering this text but what you see is janky.

    If its something like this you just need to search through your return string and remove what you don't need.
  • yuriyuri Posts: 861
    if setting the justication to center (like champ said) doesn't work for you you could try to determine to absolute justification by checking the length of the station name (3 in your example), and then changing to justification using a SEND_COMMAND?
  • You could just add this into your code ...
    INTEGER nStringSize
    INTEGER nLoop
    
    nStringSize = LENGTH_STRING(cReply)
    					
    FOR(nLoop = nStringSize; nLoop > 0; nLoop --)
    {
         IF(cReply[nLoop] != ' ')
         {
              cReply = LEFT_STRING(cReply,nLoop)
              BREAK
         }
    }
    

    Now cReply is the same string minus the whitespace.

    Simon
  • Thanks guys, will use the suggestions..
  • What is it with radio tuners and me?? I am busy doing an Arcam T32 tuner via RS232 and the suggested code refuses to remove the "Whitespace"..

    Receipt of the Station Name is done with...
    Start Zone DABStation Nil String Length
    $21, $01, $18, $00, $10

    Data inbound within Notifications Tab
    Line 729 (12:43:14):: String From [5001:6:1]-[!$01$18$00$10Capital <9Spaces> $0D]
    (I have added the <9Spaces> part as the forum removes the spaces...)

    My Data Event Parse Code
     DATA_EVENT[dv_Arcam_Dab] //Station Name
    {
    STRING:
        {
        cDevDaTA = "dv_Arcam_Dab, DATA.TEXT"
        WHILE(FIND_STRING(cDevDaTA,"$0D",1)) 
    	{
    	cDevBuffer=REMOVE_STRING(cDevDaTA,"$0D",1)
    	IF (FIND_STRING(cDevBuffer,"$21,$01,$18",1))
    	    {
    	    STACK_VAR INTEGER nStringSize 
    	    STACK_VAR INTEGER nLoop 
    	    cDabSNPos 		=	FIND_STRING (cDevBuffer,"$21,$01,$18",1)
    	    cDabSN_GSL 		= 	cDabSNPos+4
    	    cDabSN_STR_H 	=	MID_STRING (cDevBuffer,cDabSN_GSL,1)
    	    cDabSN_STR_I 	= 	HEXTOI(cDabSN_STR_H)
    	    cDabSN_STR_LNGTH 	= 	cDabSN_STR_I-5
    	    cDabSN_TXT_POS	=	cDabSNPos+5
    	    cDabSN		=	MID_STRING(cDevBuffer,cDabSN_TXT_POS,cDabSN_STR_LNGTH)
    	    CALL 'TIDY UP CHARS'
    	    }
          }
    }
    

    My Call based on previous recommendation to remove whitespace..
    DEFINE_CALL 'TIDY UP CHARS'
    {
    STACK_VAR INTEGER nStringSize 
    STACK_VAR INTEGER nLoop  
    nStringSize = LENGTH_STRING(cDabSN)
    FOR (nLoop  =  nStringSize; nLoop > 0; nLoop --)
        {
        IF ( cDabSN[nLoop] != "$20")
    	{
    	cDabSN1 = LEFT_STRING(cDabSN,nLoop)
    	BREAK
    	}
        }
    SEND_COMMAND dvTP_TUNER_Study, "'^TXT-62,0,',cDabSN1"
    }
    

    But still my cDabSN and cDabSN1 are still both 17 chars long and the full value gets sent to
    my current programme area and sits off to the left when a short station name is true.........

    In the FOR loop above, I have also tried IF ( cDabSN[nLoop] != ' ') but that makes no difference.

    When I look at the values for cDabSN and cDabSN1 within my Debug they show as...
    43,61,70,69,74,61,6C,20,20,20,20,20,20,20,20,20,D
    Is the D on the end the culprit?


    Please HEEELP =)
  • sling100sling100 Posts: 123
    You are correct - the 'D' is causing the issue there. The loop only runs once as it finds a char that isn't $20 straight away.

    Is the 'D' simply a checksum character? Remove it first then run the loop.

    Simon
  • the8thstthe8thst Posts: 470
    You can easily fix what you have by adding:
    set_length_string(cDevBuffer,length_string(cDevBuffer) - 1)
    
    Directly after the line:
    cDevBuffer=REMOVE_STRING(cDevDaTA,"$0D",1)
    

    There are many other ways to skin this cat, but that is the quickest way I can think of to make the bulk of your existing code work.
  • Guys, as always, Thank You!! The set_length_string sorted it =) All sorted.
Sign In or Register to comment.