audio_controls.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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_POWER,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. BCTRLS_PS1,BCTRLS_PS2,BCTRLS_PS3,BCTRLS_PS4,BCTRLS_PS5,BCTRLS_PS6,
  15. KNOB_LEFT, KNOB_RIGHT, KNOB_PUSH,
  16. ACTRLS_REMAP, ACTRLS_MAX
  17. } actrls_action_e;
  18. typedef void (*actrls_handler)(bool pressed);
  19. typedef actrls_handler actrls_t[ACTRLS_MAX - ACTRLS_NONE - 1];
  20. typedef bool actrls_hook_t(int gpio, actrls_action_e action, button_event_e event, button_press_e press, bool long_press);
  21. typedef bool actrls_ir_handler_t(uint16_t addr, uint16_t cmd);
  22. // BEWARE any change to struct below must be mapped to actrls_config_map
  23. typedef struct {
  24. actrls_action_e action;
  25. const char * name;
  26. } actrls_action_detail_t;
  27. typedef struct actrl_config_s {
  28. int gpio;
  29. int type;
  30. bool pull;
  31. int debounce;
  32. int long_press;
  33. int shifter_gpio;
  34. actrls_action_detail_t normal[2], longpress[2], shifted[2], longshifted[2]; // [0] keypressed, [1] keyreleased
  35. } actrls_config_t;
  36. esp_err_t actrls_init(const char *profile_name);
  37. /*
  38. Set hook function to non-null to be set your own direct managemet function,
  39. which should return true if it managed the control request, false if the
  40. normal handling should be done
  41. The add_release boolean forces a release event to be sent if a press action has been
  42. set, whether a release action has been set or not
  43. */
  44. void actrls_set_default(const actrls_t controls, bool raw_controls, actrls_hook_t *hook, actrls_ir_handler_t *ir_handler);
  45. void actrls_set(const actrls_t controls, bool raw_controls, actrls_hook_t *hook, actrls_ir_handler_t *ir_handler);
  46. void actrls_unset(void);
  47. bool actrls_ir_action(uint16_t addr, uint16_t code);