audio_controls.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. #include "buttons.h"
  10. // BEWARE: this is the index of the array of action below (change actrls_action_s as well!)
  11. typedef enum { ACTRLS_NONE = -1, ACTRLS_VOLUP, ACTRLS_VOLDOWN, ACTRLS_TOGGLE, ACTRLS_PLAY,
  12. ACTRLS_PAUSE, ACTRLS_STOP, ACTRLS_REW, ACTRLS_FWD, ACTRLS_PREV, ACTRLS_NEXT,
  13. BCTRLS_UP, BCTRLS_DOWN, BCTRLS_LEFT, BCTRLS_RIGHT,
  14. KNOB_LEFT, KNOB_RIGHT, KNOB_PUSH,
  15. ACTRLS_REMAP, ACTRLS_MAX
  16. } actrls_action_e;
  17. typedef void (*actrls_handler)(void);
  18. typedef actrls_handler actrls_t[ACTRLS_MAX - ACTRLS_NONE - 1];
  19. typedef bool actrls_hook_t(int gpio, actrls_action_e action, button_event_e event, button_press_e press, bool long_press);
  20. // BEWARE any change to struct below must be mapped to actrls_config_map
  21. typedef struct {
  22. actrls_action_e action;
  23. const char * name;
  24. } actrls_action_detail_t;
  25. typedef struct actrl_config_s {
  26. int gpio;
  27. int type;
  28. bool pull;
  29. int debounce;
  30. int long_press;
  31. int shifter_gpio;
  32. actrls_action_detail_t normal[2], longpress[2], shifted[2], longshifted[2]; // [0] keypressed, [1] keyreleased
  33. } actrls_config_t;
  34. esp_err_t actrls_init(int n, const actrls_config_t *config);
  35. esp_err_t actrls_init_json(const char *profile_name, bool create);
  36. /*
  37. Set hook function to non-null to be set your own direct managemet function,
  38. which should return true if it managed the control request, false if the
  39. normal handling should be done
  40. */
  41. void actrls_set_default(const actrls_t controls, actrls_hook_t *hook);
  42. void actrls_set(const actrls_t controls, actrls_hook_t *hook);
  43. void actrls_unset(void);