Home AMX User Forum AMXForums Archive Threads AMX Applications and Solutions

Manipulating user input in Touch Panels

Hi guys, I'm trying to learn the ropes in AMX programming, so I hope you can answer my questions.

I wanted to create a calculator application in the touch panel as a warm up to Netlinx, but i'm having trouble displaying the button presses. What I wanted was for every corresponding button push event, i store that value to an array.

What's next? How do display that result? Is there some sort of "Button1.Text = result" command in Netlinx?

Thanks.

Comments

  • glr-ftiglr-fti Posts: 286
    BUTTON.INPUT.CHANNEL will give you the last button pressed.


    Button Events
    Button events include pushes, releases and holds. These events are associated with a push or release on a particular device-channel.

    Example:

    BUTTON_EVENT[DEVICE,CHANNEL] or

    BUTTON_EVENT[(DEVCHAN[ ])]

    {

    PUSH:

    {

    // PUSH event handler

    }

    RELEASE:

    {

    // RELEASE event handler

    }

    HOLD[TIME]: or HOLD[TIME, REPEAT]:

    {

    // HOLD event handler

    }

    }

    A HOLD event handler specifies the actions that should be performed when a button is pressed and held for a minimum length of time indicated by the TIME parameter (TIME is specified in 0.1 second increments).

    The REPEAT keyword is used to specify that the event notification should be repeated in TIME increments as long as the button is held.

    The BUTTON object is available to the button event handler as a local variable. The following table lists the information contained in Button Objects.

    Property Name
    Type
    Description

    Button.Input
    DEVCHAN
    Device + Channel

    Button.Input.Channel
    INTEGER
    Channel

    Button.Input.Device
    DEV
    Device

    Button.Input.Device.Number
    INTEGER
    Device number

    Button.Input.Device.Port
    INTEGER
    Device port

    Button.Input.Device.System
    INTEGER
    System number

    Button.Holdtime
    LONG
    Current hold time in .10 second increments.

    Note: Button.Holdtime returns are in 1ms increments.

    Button.SourceDev
    DEV
    Source device of button event

    Button.SourceDev.Number
    INTEGER
    Source device number

    Button.SourceDev.Port
    INTEGER
    Source device port

    Button.SourceDev.System
    INTEGER
    Source device system.


    If the event handler is specified using an array for DEV, CHANNEL, or a DEVCHAN array, GET_LAST can determine which index in the array caused the event to run.
  • jweatherjweather Posts: 320
    To change the text of a TP button, send a command to the touchpanel. There are lots to choose from on modern panels with various advantages and disadvantages. Here's one example:

    SEND_COMMAND dvTP, '^TXT-42,0,Hello World!'

    the "42" is the address code of a button to update (must be set in TP4). The 0 is for state number, and is usually left at 0. The text to show is everything after the second comma.
  • Thanks, I finally got it working, but it seems that the button text can only handle up to 6 digits, after then it goes into exponential annotation (ex. 1.23456E+06).

    I was doing something like this for my calculator app.

    DEFINE_VARIABLE
    float num = 0

    DEFINE_EVENT
    button_event [TP,3] // button 1 is pressed
    {
    PUSH:
    {
    num = (num * 10) + 1
    SEND_COMMAND TP, "'^TXT-1,1,',ftoa(num)"
    }
    }

    button_event [TP,4] // button 2 is pressed
    {
    PUSH:
    {
    num = (num * 10) + 2
    SEND_COMMAND TP, "'^TXT-1,1,',ftoa(num)"
    }
    }
    .
    .
    .

    If there are other ways of displaying the text, that would be fine, because I may be doing a "Search Movies" query application for a MAX Server in the future, so any suggestions would be appreciated.
  • glr-ftiglr-fti Posts: 286
    Looks like I misunderstood your question. I'll try again. You need to parse the data event that is triggered by the button event. As an example here is a snippet that is used for a security keypad where the user code is entered. You could do something similar for your calculator to display. Instead of a page flip send your text.
    DATA_EVENT[dvTP]							// KEYPAD ENTRY
    {
        STRING:
        {
            nTP_NUM=GET_LAST(dvTP)							// WHICH TP IS THIS?
    	SELECT
    	{
    	    ACTIVE(FIND_STRING(DATA.TEXT,'KEYP-',1)): 			// LOOK FOR MESSAGE FROM 
    	    {	
    		sJUNK=REMOVE_STRING(DATA.TEXT,'KEYP-',1)		// REMOVE PREFIX JUNK
    		sSec_Code=DATA.TEXT 					// SAVE KEYPAD TEXT	
    		SWITCH(sSec_Code)					// Security Code
    		{
    		    CASE 'xxxx':						
    		    {
    			SEND_COMMAND dvTP[nTP_NUM],"'PAGE-Security'"
    			WAIT 300
    			{
    			   SEND_COMMAND dvTP[nTP_NUM],"'PAGE-Main Navigation'" 
    			}
    		    }
    		}
    	    }
    	}
        }
    }
    
  • Finally got it all sorted out except one last bit. The button text keeps truncating the results to a max of 6 numbers. Yes, the computations are correct, but I can't see the complete digits because when the digits pass the 6th, it goes like 1.23456E+07.

    What I do is convert them all to Float, calculate, then convert back to ASCII so that I can use it in send_command. My hunch is that the part when I convert the values to Float, the calculation automatically does that. Any other options?
  • Maybe try changing the FLOAT to a DOUBLE?

    FLOAT
    An intrinsic data type representing a 32-bit signed floating point value.

    DOUBLE
    An intrinsic data type representing a 64-bit (double precision) signed floating point value.


    Just a thought
Sign In or Register to comment.