buttons.h 1.2 KB

12345678910111213141516171819202122232425262728293031323334
  1. /*
  2. * (c) Philippe G. 2019, philippe_44@outlook.com
  3. *
  4. * This software is released under the MIT License.
  5. * https://opensource.org/licenses/MIT
  6. *
  7. */
  8. #pragma once
  9. // button type (pressed = LOW or HIGH, matches GPIO level)
  10. #define BUTTON_LOW 0
  11. #define BUTTON_HIGH 1
  12. typedef enum { BUTTON_PRESSED, BUTTON_RELEASED } button_event_e;
  13. typedef enum { BUTTON_NORMAL, BUTTON_SHIFTED } button_press_e;
  14. typedef void (*button_handler)(void *id, button_event_e event, button_press_e mode, bool long_press);
  15. /*
  16. set debounce to 0 for default (50ms)
  17. set long_press to 0 for no long-press
  18. set shifter_gpio to -1 for no shift
  19. NOTE: shifter buttons *must* be created before shiftee
  20. */
  21. void button_create(void *client, int gpio, int type, bool pull, int debounce, button_handler handler, int long_press, int shifter_gpio);
  22. void *button_remap(void *client, int gpio, button_handler handler, int long_press, int shifter_gpio);
  23. void *button_get_client(int gpio);
  24. bool button_is_pressed(int gpio, void *client);
  25. typedef enum { ROTARY_LEFT, ROTARY_RIGHT, ROTARY_PRESSED, ROTARY_RELEASED } rotary_event_e;
  26. typedef void (*rotary_handler)(void *id, rotary_event_e event, bool long_press);
  27. bool create_rotary(void *id, int A, int B, int SW, int long_press, rotary_handler handler);