2
0

audio_controls.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /*
  2. * audio control callbacks
  3. *
  4. * (c) Sebastien 2019
  5. * Philippe G. 2019, philippe_44@outlook.com
  6. *
  7. * This program is free software: you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation, either version 3 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. *
  20. */
  21. #include <stdlib.h>
  22. #include <unistd.h>
  23. #include "esp_system.h"
  24. #include "esp_log.h"
  25. #include "buttons.h"
  26. #include "audio_controls.h"
  27. static const char * TAG = "audio_controls";
  28. typedef struct {
  29. void (*volume_up)(void);
  30. void (*volume_down)(void);
  31. void (*play_toggle)(void);
  32. void (*play)(void);
  33. void (*pause)(void);
  34. void (*stop)(void);
  35. } audio_control_t;
  36. static audio_control_t default_control, current_control;
  37. /****************************************************************************************
  38. * Volume DOWN command
  39. */
  40. static void volume_down(button_event_e event, button_press_e press) {
  41. ESP_LOGI(TAG, "volume down %u", event);
  42. //if (event == BUTTON_PRESSED) (*current_control.volume_down)();
  43. }
  44. static void volume_down_special(button_event_e event, button_press_e press) {
  45. if (press == BUTTON_LONG) ESP_LOGI(TAG, "volume down long %u", event);
  46. else ESP_LOGI(TAG, "volume down shifted %u", event);
  47. //if (event == BUTTON_PRESSED) (*current_control.volume_down)();
  48. }
  49. /****************************************************************************************
  50. * Volume UP commands
  51. */
  52. static void volume_up(button_event_e event, button_press_e press) {
  53. ESP_LOGI(TAG, "volume up %u", event);
  54. //if (event == BUTTON_PRESSED) (*current_control.volume_up)();
  55. }
  56. static void volume_up_long(button_event_e event, button_press_e press) {
  57. if (press == BUTTON_LONG) ESP_LOGI(TAG, "volume up long %u", event);
  58. else ESP_LOGI(TAG, "volume up shifted %u", event);
  59. //if (event == BUTTON_PRESSED) (*current_control.volume_down)();
  60. }
  61. /****************************************************************************************
  62. *
  63. */
  64. void audio_controls_init(void) {
  65. /*
  66. button_create(18, BUTTON_LOW, true, volume_up, NULL);
  67. button_create(19, BUTTON_LOW, true, volume_down, "long", volume_down_long, 3000, NULL);
  68. button_create(21, BUTTON_LOW, true, volume_up, NULL);
  69. */
  70. button_create(4, BUTTON_LOW, true, volume_up, NULL);
  71. button_create(5, BUTTON_LOW, true, volume_down, "long", volume_down_special, 3000, "shift", volume_down_special, 4, NULL);
  72. }
  73. /****************************************************************************************
  74. *
  75. */
  76. void default_audio_control(audio_control_t *control) {
  77. default_control = current_control = *control;
  78. }
  79. /****************************************************************************************
  80. *
  81. */
  82. void register_audio_control(audio_control_t *control) {
  83. current_control = *control;
  84. }
  85. /****************************************************************************************
  86. *
  87. */
  88. void deregister_audio_control(void) {
  89. current_control = default_control;
  90. }