diff --git a/components/services/monitor.c b/components/services/monitor.c index 550c52c3..36a03123 100644 --- a/components/services/monitor.c +++ b/components/services/monitor.c @@ -145,7 +145,7 @@ static void monitor_callback(TimerHandle_t xTimer) { * */ 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"); + ESP_LOGI(TAG, "Jack %s", event == BUTTON_PRESSED ? "inserted" : "removed"); if (jack_handler_svc) (*jack_handler_svc)(event == BUTTON_PRESSED); } diff --git a/components/squeezelite/external/dac_external.c b/components/squeezelite/external/dac_external.c index babab59d..5502d09f 100644 --- a/components/squeezelite/external/dac_external.c +++ b/components/squeezelite/external/dac_external.c @@ -20,8 +20,8 @@ static const char TAG[] = "DAC external"; -static void speaker(bool active) { } -static void headset(bool active) { } +static void speaker(bool active); +static void headset(bool active); static bool volume(unsigned left, unsigned right) { return false; } static void power(adac_power_e mode); static bool init(char *config, int i2c_port_num, i2s_config_t *i2s_config); @@ -95,6 +95,22 @@ static void power(adac_power_e mode) { else i2c_json_execute("poweron"); } +/**************************************************************************************** + * speaker + */ +static void speaker(bool active) { + if (active) i2c_json_execute("speakeron"); + else i2c_json_execute("speakeroff"); +} + +/**************************************************************************************** + * headset + */ +static void headset(bool active) { + if (active) i2c_json_execute("headseton"); + else i2c_json_execute("headsetoff"); +} + /**************************************************************************************** * */ diff --git a/components/squeezelite/output_i2s.c b/components/squeezelite/output_i2s.c index 3082adb1..22bc7c9c 100644 --- a/components/squeezelite/output_i2s.c +++ b/components/squeezelite/output_i2s.c @@ -129,8 +129,13 @@ static bool handler(u8_t *data, int len){ jack_mutes_amp = pkt->config == 0; config_set_value(NVS_TYPE_STR, "jack_mutes_amp", jack_mutes_amp ? "y" : "n"); - if (jack_mutes_amp && jack_inserted_svc()) adac->speaker(false); - else adac->speaker(true); + if (jack_mutes_amp && jack_inserted_svc()) { + adac->speaker(false); + if (amp_control.gpio != -1) gpio_set_level(amp_control.gpio, !amp_control.active); + } else { + adac->speaker(true); + if (amp_control.gpio != -1) gpio_set_level(amp_control.gpio, amp_control.active); + } } LOG_INFO("got AUDO %02x", pkt->config); @@ -151,13 +156,12 @@ 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 ? "OFF" : "ON"); - if (inserted) adac->speaker(false); - else adac->speaker(true); + adac->speaker(!inserted); + if (amp_control.gpio != -1) gpio_set_level(amp_control.gpio, inserted ? !amp_control.active : amp_control.active); } // activate headset - if (inserted) adac->headset(true); - else adac->headset(false); + adac->headset(inserted); // and chain if any if (jack_handler_chain) (jack_handler_chain)(inserted); @@ -343,12 +347,13 @@ void output_init_i2s(log_level level, char *device, unsigned output_buf_size, ch jack_handler_chain = jack_handler_svc; jack_handler_svc = jack_handler; + parse_set_GPIO(set_amp_gpio); + if (jack_mutes_amp && jack_inserted_svc()) adac->speaker(false); else adac->speaker(true); adac->headset(jack_inserted_svc()); - parse_set_GPIO(set_amp_gpio); // create task as a FreeRTOS task but uses stack in internal RAM { @@ -455,7 +460,10 @@ static void output_thread_i2s(void *arg) { adac->speaker(false); led_blink(LED_GREEN, 200, 1000); } else if (output.state == OUTPUT_RUNNING) { - if (!jack_mutes_amp || !jack_inserted_svc()) adac->speaker(true); + if (!jack_mutes_amp || !jack_inserted_svc()) { + if (amp_control.gpio != -1) gpio_set_level(amp_control.gpio, amp_control.active); + adac->speaker(true); + } led_on(LED_GREEN); } } @@ -513,7 +521,6 @@ static void output_thread_i2s(void *arg) { i2s_zero_dma_buffer(CONFIG_I2S_NUM); i2s_start(CONFIG_I2S_NUM); adac->power(ADAC_ON); - if (amp_control.gpio != -1) gpio_set_level(amp_control.gpio, amp_control.active); } // this does not work well as set_sample_rates resets the fifos (and it's too early)