Inkplate-micropython icon indicating copy to clipboard operation
Inkplate-micropython copied to clipboard

Inkplate6PLUS touchInArea only supports single button

Open ebrynne opened this issue 2 years ago • 1 comments

If there are multiple touchable areas on screen, the touchInArea function cannot be used reliably to detect contact for any of them (only works reliably for a single button).

The touchInArea function blocks in a manner during active touch such that if there are a series of checks for different buttons, only one will be evaluated for each touch (waits within single check until touch is removed).

To demonstrate the behaviour:

from inkplate6_PLUS import Inkplate
from image import *
import time

display = Inkplate(Inkplate.INKPLATE_1BIT)


if __name__ == "__main__":
    display.begin()
    display.tsInit(1)
    display.drawRect(0, 0, 300, 300, display.BLACK)
    display.drawRect(300, 300, 300, 300, display.BLACK)
    display.display()

    while True:
        # touch a square
        if (display.touchInArea(0, 0, 300, 300)):
            print('### FIRST BOX ###', counter)
        if (display.touchInArea(300, 300, 300, 300)):
            print("%%% SECOND BOX %%%")

Expected behaviour over multiple single-finger pressings of each button: a string indicating button press is printed every time. Actual behaviour: Inconsistent printing of touch message regardless of button.

I've handled this locally by adding a method to the Inkplate class to return the touch coordinates and I handle the "which button was this" in my own code (method below). But given that the touchscreen example seems to suggest buttons should be handled individually using this method it's probably worth clarifying the example or modifying the method's behaviour?

Current solution:

    @classmethod
    def activeTouch(cls):
         if cls.tsAvailable():
            fingers = cls.tsGetData()
            print("touchInArea", fingers)
            if fingers > 0:
                cls.touchX = cls._xPos[0]
                cls.touchY = cls._yPos[0]
                print("gotFingers", cls._xPos[0], cls.touchX, cls._yPos[0], cls.touchY)
                return (cls.touchX, cls.touchY)

Side note - sorry for the lack of PRs, just had a kid and I'm not writing code to any reasonable standard for a bit. :)

ebrynne avatar May 26 '23 00:05 ebrynne

Hi @ebrynne

Thanks for letting us know about this issue and we really appreciate your submitted source code which solves the problem. No need to make a PR - we will start working on this for the next iteration of the MicroPython Inkplate library, where you will be credited as a contributor.

We will let you know here when an official release is made.

-Rob

Congratulations, btw :)

rsoric avatar May 29 '23 13:05 rsoric