Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clear ongoing taps when going to sleep #2108

Merged
merged 4 commits into from
Oct 27, 2024
Merged

Conversation

mark9064
Copy link
Contributor

Currently if the touch panel is pressed when DisplayApp goes to sleep, the finger up event gets dropped. This causes LVGL to think the finger is never released from the touch panel, so it prevents the device from sleeping. This PR clears the tapped state when going to sleep so the internal LVGL state remains consistent with the real touch panel state.

Fixes part of #1790 #2012 (there may be other issues contributing to these, but this is probably part of it)

Copy link

github-actions bot commented Aug 23, 2024

Build size and comparison to main:

Section Size Difference
text 374512B -48B
data 948B 0B
bss 63488B 0B

@mark9064
Copy link
Contributor Author

Also fixes #1992

@mark9064
Copy link
Contributor Author

Actually the same problem exists with TouchHandler. Should we clear the tap state there too? Or do we define calling its methods as UB when the touch panel is sleeping (as when it's sleeping, it's not possible to know whether the screen is touched or not)

TouchHandler doesn't cause any bugs, but it could certainly in the future. If we choose to define it as UB then we should guard

// DisplayApp.cpp
  if (touchHandler.IsTouching()) {
    currentScreen->OnTouchEvent(touchHandler.GetX(), touchHandler.GetY());
  }

with a state == Running check

@minacode
Copy link
Contributor

I would avoid any UB.

@mark9064
Copy link
Contributor Author

I mean defining calling the methods as UB by documentation i.e the documentation for the function IsTouching() saying "if the device is sleeping, the value returned is undefined". There is no UB C++ spec wise

@minacode
Copy link
Contributor

minacode commented Aug 29, 2024

I think the perfect type of that function would not be bool but std::optional<bool>. The value std::nullopt would represent the case where no measurement can be made (screen asleep) and the bool would be the measurement, if possible (screen awake).

Otherwise return always false if the screen is asleep. Because no screen, no touch.

@mark9064
Copy link
Contributor Author

Excellent idea, optional makes perfect sense here semantically. I will try it out

@JF002
Copy link
Collaborator

JF002 commented Sep 14, 2024

Actually the same problem exists with TouchHandler. Should we clear the tap state there too? Or do we define calling its methods as UB when the touch panel is sleeping (as when it's sleeping, it's not possible to know whether the screen is touched or not)

I think we could just clear the tap in TouchHandler as soon as the touch panel is sleeping as well, since I don't think we want to handle touch while the device is sleeping.

@mark9064
Copy link
Contributor Author

So this has turned out to be a bit trickier than I thought. TLDR the touch panel still delivers events when sleeping, so trying to pretend it doesn't with TouchController having a null state is incompatible with double tap wake / tap wake. So instead I've opted to unify the touch processing into something a little more sensible, so the TouchController always has up to date touch state even when the device is sleeping.

So the original problem is addressed with DisplayApp not receiving or processing any touch events while sleeping, and clearing touch state on sleep entry

@NeroBurner NeroBurner added this to the 1.15.0 milestone Sep 28, 2024
@NeroBurner NeroBurner added the bug Something isn't working label Sep 28, 2024
NeroBurner added a commit to InfiniTimeOrg/InfiniSim that referenced this pull request Sep 28, 2024
Add function `LittleVgl::ClearTouchState` introduced with
InfiniTimeOrg/InfiniTime#2108

As it is a new function the change is compatible with current
v1.14.0-dev state (`main` branch of InfiniTime)
Copy link
Contributor

@NeroBurner NeroBurner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changes look sound, not tested on PineTime

@mark9064
Copy link
Contributor Author

Cleaned up the OnTouchEvent method as it was just an alias for PushMessage after Unify touch handling, no other changes

Copy link
Collaborator

@JF002 JF002 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!
Tested on my pinetime, works fine!

@JF002 JF002 merged commit 57b6db8 into InfiniTimeOrg:main Oct 27, 2024
6 of 7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants