U8g2 MUI organisation as part of a custom UIManager class #2252
Replies: 5 comments 7 replies
-
"muif_cb" is defined as typedef uint8_t (*muif_cb)(mui_t *ui, uint8_t msg); You function must exactly look like this, especially it must not be a member function of a class (like in your example). |
Beta Was this translation helpful? Give feedback.
-
I'm having the exact same issue. I noticed that first when MUI rendered just a blank screen when initializing the Fds and Fpl inside of a class method. It would be great to have an example of how to use MUI with class methods, or a workaround with friend functions. Also for my code, I used |
Beta Was this translation helpful? Give feedback.
-
The core code of u8g2 is written in C only. I continued doing so with MUI. If you want me to create a C++ example, then maybe consider the creation of an issue... but my time is a little bit limited... |
Beta Was this translation helpful? Give feedback.
-
So far, the following structure of code seems to work for me:
I included a screenshot of the structure in my main.cpp (at the end of this post), meanwhile the following is how my constructor currently handles references in UIManager.cpp:
...and how my
This is my result so far, although I didn't yet fully achieve my intentions of making main.cpp maximally clean yet though. For moving the header files for the MUI callback functions and
I would be happy to receive critical remarks and general thoughts (and as mentioned before please know I am not an expert in this)! |
Beta Was this translation helpful? Give feedback.
-
Using the U8g2 library with the MUI addon has been a great pleasure so far. Initially I wrote all my code in one single main.cpp file which was working fine. But when my code started growing beyond pleasantly scrollable I chose to organise everything into different classes, rewriting my code from the ground up. I am now trying to construct a class called UIManager which is supposed to be responsible for handling all UI input (rotary encoder, buttons, etc.) and controlling UI output (SSD1306 OLED, different LEDs, alarm buzzer, etc.). Currently this class is able to display buttons, labels, and other more static data on my OLED, but since I started using "MUIF_RO" within the MUIF table, I've encountered an error that says:
a value of type "uint8_t (UIManager::*)(mui_t *ui, uint8_t msg)" cannot be used to initialize an entity of type "muif_cb"
Using the same function in my initial, all-included main.cpp was working fine. And also when commenting out the specific line in my current UIManager.cpp, responsible for linking the function with a MUI item in my 'muif_list' (
MUIF_RO("SH", show_my_data)
), it works fine again as well. Since MUI makes use of preprocessor directives, is it even possible to organise custom MUI function callbacks from within a separate UIManager class?(I am relatively new to C++ programming)
Beta Was this translation helpful? Give feedback.
All reactions