mirror of
https://github.com/sle118/squeezelite-esp32.git
synced 2025-12-06 19:47:02 +03:00
add speaker fault + some cleanup
This commit is contained in:
@@ -187,6 +187,7 @@ void button_create(void *id, int gpio, int type, bool pull, int debounce, button
|
||||
}
|
||||
}
|
||||
|
||||
gpio_pad_select_gpio(gpio);
|
||||
gpio_set_direction(gpio, GPIO_MODE_INPUT);
|
||||
|
||||
// we need any edge detection
|
||||
|
||||
@@ -17,16 +17,25 @@
|
||||
#include "monitor.h"
|
||||
#include "driver/gpio.h"
|
||||
#include "buttons.h"
|
||||
#include "led.h"
|
||||
|
||||
#ifdef CONFIG_SQUEEZEAMP
|
||||
#define JACK_GPIO 34
|
||||
#define SPKFAULT_GPIO 2
|
||||
#endif
|
||||
|
||||
#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);
|
||||
|
||||
void (*spkfault_handler_svc)(bool inserted);
|
||||
bool spkfault_svc(void);
|
||||
|
||||
/****************************************************************************************
|
||||
*
|
||||
*/
|
||||
@@ -57,6 +66,28 @@ bool jack_inserted_svc (void) {
|
||||
#endif
|
||||
}
|
||||
|
||||
/****************************************************************************************
|
||||
*
|
||||
*/
|
||||
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);
|
||||
}
|
||||
|
||||
/****************************************************************************************
|
||||
*
|
||||
*/
|
||||
bool spkfault_svc (void) {
|
||||
#ifdef SPKFAULT_GPIO
|
||||
return !gpio_get_level(SPKFAULT_GPIO);
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
#include "driver/rtc_io.h"
|
||||
/****************************************************************************************
|
||||
*
|
||||
*/
|
||||
@@ -71,6 +102,15 @@ void monitor_svc_init(void) {
|
||||
button_create(NULL, JACK_GPIO, BUTTON_LOW, false, 250, jack_handler_default, 0, -1);
|
||||
#endif
|
||||
|
||||
#ifdef SPKFAULT_GPIO
|
||||
gpio_pad_select_gpio(SPKFAULT_GPIO);
|
||||
ESP_LOGI(TAG, "DIR %d", gpio_set_direction(SPKFAULT_GPIO, GPIO_MODE_INPUT));
|
||||
ESP_LOGI(TAG, "PULLUP %d", 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);
|
||||
#endif
|
||||
|
||||
monitor_timer = xTimerCreate("monitor", MONITOR_TIMER / portTICK_RATE_MS, pdTRUE, NULL, monitor_callback);
|
||||
xTimerStart(monitor_timer, portMAX_DELAY);
|
||||
}
|
||||
|
||||
@@ -23,3 +23,6 @@
|
||||
extern void (*jack_handler_svc)(bool inserted);
|
||||
extern bool jack_inserted_svc(void);
|
||||
|
||||
extern void (*spkfault_handler_svc)(bool inserted);
|
||||
extern bool spkfault_svc(void);
|
||||
|
||||
|
||||
@@ -208,7 +208,7 @@ static u8_t tas57_addr;
|
||||
static void jack_handler(bool inserted) {
|
||||
// jack detection bounces a bit but that seems fine
|
||||
if (jack_mutes_amp) {
|
||||
LOG_INFO("switching amplifier %s", inserted ? "ON" : "OFF");
|
||||
LOG_INFO("switching amplifier %s", inserted ? "OFF" : "ON");
|
||||
if (inserted) dac_cmd(DAC_ANALOGUE_OFF);
|
||||
else dac_cmd(DAC_ANALOGUE_ON);
|
||||
}
|
||||
|
||||
@@ -287,7 +287,7 @@ void register_default_nvs(){
|
||||
ESP_LOGD(TAG,"Registering Audio control board type %s, value %s","actrls_brd2", actrls_brd1);
|
||||
config_set_default(NVS_TYPE_STR, "actrls_brd2",(void *) actrls_brd2, 0);
|
||||
|
||||
ESP_LOGD(TAG,"Registering Defalt Audio control board type %s, value ","actrls_brd");
|
||||
ESP_LOGD(TAG,"Registering default Audio control board type %s, value ","actrls_brd");
|
||||
config_set_default(NVS_TYPE_STR, "actrls_brd", "", 0);
|
||||
|
||||
char number_buffer[101] = {};
|
||||
@@ -323,7 +323,7 @@ void app_main()
|
||||
wifi_event_group = xEventGroupCreate();
|
||||
ESP_LOGD(TAG,"Clearing CONNECTED_BIT from wifi group");
|
||||
xEventGroupClearBits(wifi_event_group, CONNECTED_BIT);
|
||||
|
||||
|
||||
ESP_LOGI(TAG,"Starting app_main");
|
||||
initialize_nvs();
|
||||
|
||||
@@ -358,7 +358,6 @@ void app_main()
|
||||
bypass_wifi_manager=(strcmp(bypass_wm,"1")==0 ||strcasecmp(bypass_wm,"y")==0);
|
||||
}
|
||||
|
||||
|
||||
char *actrls_brd = config_alloc_get_default(NVS_TYPE_STR, "actrls_brd", NULL, 0);
|
||||
if (actrls_brd) {
|
||||
if(actrls_brd[0] !='\0'){
|
||||
@@ -373,6 +372,8 @@ void app_main()
|
||||
}
|
||||
}
|
||||
free(actrls_brd);
|
||||
} else {
|
||||
ESP_LOGD(TAG,"No audio control buttons");
|
||||
}
|
||||
|
||||
/* start the wifi manager */
|
||||
|
||||
Reference in New Issue
Block a user