audio_controls.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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
  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_PUSH, BCTRLS_UP, BCTRLS_DOWN, BCTRLS_LEFT, BCTRLS_RIGHT,
  24. ACTRLS_MAX
  25. } actrls_action_e;
  26. typedef enum {
  27. ACTRLS_MAP_INT, ACTRLS_MAP_BOOL, ACTRLS_MAP_ACTION,ACTRLS_MAP_TYPE,ACTRLS_MAP_END
  28. } actrls_action_map_element_type_e;
  29. typedef void (*actrls_handler)(void);
  30. typedef actrls_handler actrls_t[ACTRLS_MAX - ACTRLS_NONE - 1];
  31. typedef struct {
  32. int gpio;
  33. int type;
  34. bool pull;
  35. int long_press;
  36. int shifter_gpio;
  37. actrls_action_e normal[2], longpress[2], shifted[2], longshifted[2]; // [0] keypressed, [1] keyreleased
  38. } actrls_config_t;
  39. typedef struct {
  40. char * member;
  41. uint32_t offset;
  42. actrls_action_map_element_type_e type;
  43. } actrls_config_map_t;
  44. static const actrls_config_map_t actrls_config_map[] =
  45. {
  46. {"gpio", offsetof(actrls_config_t,gpio), ACTRLS_MAP_INT},
  47. {"type", offsetof(actrls_config_t,type),ACTRLS_MAP_TYPE},
  48. {"pull", offsetof(actrls_config_t,pull),ACTRLS_MAP_BOOL},
  49. {"long_press", offsetof(actrls_config_t,long_press),ACTRLS_MAP_INT},
  50. {"shifter_gpio", offsetof(actrls_config_t,shifter_gpio),ACTRLS_MAP_INT},
  51. {"normal", offsetof(actrls_config_t,normal), ACTRLS_MAP_ACTION},
  52. {"longpress", offsetof(actrls_config_t,longpress), ACTRLS_MAP_ACTION},
  53. {"longshifted", offsetof(actrls_config_t,longshifted), ACTRLS_MAP_ACTION},
  54. {"", 0,ACTRLS_MAP_END}
  55. };
  56. esp_err_t actrls_init(int n, const actrls_config_t *config);
  57. esp_err_t actrls_init_json(const char * config);
  58. void actrls_set_default(const actrls_t controls);
  59. void actrls_set(const actrls_t controls);
  60. void actrls_unset(void);