mirror of
https://github.com/sle118/squeezelite-esp32.git
synced 2025-12-06 11:36:59 +03:00
more refactoring
- jack & led moved to services - output_i2s subscribes to jack detection - add user-defined debounce timer to buttons
This commit is contained in:
@@ -15,12 +15,17 @@
|
||||
#include "esp_system.h"
|
||||
#include "esp_log.h"
|
||||
#include "monitor.h"
|
||||
#include "driver/gpio.h"
|
||||
#include "buttons.h"
|
||||
|
||||
#define JACK_GPIO 34
|
||||
#define MONITOR_TIMER (10*1000)
|
||||
|
||||
static const char TAG[] = "monitor";
|
||||
|
||||
static TimerHandle_t monitor_timer;
|
||||
void (*jack_handler_svc)(bool inserted);
|
||||
bool jack_inserted_svc(void);
|
||||
|
||||
/****************************************************************************************
|
||||
*
|
||||
@@ -33,12 +38,39 @@ static void monitor_callback(TimerHandle_t xTimer) {
|
||||
heap_caps_get_minimum_free_size(MALLOC_CAP_SPIRAM));
|
||||
}
|
||||
|
||||
/****************************************************************************************
|
||||
*
|
||||
*/
|
||||
static void jack_handler_default(void *id, button_event_e event, button_press_e mode, bool long_press) {
|
||||
ESP_LOGD(TAG, "Jack %s", event == BUTTON_PRESSED ? "inserted" : "removed");
|
||||
if (jack_handler_svc) (*jack_handler_svc)(event == BUTTON_PRESSED);
|
||||
}
|
||||
|
||||
/****************************************************************************************
|
||||
*
|
||||
*/
|
||||
bool jack_inserted_svc (void) {
|
||||
#ifdef JACK_GPIO
|
||||
return !gpio_get_level(JACK_GPIO);
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
/****************************************************************************************
|
||||
*
|
||||
*/
|
||||
void monitor_svc_init(void) {
|
||||
ESP_LOGI(TAG, "Initializing monitoring");
|
||||
|
||||
#ifdef JACK_GPIO
|
||||
gpio_pad_select_gpio(JACK_GPIO);
|
||||
gpio_set_direction(JACK_GPIO, GPIO_MODE_INPUT);
|
||||
|
||||
// re-use button management for jack handler, it's a GPIO after all
|
||||
button_create(NULL, JACK_GPIO, BUTTON_LOW, false, 250, jack_handler_default, 0, -1);
|
||||
#endif
|
||||
|
||||
monitor_timer = xTimerCreate("monitor", MONITOR_TIMER / portTICK_RATE_MS, pdTRUE, NULL, monitor_callback);
|
||||
xTimerStart(monitor_timer, portMAX_DELAY);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user