buttons.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. /*
  2. * (c) Philippe G. 2019, philippe_44@outlook.com
  3. *
  4. * This program is free software: you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation, either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. *
  17. */
  18. #pragma once
  19. // button type (pressed = LOW or HIGH, matches GPIO level)
  20. #define BUTTON_LOW 0
  21. #define BUTTON_HIGH 1
  22. typedef enum { BUTTON_PRESSED, BUTTON_RELEASED } button_event_e;
  23. typedef enum { BUTTON_NORMAL, BUTTON_SHIFTED } button_press_e;
  24. typedef void (*button_handler)(void *id, button_event_e event, button_press_e mode, bool long_press);
  25. /*
  26. set debounce to 0 for default (50ms)
  27. set long_press to 0 for no long-press
  28. set shifter_gpio to -1 for no shift
  29. NOTE: shifter buttons *must* be created before shiftee
  30. */
  31. void button_create(void *client, int gpio, int type, bool pull, int debounce, button_handler handler, int long_press, int shifter_gpio);
  32. void *button_remap(void *client, int gpio, button_handler handler, int long_press, int shifter_gpio);
  33. void *button_get_client(int gpio);
  34. bool button_is_pressed(int gpio, void *client);
  35. typedef enum { ROTARY_LEFT, ROTARY_RIGHT, ROTARY_PRESSED, ROTARY_RELEASED } rotary_event_e;
  36. typedef void (*rotary_handler)(void *id, rotary_event_e event, bool long_press);
  37. bool create_rotary(void *id, int A, int B, int SW, int long_press, rotary_handler handler);