Skip to content

Please add rotation to Touchscreen #7

Closed
@RichardA1

Description

@RichardA1

I am not sure how it could be added to this library, but I created the following code to recalculate the touch coordinates based on the orientation of the screen set by board.DISPLAY.rotation. This fixes an issue with how the hotspots are setup from the Button() function used in Displayio.

### Function for recalculating .touch_point based on Display rotation
def touch_rotate():
    touchData = ts.touch_point
    if touchData:
        if display.rotation == 0:
            return touchData
        elif display.rotation == 90:
            touchX = adafruit_touchscreen.map_range(touchData[0], 0, ts._size[0], ts._size[0], 0)
            return (touchData[1],int(touchX) )
        elif display.rotation == 180:
            touchX = adafruit_touchscreen.map_range(touchData[0], 0, ts._size[0], ts._size[0], 0)
            touchY = adafruit_touchscreen.map_range(touchData[1], 0, ts._size[1], ts._size[1], 0)
            return (int(touchX), int(touchY))
        elif display.rotation == 270:
            touchY = adafruit_touchscreen.map_range(touchData[1], 0, ts._size[1], ts._size[1], 0)
            return (int(touchY),touchData[0] )

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions