audio_controls.h 2.1 KB

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