mirror of
https://github.com/sle118/squeezelite-esp32.git
synced 2025-12-07 20:17:04 +03:00
More refactoring
last compile dependency on DAC
This commit is contained in:
@@ -62,7 +62,7 @@ void battery_svc_init(void) {
|
||||
battery.channel = CONFIG_BAT_CHANNEL;
|
||||
battery.scale = atof(CONFIG_BAT_SCALE);
|
||||
|
||||
#ifndef BAT_LOCKED
|
||||
#ifndef CONFIG_BAT_LOCKED
|
||||
char *nvs_item = config_alloc_get_default(NVS_TYPE_STR, "bat_config", "n", 0);
|
||||
if (nvs_item) {
|
||||
char *p;
|
||||
|
||||
@@ -29,7 +29,6 @@ extern int spi_system_dc_gpio;
|
||||
extern bool gpio36_39_used;
|
||||
|
||||
#ifdef CONFIG_SQUEEZEAMP
|
||||
#define SPKFAULT_GPIO 2 // this requires a pull-up, so can't be >34
|
||||
#define ADAC dac_tas57xx
|
||||
#elif defined(CONFIG_A1S)
|
||||
#define ADAC dac_a1s
|
||||
|
||||
@@ -170,7 +170,7 @@ void set_led_gpio(int gpio, char *value) {
|
||||
}
|
||||
|
||||
void led_svc_init(void) {
|
||||
#ifndef LED_LOCKED
|
||||
#ifndef CONFIG_LED_LOCKED
|
||||
parse_set_GPIO(set_led_gpio);
|
||||
#endif
|
||||
ESP_LOGI(TAG,"Configuring LEDs green:%d (active:%d), red:%d (active:%d)", green.gpio, green.state, red.gpio, red.state);
|
||||
|
||||
@@ -26,7 +26,12 @@
|
||||
static const char *TAG = "monitor";
|
||||
|
||||
static TimerHandle_t monitor_timer;
|
||||
static int jack_gpio = -1;
|
||||
|
||||
static struct {
|
||||
int gpio;
|
||||
int active;
|
||||
} jack = { CONFIG_JACK_GPIO, CONFIG_JACK_GPIO_LEVEL },
|
||||
spkfault = { CONFIG_SPKFAULT_GPIO, CONFIG_SPKFAULT_GPIO_LEVEL };
|
||||
|
||||
void (*jack_handler_svc)(bool inserted);
|
||||
bool jack_inserted_svc(void);
|
||||
@@ -57,54 +62,34 @@ static void jack_handler_default(void *id, button_event_e event, button_press_e
|
||||
*
|
||||
*/
|
||||
bool jack_inserted_svc (void) {
|
||||
if (jack_gpio != -1) return button_is_pressed(jack_gpio, NULL);
|
||||
else return false;
|
||||
return button_is_pressed(jack.gpio, NULL);
|
||||
}
|
||||
|
||||
/****************************************************************************************
|
||||
*
|
||||
*/
|
||||
#ifdef SPKFAULT_GPIO
|
||||
static void spkfault_handler_default(void *id, button_event_e event, button_press_e mode, bool long_press) {
|
||||
ESP_LOGD(TAG, "Speaker status %s", event == BUTTON_PRESSED ? "faulty" : "normal");
|
||||
if (event == BUTTON_PRESSED) led_on(LED_RED);
|
||||
else led_off(LED_RED);
|
||||
if (spkfault_handler_svc) (*spkfault_handler_svc)(event == BUTTON_PRESSED);
|
||||
}
|
||||
#endif
|
||||
|
||||
/****************************************************************************************
|
||||
*
|
||||
*/
|
||||
bool spkfault_svc (void) {
|
||||
#ifdef SPKFAULT_GPIO
|
||||
return !gpio_get_level(SPKFAULT_GPIO);
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
return button_is_pressed(spkfault.gpio, NULL);
|
||||
}
|
||||
|
||||
/****************************************************************************************
|
||||
*
|
||||
*/
|
||||
void set_jack_gpio(int gpio, char *value) {
|
||||
char *p;
|
||||
int active = 1;
|
||||
|
||||
if (strcasestr(value, "jack")) {
|
||||
jack_gpio = gpio;
|
||||
if ((p = strchr(value, ':')) != NULL) active = atoi(p + 1);
|
||||
}
|
||||
|
||||
if (jack_gpio != -1) {
|
||||
gpio_pad_select_gpio(jack_gpio);
|
||||
gpio_set_direction(jack_gpio, GPIO_MODE_INPUT);
|
||||
gpio_set_pull_mode(jack_gpio, active ? GPIO_PULLDOWN_ONLY : GPIO_PULLUP_ONLY);
|
||||
|
||||
ESP_LOGI(TAG,"Adding jack (%s) detection GPIO %d", active ? "high" : "low", gpio);
|
||||
|
||||
// re-use button management for jack handler, it's a GPIO after all
|
||||
button_create(NULL, jack_gpio, active ? BUTTON_HIGH : BUTTON_LOW, false, 250, jack_handler_default, 0, -1);
|
||||
char *p;
|
||||
jack.gpio = gpio;
|
||||
if ((p = strchr(value, ':')) != NULL) jack.active = atoi(p + 1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -114,25 +99,26 @@ void set_jack_gpio(int gpio, char *value) {
|
||||
void monitor_svc_init(void) {
|
||||
ESP_LOGI(TAG, "Initializing monitoring");
|
||||
|
||||
#if CONFIG_JACK_GPIO_LEVEL == 1
|
||||
set_jack_gpio(CONFIG_JACK_GPIO, "jack:1");
|
||||
#else
|
||||
set_jack_gpio(CONFIG_JACK_GPIO, "jack:0");
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_JACK_LOCKED
|
||||
parse_set_GPIO(set_jack_gpio);
|
||||
#endif
|
||||
|
||||
#ifdef SPKFAULT_GPIO
|
||||
gpio_pad_select_gpio(SPKFAULT_GPIO);
|
||||
gpio_set_direction(SPKFAULT_GPIO, GPIO_MODE_INPUT);
|
||||
gpio_set_pull_mode(SPKFAULT_GPIO, GPIO_PULLUP_ONLY);
|
||||
|
||||
// re-use button management for speaker fault handler, it's a GPIO after all
|
||||
button_create(NULL, SPKFAULT_GPIO, BUTTON_LOW, true, 0, spkfault_handler_default, 0, -1);
|
||||
// re-use button management for jack handler, it's a GPIO after all
|
||||
if (jack.gpio != -1) {
|
||||
ESP_LOGI(TAG,"Adding jack (%s) detection GPIO %d", jack.active ? "high" : "low", jack.gpio);
|
||||
button_create(NULL, jack.gpio, jack.active ? BUTTON_HIGH : BUTTON_LOW, false, 250, jack_handler_default, 0, -1);
|
||||
}
|
||||
|
||||
#ifndef CONFIG_SPKFAULT_LOCKED
|
||||
parse_set_GPIO(set_spkfault_gpio);
|
||||
#endif
|
||||
|
||||
// re-use button management for speaker fault handler, it's a GPIO after all
|
||||
if (spkfault.gpio != -1) {
|
||||
ESP_LOGI(TAG,"Adding speaker fault (%s) detection GPIO %d", spkfault.active ? "high" : "low", spkfault.gpio);
|
||||
button_create(NULL, spkfault.gpio, spkfault.active ? BUTTON_HIGH : BUTTON_LOW, false, 0, spkfault_handler_default, 0, -1);
|
||||
}
|
||||
|
||||
// do we want stats
|
||||
char *p = config_alloc_get_default(NVS_TYPE_STR, "stats", "n", 0);
|
||||
if (p && (*p == '1' || *p == 'Y' || *p == 'y')) {
|
||||
@@ -140,5 +126,4 @@ void monitor_svc_init(void) {
|
||||
xTimerStart(monitor_timer, portMAX_DELAY);
|
||||
}
|
||||
free(p);
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user