-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Add new button handler that can handle long press and double click #480
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
Conversation
|
I just commented on another PR that a long press function would be useful, and now I see this. You've been busy Riksu9000! |
|
Tested, works well, I think it could do with a settings page to choose what single/long/double press does as different people probably want different things. I think the current single and long press behaviour are ideal for me, but if the double press could be configured to launch a specific app (music, navigation, timer...) that would be amazing. |
Thanks for testing. The double press launching notifications is mainly just to demonstrate the ability to detect the event. Having it configurable might be a good idea, but that should be a separate PR after this. There's also #487. We need to choose which shortcut should be used for favorite apps, or make them work together somehow. |
|
Works perfectly. Really makes browsing menus much more pleasant! Together with #586 the wake-up on press is instant 11 ms. |
|
Just noticed just a small issue. I have display timeout set to 5 seconds. When I press and hold button in different times like 2-3 seconds before screen sleep timeout, then the screen dims a bit (this is a feature few seconds before going to sleep) and then it goes to the About screen. |
|
Good find. Fixed by calling ReloadIdleTimer on press and release. It can still dim if you hold the button for more than three seconds, but I think that's acceptable as nothing happens after two seconds and this avoids calling ReloadIdleTimer continuously. I also noticed that the way SystemTask processed the button events was a bit weird, so I moved everything to messages, which is futureproof in case we want SystemTask to process the button events in some way. |
|
Thanks, tested and works fine. |
|
The last improvement fd39ba3 brings a bug. The previous code worked fine without this bug. When the watch is turned on and brightness is max, then I press button to go to sleep. But during the fading down (or maybe a while after screen is off) I press the button again. The watch freezes and resets. |
|
When I moved the functions to messages, I left out a check for |
I think that happens regardless of this PR. There is for example this code that stops execution for half a second each time the screen is turned off. |
|
Why is this even doing this? This feels...wrong. does nrf_delay even yield to RreeRTOS? That feels...bad. |
Yeah I doubt that's necessary. Someone should look into that.. |
|
This PR is working perfectly fine and I would add it to the next release pleaase, 'cause I got used to it :) |
|
Just an idea when I see #708 App chooser made by @coxtor. Since we have a settings page to choose Favorite app, and this button handler will sooner or later also need some App chooser for doubleclick and looong buton press - wouldn't be the best solution to create a "shared app/settings chooser" which could be used by other apps? That way we could use single code/dialog to set:
It might not display only apps but also settings. Now I'm thinking - wouldn't be possible to use current menu for apps and settings? It might work the same way, but if called with some flag, it might display some text in the top bar like "Choose a app" and when selected - it will return to previous app instead of running the app. The same may apply for Settings dialog. This might deduplicate lot of things. What do you think? |
|
Riksu, thanks a ton for keeping these up to date with develop. Any reason for merging instead of rebasing however? We get a lot of "merge" commits this way? Really more of a curiosity. Awesome work as always! |
Well that's what GitHub and others often tell to do, so that's just what I've been doing. I can take a look at rebasing if it's important. I believe it could also just be squashed when merging as well. Any reason not to do that? I don't think there's anything too important in the history that would be lost. |
|
Its definitely a preference argument. pesronally I don't like squashing most merges as you lose design/development intention. Which is sometimes crucial for bug hunting. As for re-basing vs merging...valid reason is valid both work fine and have the same end result! The merge commits can also be squashed or similar, just more work for the merging party where a re-base its done already. At the end of the day its really just a cleanliness thing that's up to @JF002 to tell us what we want the repository's "norm" to be. Thanks for the response :) |
|
I'm sorry, I'm a bit late to the party!
This is not something I had the opportunity to think about so far, but that's an interesting topic :)
@Riksu9000 @geekbozu That's probably something we can talk in another 'discussion' issue, so we can try to specify how we want to merge features and manage the history :) Now, regarding this PR : This is a really nice feature, thanks, @Riksu9000 ! However, I noticed that this PR introduces a new task to handle the button. As a task costs a bit of CPU time and RAM (320 bytes of stack in this case), are we really sure we need it? It does make the code tidy and easy to read, but I'm wondering if we shouldn't try to consider another solution that would avoid this overhead, mostly in RAM space. I haven't dig that much into the code, but it might be possible to implement the class ButtonHandler as a "simple" class (with no task) that would be called directly from the IRQ handler). It'll probably need an additional timer (HW or FreeRTOS timer) to implement timeouts for the double push. This implementation would be a bit more complex, but knowing that we are very tight in memory, I think that would be a good idea to at least consider that option. What's your opinion? Is there something I'm missing that makes the new task necessary? |
|
A timer would be needed for the two levels of long press. I was concerned that it would get too complicated without a task, but with a state machine it might be manageable. It would need to respond to press, release and timer events. I think I'll just start from scratch and create a new PR so we can compare both approaches. |
|
Hi @Riksu9000 , i think that this pull can be either closed or be put as draft since the new is now on 1.7.0. |
It's likely that the new one will be merged instead of this, but both of these PRs are functional, and as one is merged, the other one will be closed. |
|
I'm closing this one as we've just merged #782. |
VID_20210711_115406.mp4
Basic implementation for detecting different button events.
I'm unsure what to do with the recovery source files list. I added the new files there. Is this fine?
There is a new issue in SystemInfo, because now there are eight tasks, and only seven can fit on screen.
EDIT: We could make waking up by pressing the button faster by uncommenting the piece of code, but then we can't make the watch handle different events while sleeping. For example if we wanted to enable flashlight by long pressing the button while the watch is sleeping, we would need to remove that code. Then again raise to wake would make this inconsistent.
EDIT2: I enabled the faster wakeup code. I also thought about making this task use a message queue, but that doesn't seem necessary, as the task needs to read the button state anyway and can't rely on messages only.
EDIT3: This probably fixes the issue with the screen sometimes turning on and off after a single button push.