olikraus / u8g2

U8glib library for monochrome displays, version 2
Other
5.12k stars 1.05k forks source link

Add support for active-high menu buttons #2214

Open pandomic opened 1 year ago

pandomic commented 1 year ago

Summary

Hey folks, first of all, thanks for such an amazing library!

I already completed and ordered a hardware part for my project, when I realized the library can only handle active-low button events (while the project is already set up for active-high).

It will be a great addition if the library could support active-high as well. Currently, I simply patch the following function to achieve the desired result:

// changed from
u8x8_SetGPIOResult(u8x8, digitalRead(i) == 0 ? 0 : 1);
// changed to
u8x8_SetGPIOResult(u8x8, digitalRead(i) == 1 ? 0 : 1);

but this approach is not reliable as the library could change at any time.

Instead, there could be a simple flag, let's say U8X8_USE_ACTIVE_HIGH:

#ifdef U8X8_USE_ACTIVE_HIGH
  u8x8_SetGPIOResult(u8x8, digitalRead(i) == 1 ? 0 : 1);
#else
  u8x8_SetGPIOResult(u8x8, digitalRead(i) == 0 ? 0 : 1);
#endif // U8X8_USE_ACTIVE_HIGH

I may try raising a PR with proposed solution from above once I have a bit of time 🙌

olikraus commented 1 year ago

The existing "user" menues are kind of obsolete. I suggest to use MUI. It supports proper button libs: https://github.com/olikraus/u8g2/wiki/gallery#18-jun-2023-mui-shield-with-rotary-encoder-and-sh1106-oled

https://github.com/olikraus/u8g2/blob/master/sys/arduino/u8g2_page_buffer/MUIInput2BtnBounce2/MUIInput2BtnBounce2.ino