audio_controls.h 2.2 KB

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