Portrait rotation with touch?

Hi everyone,

I’m coming across a challenge with the correct settings to align the screen orientation with the touch orientation.

I’ve created a simple project in SLS with 240w x 320h – no rotation.

I’ve exported to Arduino IDE.
Double checked the width and height parameters in ui. code.
Set the orientation code to == 0.

The screen is reacting to touch just fine yet the touch portion I believe thinks the screen is in landscape orientation, not portrait.

Could this be a setting within this code?

/*Read the touchpad*/
void my_touchpad_read( lv_indev_drv_t * indev_driver, lv_indev_data_t * data )
{
    **uint16_t touchX = 0, touchY = 0;** 

    //bool touched = false;//tft.getTouch( &touchX, &touchY, 600 );
    bool touched = tft.getTouch( &touchX, &touchY, 600 );

and/or:

/*Change to your screen resolution*/
static const uint16_t screenWidth  = 240;
static const uint16_t screenHeight = 320;

Thank you!

Does tft.getTouch return calibrated values in the range of horizontal and vertical resolution?

If so swapping touch coordinates is very simple. Basically there are 3 things that you can do:

  • swap X and Y
int tmp = touchX;
touchX = touchY;
touchY = tmp;
  • invert X:
touchX = 320-touchX
  • invert Y:
touchY = 240-touchY

You can add a “mouse cursor icon” to better see what’s going on:

  lv_obj_t * cursor_obj = lv_img_create(lv_scr_act()); /*Create an image object for the cursor */
  lv_img_set_src(cursor_obj, LV_SYMBOL_CLOSE);           /*Set the image source*/
  lv_indev_set_cursor(mouse_indev, cursor_obj);             /*Connect the image  object to the driver*/