From a5b2d4023b9da738560f1fa2b8232015206d4ced Mon Sep 17 00:00:00 2001 From: philippe44 Date: Fri, 6 Dec 2019 03:58:19 -0800 Subject: [PATCH 01/89] jack muting --- components/squeezelite/output_i2s.c | 34 ++++++++++------------------- 1 file changed, 12 insertions(+), 22 deletions(-) diff --git a/components/squeezelite/output_i2s.c b/components/squeezelite/output_i2s.c index 047b9122..0d4a1629 100644 --- a/components/squeezelite/output_i2s.c +++ b/components/squeezelite/output_i2s.c @@ -83,7 +83,7 @@ sure that using rate_delay would fix that #define CONFIG_SPDIF_NUM -1 #endif -typedef enum { DAC_ACTIVE = 0, DAC_STANDBY, DAC_DOWN, DAC_ANALOG_UP, DAC_ANALOG_DOWN, DAC_VOLUME } dac_cmd_e; +typedef enum { DAC_ACTIVE = 0, DAC_STANDBY, DAC_DOWN, DAC_ANALOG_OFF, DAC_ANALOG_ON, DAC_VOLUME } dac_cmd_e; // must have an integer ratio with FRAME_BLOCK (see spdif comment) #define DMA_BUF_LEN 512 @@ -130,7 +130,6 @@ static int _i2s_write_frames(frames_t out_frames, bool silence, s32_t gainL, s32 static void *output_thread_i2s(); static void *output_thread_i2s_stats(); static void dac_cmd(dac_cmd_e cmd, ...); -static void set_analogue(bool mute); static int tas57_detect(void); static void spdif_convert(ISAMPLE_T *src, size_t frames, u32_t *dst, size_t *count); @@ -160,6 +159,9 @@ static void spdif_convert(ISAMPLE_T *src, size_t frames, u32_t *dst, size_t *cou #define VOLUME_GPIO 14 #define JACK_GPIO 34 +#define TAS575x 0x98 +#define TAS578x 0x90 + struct tas57xx_cmd_s { u8_t reg; u8_t value; @@ -172,6 +174,8 @@ static const struct tas57xx_cmd_s tas57xx_init_sequence[] = { { 0x02, 0x10 }, // standby { 0x0d, 0x10 }, // use SCK for PLL { 0x25, 0x08 }, // ignore SCK halt + { 0x08, 0x10 }, // Mute control enable (from TAS5780) + { 0x54, 0x02 }, // Mute output control (from TAS5780) { 0x02, 0x00 }, // restart { 0xff, 0xff } // end of table }; @@ -189,8 +193,8 @@ static const struct tas57xx_cmd_s tas57xx_cmd[] = { { 0x02, 0x00 }, // DAC_ACTIVE { 0x02, 0x10 }, // DAC_STANDBY { 0x02, 0x01 }, // DAC_DOWN - { 46, 0x01 }, // DAC_ANALOG_UP - { 46, 0x00 }, // DAC_ANALOG_DOWN + { 0x56, 0x10 }, // DAC_ANALOG_OFF + { 0x56, 0x00 }, // DAC_ANALOG_ON }; static u8_t tas57_addr; @@ -243,7 +247,7 @@ void output_init_i2s(log_level level, char *device, unsigned output_buf_size, ch } // activate analogue output if needed - if (!jack_mutes_amp) set_analogue(true); + if (!jack_mutes_amp) dac_cmd(DAC_ANALOG_ON); #endif #ifdef CONFIG_I2S_BITS_PER_CHANNEL @@ -457,7 +461,7 @@ static void *output_thread_i2s() { if (gpio_get_level(JACK_GPIO) != jack_status) { jack_status = gpio_get_level(JACK_GPIO); if (jack_mutes_amp) { - set_analogue(jack_status); + dac_cmd(jack_status ? DAC_ANALOG_ON : DAC_ANALOG_OFF); LOG_INFO("Changing jack status %d", jack_status); } } @@ -641,26 +645,12 @@ void dac_cmd(dac_cmd_e cmd, ...) { va_end(args); } -/**************************************************************************************** - * Analogue mute - */ -#ifdef TAS57xx -static void set_analogue(bool active) { - - dac_cmd(DAC_STANDBY); - // need to wait a bit for TAS to execute standby before sending backend-down command - usleep(50*1000); - dac_cmd(active ? DAC_ANALOG_UP : DAC_ANALOG_DOWN); - dac_cmd(DAC_ACTIVE); -} -#endif /**************************************************************************************** * TAS57 detection */ #ifdef TAS57xx static int tas57_detect(void) { - - u8_t data, addr[] = {0x90, 0x98}; + u8_t data, addr[] = {TAS578x, TAS575x}; int ret; for (int i = 0; i < sizeof(addr); i++) { @@ -683,7 +673,7 @@ static int tas57_detect(void) { return addr[i]; } } - + return 0; } #endif From 7808c08874dafa737c9cecb78a981e7807d18fc3 Mon Sep 17 00:00:00 2001 From: philippe44 Date: Fri, 6 Dec 2019 04:04:27 -0800 Subject: [PATCH 02/89] jack muting - release --- components/squeezelite/output_i2s.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/components/squeezelite/output_i2s.c b/components/squeezelite/output_i2s.c index 0d4a1629..0ea78dfc 100644 --- a/components/squeezelite/output_i2s.c +++ b/components/squeezelite/output_i2s.c @@ -83,7 +83,7 @@ sure that using rate_delay would fix that #define CONFIG_SPDIF_NUM -1 #endif -typedef enum { DAC_ACTIVE = 0, DAC_STANDBY, DAC_DOWN, DAC_ANALOG_OFF, DAC_ANALOG_ON, DAC_VOLUME } dac_cmd_e; +typedef enum { DAC_ACTIVE = 0, DAC_STANDBY, DAC_DOWN, DAC_ANALOGUE_OFF, DAC_ANALOGUE_ON, DAC_VOLUME } dac_cmd_e; // must have an integer ratio with FRAME_BLOCK (see spdif comment) #define DMA_BUF_LEN 512 @@ -193,8 +193,8 @@ static const struct tas57xx_cmd_s tas57xx_cmd[] = { { 0x02, 0x00 }, // DAC_ACTIVE { 0x02, 0x10 }, // DAC_STANDBY { 0x02, 0x01 }, // DAC_DOWN - { 0x56, 0x10 }, // DAC_ANALOG_OFF - { 0x56, 0x00 }, // DAC_ANALOG_ON + { 0x56, 0x10 }, // DAC_ANALOGUE_OFF + { 0x56, 0x00 }, // DAC_ANALOGUE_ON }; static u8_t tas57_addr; @@ -247,7 +247,7 @@ void output_init_i2s(log_level level, char *device, unsigned output_buf_size, ch } // activate analogue output if needed - if (!jack_mutes_amp) dac_cmd(DAC_ANALOG_ON); + if (!jack_mutes_amp) dac_cmd(DAC_ANALOGUE_ON); #endif #ifdef CONFIG_I2S_BITS_PER_CHANNEL @@ -461,7 +461,7 @@ static void *output_thread_i2s() { if (gpio_get_level(JACK_GPIO) != jack_status) { jack_status = gpio_get_level(JACK_GPIO); if (jack_mutes_amp) { - dac_cmd(jack_status ? DAC_ANALOG_ON : DAC_ANALOG_OFF); + dac_cmd(jack_status ? DAC_ANALOGUE_ON : DAC_ANALOGUE_OFF); LOG_INFO("Changing jack status %d", jack_status); } } @@ -577,7 +577,7 @@ static void *output_thread_i2s_stats() { //return; while (running) { #ifdef TAS57xx - LOG_ERROR("Jack %d Voltage %.2fV", !gpio_get_level(JACK_GPIO), adc1_get_raw(ADC1_CHANNEL_7) / 4095. * (10+174)/10. * 1.1); + LOG_INFO("Jack %d Voltage %.2fV", !gpio_get_level(JACK_GPIO), adc1_get_raw(ADC1_CHANNEL_7) / 4095. * (10+174)/10. * 1.1); #endif LOCK; output_state state = output.state; From 17a063592fa23e64f09c43b6c214f27c0cbaa6aa Mon Sep 17 00:00:00 2001 From: philippe44 Date: Sat, 7 Dec 2019 04:11:51 -0800 Subject: [PATCH 03/89] manual handling of analogue front end for power optimization - release --- components/squeezelite/output_i2s.c | 33 +++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/components/squeezelite/output_i2s.c b/components/squeezelite/output_i2s.c index 0ea78dfc..8bfd4b33 100644 --- a/components/squeezelite/output_i2s.c +++ b/components/squeezelite/output_i2s.c @@ -162,6 +162,11 @@ static void spdif_convert(ISAMPLE_T *src, size_t frames, u32_t *dst, size_t *cou #define TAS575x 0x98 #define TAS578x 0x90 +static struct { + float sum, avg; + u16_t count; +} battery; + struct tas57xx_cmd_s { u8_t reg; u8_t value; @@ -245,9 +250,6 @@ void output_init_i2s(log_level level, char *device, unsigned output_buf_size, ch if (ret != ESP_OK) { LOG_ERROR("could not intialize TAS57xx %d", ret); } - - // activate analogue output if needed - if (!jack_mutes_amp) dac_cmd(DAC_ANALOGUE_ON); #endif #ifdef CONFIG_I2S_BITS_PER_CHANNEL @@ -378,7 +380,6 @@ void output_close_i2s(void) { */ bool output_volume_i2s(unsigned left, unsigned right) { #ifdef TAS57xx - if (!spdif) { LOG_INFO("TAS57xx volume (L:%u R:%u)", left, right); gpio_set_level(VOLUME_GPIO, left || right); @@ -386,7 +387,6 @@ bool output_volume_i2s(unsigned left, unsigned right) { #endif return false; } - /**************************************************************************************** * Write frames to the output buffer @@ -472,8 +472,17 @@ static void *output_thread_i2s() { if (state != output.state) { LOG_INFO("Output state is %d", output.state); if (output.state == OUTPUT_OFF) led_blink(LED_GREEN, 100, 2500); - else if (output.state == OUTPUT_STOPPED) led_blink(LED_GREEN, 200, 1000); - else if (output.state == OUTPUT_RUNNING) led_on(LED_GREEN); + else if (output.state == OUTPUT_STOPPED) { +#ifdef TAS57xx + dac_cmd(DAC_ANALOGUE_OFF); +#endif + led_blink(LED_GREEN, 200, 1000); + } else if (output.state == OUTPUT_RUNNING) { +#ifdef TAS57xx + if (!jack_mutes_amp || (jack_mutes_amp && jack_status)) dac_cmd(DAC_ANALOGUE_ON); +#endif + led_on(LED_GREEN); + } } state = output.state; @@ -574,11 +583,17 @@ static void *output_thread_i2s() { * Stats output thread */ static void *output_thread_i2s_stats() { - //return; + while (running) { #ifdef TAS57xx - LOG_INFO("Jack %d Voltage %.2fV", !gpio_get_level(JACK_GPIO), adc1_get_raw(ADC1_CHANNEL_7) / 4095. * (10+174)/10. * 1.1); + battery.sum += adc1_get_raw(ADC1_CHANNEL_7) / 4095. * (10+174)/10. * 1.1; + if (++battery.count == (300 * 1000) / STATS_PERIOD_MS) { + battery.avg = battery.sum / battery.count; + battery.sum = battery.count = 0; + LOG_INFO("Voltage %.2fV", battery.avg); + } #endif + LOCK; output_state state = output.state; UNLOCK; From 992c8d2679d1730d7e7d5e12c918417d95b3f7c0 Mon Sep 17 00:00:00 2001 From: Christian Herzog Date: Fri, 27 Dec 2019 20:31:09 +0100 Subject: [PATCH 04/89] add battery indicator --- components/wifi-manager/battery-0.svg | 1 + components/wifi-manager/battery-1.svg | 1 + components/wifi-manager/battery-2.svg | 1 + components/wifi-manager/battery-3.svg | 1 + components/wifi-manager/battery-4.svg | 1 + components/wifi-manager/code.js | 22 ++++++++++++++++++++++ components/wifi-manager/index.html | 1 + components/wifi-manager/style.css | 13 +++++++++++++ 8 files changed, 41 insertions(+) create mode 100644 components/wifi-manager/battery-0.svg create mode 100644 components/wifi-manager/battery-1.svg create mode 100644 components/wifi-manager/battery-2.svg create mode 100644 components/wifi-manager/battery-3.svg create mode 100644 components/wifi-manager/battery-4.svg diff --git a/components/wifi-manager/battery-0.svg b/components/wifi-manager/battery-0.svg new file mode 100644 index 00000000..2b98108f --- /dev/null +++ b/components/wifi-manager/battery-0.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/components/wifi-manager/battery-1.svg b/components/wifi-manager/battery-1.svg new file mode 100644 index 00000000..5bc3b0a7 --- /dev/null +++ b/components/wifi-manager/battery-1.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/components/wifi-manager/battery-2.svg b/components/wifi-manager/battery-2.svg new file mode 100644 index 00000000..57084430 --- /dev/null +++ b/components/wifi-manager/battery-2.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/components/wifi-manager/battery-3.svg b/components/wifi-manager/battery-3.svg new file mode 100644 index 00000000..bea94bf5 --- /dev/null +++ b/components/wifi-manager/battery-3.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/components/wifi-manager/battery-4.svg b/components/wifi-manager/battery-4.svg new file mode 100644 index 00000000..42373ea2 --- /dev/null +++ b/components/wifi-manager/battery-4.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/components/wifi-manager/code.js b/components/wifi-manager/code.js index d14c2914..b2617607 100644 --- a/components/wifi-manager/code.js +++ b/components/wifi-manager/code.js @@ -706,6 +706,24 @@ function checkStatus(){ lastMsg = msg; } } + if (data.hasOwnProperty('Voltage')) { + var voltage = data['Voltage']; + var i; + if (voltage > 0) { + if (inRange(voltage, 5.8, 6.2) || inRange(voltage, 8.8, 9.2)) { + i = 0; + } else if (inRange(voltage, 6.2, 6.8) || inRange(voltage, 9.2, 10.0)) { + i = 1; + } else if (inRange(voltage, 6.8, 7.1) || inRange(voltage, 10.0, 10.5)) { + i = 2; + } else if (inRange(voltage, 7.1, 7.5) || inRange(voltage, 10.5, 11.0)) { + i = 3; + } else { + i = 4; + } + $("#battery").html(''); + } + } blockAjax = false; }) .fail(function(xhr, ajaxOptions, thrownError) { @@ -778,3 +796,7 @@ function showMessage(message, severity) { }); }); } + +function inRange(x, min, max) { + return ((x-min)*(x-max) <= 0); +} diff --git a/components/wifi-manager/index.html b/components/wifi-manager/index.html index 6bfe8c6d..8bfe1411 100644 --- a/components/wifi-manager/index.html +++ b/components/wifi-manager/index.html @@ -24,6 +24,7 @@ +