Menu

Box touch sensing for use on a GLCD menu

2023-09-23
2023-09-25
  • Steve Scott

    Steve Scott - 2023-09-23

    I have looked at the demo programs and have success with a ILI9341 with printing to the screen and have looked at CreateButton but would like to understand how you can actually select a box by a touch input.
    Do you just scan for a box that is close? Is there a better way?
    A table has been suggested but 1st I need to know some of the philosophy of how you sense a graphic by getting a touch input.
    It will eventually be learning how to change an empty box to a filled one if 'selected' by touch.
    Any pointers?
    Appreciation in advance.

     
  • Kato

    Kato - 2023-09-25

    The philosophy. Read the XY position from the XPT. Then, compare to range in the table.

    Something like.. this is psuedo code.. it will need fixing.

    #define ELEMENTSINTABLEROW 5
    
    //I cannot remember the returned variable from reading the XPT, call it...
    returnedXPOS = xptreturnedvalue()
    returnedYPOS = xptreturnedvalue() 
    
    // read the number of table elements and divide to get the number of rows of data.
    readtable TableData,0, maxthingstocheck/ELEMENTSINTABLEROW
    
    For thingstocheck = 1 to maxthingstocheck
        readtable TableData, ( thingstocheck * ELEMENTSINTABLEROW), MINXPOSRANGE
        readtable TableData, ( thingstocheck * ELEMENTSINTABLEROW)+1, MAXXPOSRANGE
        readtable TableData, ( thingstocheck * ELEMENTSINTABLEROW)+2, MINYPOSRANGE
        readtable TableData, ( thingstocheck * ELEMENTSINTABLEROW)+3, MAXXPOSRANGE
        readtable TableData, ( thingstocheck * ELEMENTSINTABLEROW)+4, VALUEOFTHING
    
          valueofitem = 0
        if XPOS > MINXPOSRANGE and XPOS < MAXXPOSRANGE and YPOS > MINYPOSRANGE and YPOS < MAXXPOSRANGE Then 
            valueofitem=VALUEOFTHING 
           endif
        next
    
    // table is a grid of 10x10 pixels
    table TableData
        0,0,10,10,1
        10,10,10,10,2
        20,20,10,10,3
        etc
    
    
    end table
    

    Good luck

     
  • Kato

    Kato - 2023-09-25

    Here is something that compiles.

    So, this is meant to return a value when you select within the described logical boxes. What is displayed on the GLCD is purely a picture... the XPT is doing all the hard work.

    Notes: maxthingstocheck return value may need to be adapted. See the code below.

    #chip 18f67k40
    #option Explicit
    // Something like.. this is psuedo code.. it will need fixing.
    #define ELEMENTSINTABLEROW 5
    
    
    dim maxthingstocheck, thingstocheck, minxposrange, minyposrange, maxxposrange, maxyposrange, valueofthing, valueofitem
    //I cannot remember the returned variable from reading the XPT, call it...
    dim returnedXPOS, returnedYPOS
    returnedXPOS = 5 //! xptreturnedvalue()
    returnedYPOS = 5 //! xptreturnedvalue() 
    
    // read the number of table elements and divide to get the number of rows of data.
    readtable TableData,0, maxthingstocheck
    
    //! need to check what maxthingstocheck returns, this may required to be
    // maxthingstocheck = ( maxthingstocheck - 1 ) / ELEMENTSINTABLEROW 
    maxthingstocheck = maxthingstocheck / ELEMENTSINTABLEROW
    
    For thingstocheck = 1 to maxthingstocheck
        readtable TableData, ( thingstocheck * ELEMENTSINTABLEROW), minxposrange
        readtable TableData, ( thingstocheck * ELEMENTSINTABLEROW)+1, maxxposrange
        readtable TableData, ( thingstocheck * ELEMENTSINTABLEROW)+2, minyposrange
        readtable TableData, ( thingstocheck * ELEMENTSINTABLEROW)+3, maxxposrange
        readtable TableData, ( thingstocheck * ELEMENTSINTABLEROW)+4, valueofthing
    
          valueofitem = 0
        if returnedXPOS > minxposrange and returnedXPOS < maxxposrange and returnedYPOS > returnedYPOS and returnedYPOS < maxxposrange Then 
            valueofitem=valueofthing 
           end if
        next
    
    // table is a grid of 10x10 pixels
    table TableData
        0,0,10,10,1
        10,10,10,10,2
        20,20,10,10,3
    end table
    
     
  • Steve Scott

    Steve Scott - 2023-09-25

    Kato-
    Thanks for the philosophy lesson - makes a bit more sense to me now.
    I will try this and once it works will start to change things to get a better understanding of this.
    I appreciate the assist!

     

Log in to post a comment.