-
Notifications
You must be signed in to change notification settings - Fork 434
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
M5Button now also on 3-button M5Stack device. Draws button graphics. Events – tap, dbltap, longpress, repeat – for buttons. Extensive documentation and examples. #232
base: master
Are you sure you want to change the base?
Conversation
Thx is your PR, these new features look very useful |
I'd be happy to hear in more detail what your thoughts are. Possibly I can adjust things to your liking. Feel free to talk here or email me: rop -at~ gonggri.jp (I will remove address here after you read it.) (( Polyphonic sound, with envelope, multiple waveforms, etc. for Core2 is coming after weekend: M5Sound.... )) |
d2b1552
to
cb08702
Compare
EDIT : Solution at bottom Fantastic library @ropg - quick question: My project has multiple pages. I need different buttons on each page, but since I cannot directly dispose of globally defined buttons, and since each pagedraw function falls back into the loop, I am forced to define all my buttons globally. I've tried creating new instances "= new xxxx" and accessing procedures through "->" instead but again - I fall foul of functional and procedural scoping. Is there an effective way you an envisaage of using this library across multiple pages where buttons need to reuse the same zone on different pages? Or will I need to bake my own touch library? Currently I'm using the loop to update lots of other screen elements like a battery bar; I may need to create internal while loops per page within pagedraw procedures instead - which also fire M5.update; etc. as well as updating the screen etc. to keep scope within those procedures for button disposal. So each page draw function really needs to become a loop in its own right. This seems to be a reasonable approach but not entirely efficient. I think my project complexity is outsmarting my coding skillset! :) For future people who might be interested - this is how I solved the problem - you can't really use the main Loop anymore. You need to create local loops within functions for every page. SO I only use the Loop for switch case statement to invoke the loopProcedure for each given page. I create a global mode variable currentPage, and a dedicated loopProcedure for every page of the project (loopMainMenu, loopPlaybackPage etc. etc.) Each loopProcedure draws the screen, invokes the necessary buttons and handlers for that page locally, and then starts a local do-while (currentPage=loopMainMenu){} loop to provide all the typical loop based functions like m5.update(); to keep the button system ticking and battery management going for that page. It stays in this while loop until the back button is pressed or the system navigates to another page somehow (by repointing the currentPage variable). It is the button handler functions that can then change the page which cause the while loop to exit back to the main Loop - and the entire loopProcedure then disposes of everything related to the old page, and a new page loopProcedure is then invoked through the switch case statement in the Loop. It's a bit clunky - It would be preferable that the library itself simply supported dynamic disposal and invokation of global objects in the long run - having a loop for each page is going to get quite bloaty quite quickly but with a little care and some carefully designed functions we can reuse most of the code not related to button invokation. I hope that helps someone in the future. |
Hi @ropg - this is outstanding work and I'd love to use it in some of my projects. Do you have a standalone version of this library, that could be used with M5Stack on top of the official framework? I looked at your repos but can only see a fork of M5Stack. |
Hi @Pensive, |
They do stay forever…so you need to pull your code out of the main loop and run everything from subroutines. When you declare the buttons locally within the subroutines, they are scoped only to that subroutine.
When you exit the subroutines it’s automatically disposed of. I describe how I did it in my post above.
…Sent from my iPhone
On 25 Jan 2022, at 11:50, 47tuc ***@***.***> wrote:
Hi @Pensive,
I'm also trying to create a multi page design on the M5Core2 and have run into the same problem. i.e. getting rid of buttons.
... and the entire loopProcedure then disposes of everything related to the old page
How do you "dispose" of the buttons on the old page? I've found that once they're set up they stay forever.
John.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications on the go with GitHub Mobile for iOS or Android.
You are receiving this because you were mentioned.
|
What is the status of this PR? Looks like it's been open for years. |
8dd199d
to
ebebdea
Compare
d84a70a
to
f72d90d
Compare
123e101
to
2feddca
Compare
M5Button: Buttons, Gestures and Events
The M5Button library supports both hardware buttons and touch screen virtual buttons, and is available both on the M5Stack Core2 touch screen device and the M5Stack devices with three buttons below the screen.
Hardware button support that is 100% Arduino Button Library compatible.
Buttons on the screen, e.g. as labels above the hardware buttons
Zone and Point objects to work with screen locations and areas. Functions for distance, direction and more.
Buttons send events that you can attach handler routines to, or poll in a loop. Events include tap, doubletap, pressed, dragged and more. Support for key repeat.
Intuitive, consistent and well-documented API.
Emulation of the (much less feature-rich) TFT_eSPI_Button class.
M5Display: small tweaks
A few small changes:
Like Touch and Buttons, M5Display now has a static member called 'instance' such that
M5Display::instance
always is a pointer to the first display instance. This way other components of the library can address it without landing in circular reference hell from having to include M5Core2.h.M5.Lcd.pushState()
saves all the display state, cursor positions, selected fonts, everything.M5.Lcd.popSate()
gets it back. Stackable so multiple layers of functionality can be non-invasive on the display.Examples
A few examples were added to demonstrate button events.
Documentation
The documentation lives as comments in the respective header files. I have included them here for reference:
src/M5Touch.h
src/utility/M5Button.h