Spirik / GEM

Good Enough Menu for Arduino
GNU Lesser General Public License v3.0
245 stars 36 forks source link

Switch button behavior for 3-buttons navigations #84

Closed albydnc closed 7 months ago

albydnc commented 7 months ago

Hello,

I have a display with only 3 buttons (up, down, enter). I would like to use the library to create menus, but to do so, I have to switch the key behaviour when the menu is in editing mode or in navigation mode. Is it possible to have the feedback of the menu state to switch behaviour?

Thanks

Spirik commented 7 months ago

Hello, @albydnc !

Yes, it is possible! Boolean property, which holds current mode of the menu (edition of variable or navigation through menu items), is called _editValueMode . It is protected (since GEM ver. 1.5.2), which makes it possible to access this property from within user-defined derived (inherited) class of GEM. Based on the example provided in How to section of wiki, it will look something like this:

// Define GEMProxy class which inherits from GEM_u8g2
class GEMProxy : public GEM_u8g2 {
  public:
    using GEM_u8g2::GEM_u8g2;

    // Get _editValueMode
    bool isInEditMode() {
      return _editValueMode;
    }
};

...

// Use GEMProxy class to create menu here
GEMProxy menu(u8g2);

...

// Access user-defined method to get value of internal _editValueMode property
menu.isInEditMode();

Another possible solution to operation of the GEM with only 3 buttons that I may suggest is to detect combinations of key presses (i.e. simultaneous presses of two buttons), available in latest version of KeyDetector. That way it is possible to implement mapping of this 3 buttons to 6 key codes GEM expects, e.g. like so (given buttons A, B, C:

Though you would have to carefully write your own key detection routine to correctly measure time intervals (delays) and key combinations. Some of this approach can be seen in Rotary Encoder examples (which uses short and long-presses of push-button and combinations of button presses with the rotation of the knob).

Hope that helps=)

shezik commented 7 months ago

This method is oddly familiar 😛

albydnc commented 7 months ago

Thanks!