audio_controls.c 3.1 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. * DOWN button
  39. */
  40. static void down(button_event_e event, button_press_e press, bool long_press) {
  41. if (press == BUTTON_NORMAL) {
  42. if (!long_press) ESP_LOGI(TAG, "volume DOWN %u", event);
  43. else ESP_LOGI(TAG, "volume DOWN long %u", event);
  44. } else {
  45. if (!long_press) ESP_LOGI(TAG, "volume DOWN shifted %u", event);
  46. else ESP_LOGI(TAG, "volume DOWN long shifted %u", event);
  47. }
  48. //if (event == BUTTON_PRESSED) (*current_control.volume_down)();
  49. }
  50. /****************************************************************************************
  51. * UP button
  52. */
  53. static void up(button_event_e event, button_press_e press, bool long_press) {
  54. if (press == BUTTON_NORMAL) {
  55. if (!long_press) ESP_LOGI(TAG, "volume UP %u", event);
  56. else ESP_LOGI(TAG, "volume UP long %u", event);
  57. } else {
  58. if (!long_press) ESP_LOGI(TAG, "volume UP shifted %u", event);
  59. else ESP_LOGI(TAG, "volume UP long shifted %u", event);
  60. }
  61. //if (event == BUTTON_PRESSED) (*current_control.volume_up)();
  62. }
  63. /****************************************************************************************
  64. *
  65. */
  66. void audio_controls_init(void) {
  67. /*
  68. button_create(18, BUTTON_LOW, true, up, 0, -1);
  69. button_create(19, BUTTON_LOW, true, down, 0, -1);
  70. button_create(21, BUTTON_LOW, true, play, 0, -1);
  71. */
  72. button_create(4, BUTTON_LOW, true, up, 2000, -1);
  73. button_create(5, BUTTON_LOW, true, down, 3000, 4);
  74. }
  75. /****************************************************************************************
  76. *
  77. */
  78. void default_audio_control(audio_control_t *control) {
  79. default_control = current_control = *control;
  80. }
  81. /****************************************************************************************
  82. *
  83. */
  84. void register_audio_control(audio_control_t *control) {
  85. current_control = *control;
  86. }
  87. /****************************************************************************************
  88. *
  89. */
  90. void deregister_audio_control(void) {
  91. current_control = default_control;
  92. }