From 26ecdf60d9387f4c111b0fe8368180c52d65f9f8 Mon Sep 17 00:00:00 2001 From: philippe44 Date: Mon, 6 Jan 2020 16:08:15 -0800 Subject: [PATCH] refactor services, increase max sockets - release --- build-scripts/16M-sdkconfig.defaults | 1 + build-scripts/I2S-16MFlash-sdkconfig.defaults | 2 +- build-scripts/I2S-4MFlash-sdkconfig.defaults | 2 +- build-scripts/NonOTA-16M-sdkconfig.defaults | 1 + .../NonOTA-I2S-16MFlash-sdkconfig.defaults | 2 +- .../NonOTA-I2S-4MFlash-sdkconfig.defaults | 2 +- .../NonOTA-SqueezeAmp-sdkconfig.defaults | 2 +- .../SqueezeAmp4MBFlash-sdkconfig.defaults | 2 +- .../SqueezeAmp8MBFlash-sdkconfig.defaults | 2 +- .../squeezelite-esp32-16M-sdkconfig.defaults | 1 + ...lite-esp32-I2S-16MFlash-sdkconfig.defaults | 2 +- ...2-I2S-4MFlash-NOAirplay-sdkconfig.defaults | 2 +- ...elite-esp32-I2S-4MFlash-sdkconfig.defaults | 2 +- ...zelite-esp32-SqueezeAmp-sdkconfig.defaults | 2 +- components/io/component.mk | 10 ---- components/raop/raop_sink.c | 2 +- components/{io => services}/CMakeLists.txt | 0 .../audio_controls.c | 4 +- .../audio_controls.h | 0 components/services/battery.c | 57 +++++++++++++++++++ components/services/battery.h | 10 ++++ .../{audio_controls => services}/buttons.c | 2 +- .../{audio_controls => services}/buttons.h | 0 .../{audio_controls => services}/component.mk | 0 components/{io => services}/led.c | 4 ++ components/{io => services}/led.h | 0 components/services/monitor.c | 44 ++++++++++++++ components/services/monitor.h | 22 +++++++ components/services/services.c | 27 +++++++++ components/squeezelite/component.mk | 2 +- components/squeezelite/controls.c | 4 +- components/squeezelite/controls.h | 8 +++ components/squeezelite/output_i2s.c | 24 -------- components/wifi-manager/wifi_manager.c | 2 +- main/esp_app_main.c | 14 +++-- 35 files changed, 204 insertions(+), 57 deletions(-) delete mode 100644 components/io/component.mk rename components/{io => services}/CMakeLists.txt (100%) rename components/{audio_controls => services}/audio_controls.c (94%) rename components/{audio_controls => services}/audio_controls.h (100%) create mode 100644 components/services/battery.c create mode 100644 components/services/battery.h rename components/{audio_controls => services}/buttons.c (99%) rename components/{audio_controls => services}/buttons.h (100%) rename components/{audio_controls => services}/component.mk (100%) rename components/{io => services}/led.c (98%) rename components/{io => services}/led.h (100%) create mode 100644 components/services/monitor.c create mode 100644 components/services/monitor.h create mode 100644 components/services/services.c create mode 100644 components/squeezelite/controls.h diff --git a/build-scripts/16M-sdkconfig.defaults b/build-scripts/16M-sdkconfig.defaults index 7cbece92..21c797ea 100644 --- a/build-scripts/16M-sdkconfig.defaults +++ b/build-scripts/16M-sdkconfig.defaults @@ -121,6 +121,7 @@ CONFIG_ESP32_PHY_MAX_WIFI_TX_POWER=20 CONFIG_ESP32_PHY_MAX_TX_POWER=20 CONFIG_FREERTOS_HZ=100 CONFIG_LWIP_TCPIP_RECVMBOX_SIZE=32 +CONFIG_LWIP_MAX_SOCKETS=16 CONFIG_LWIP_NETIF_LOOPBACK=y CONFIG_LWIP_TCP_MSL=60000 CONFIG_LWIP_TCP_SND_BUF_DEFAULT=8192 diff --git a/build-scripts/I2S-16MFlash-sdkconfig.defaults b/build-scripts/I2S-16MFlash-sdkconfig.defaults index 9947eb19..f982c87c 100644 --- a/build-scripts/I2S-16MFlash-sdkconfig.defaults +++ b/build-scripts/I2S-16MFlash-sdkconfig.defaults @@ -614,7 +614,7 @@ CONFIG_LWIP_LOCAL_HOSTNAME="espressif" CONFIG_LWIP_TIMERS_ONDEMAND=y -CONFIG_LWIP_MAX_SOCKETS=10 +CONFIG_LWIP_MAX_SOCKETS=16 CONFIG_LWIP_SO_REUSE=y CONFIG_LWIP_SO_REUSE_RXTOALL=y diff --git a/build-scripts/I2S-4MFlash-sdkconfig.defaults b/build-scripts/I2S-4MFlash-sdkconfig.defaults index b7a60ac4..2d3a107e 100644 --- a/build-scripts/I2S-4MFlash-sdkconfig.defaults +++ b/build-scripts/I2S-4MFlash-sdkconfig.defaults @@ -613,7 +613,7 @@ CONFIG_LWIP_LOCAL_HOSTNAME="espressif" CONFIG_LWIP_TIMERS_ONDEMAND=y -CONFIG_LWIP_MAX_SOCKETS=10 +CONFIG_LWIP_MAX_SOCKETS=16 CONFIG_LWIP_SO_REUSE=y CONFIG_LWIP_SO_REUSE_RXTOALL=y diff --git a/build-scripts/NonOTA-16M-sdkconfig.defaults b/build-scripts/NonOTA-16M-sdkconfig.defaults index 8c058654..ce26095f 100644 --- a/build-scripts/NonOTA-16M-sdkconfig.defaults +++ b/build-scripts/NonOTA-16M-sdkconfig.defaults @@ -117,6 +117,7 @@ CONFIG_ESP32_PHY_MAX_WIFI_TX_POWER=20 CONFIG_ESP32_PHY_MAX_TX_POWER=20 CONFIG_FREERTOS_HZ=100 CONFIG_LWIP_TCPIP_RECVMBOX_SIZE=32 +CONFIG_LWIP_MAX_SOCKETS=16 CONFIG_LWIP_NETIF_LOOPBACK=y CONFIG_LWIP_TCP_MSL=60000 CONFIG_LWIP_TCP_SND_BUF_DEFAULT=8192 diff --git a/build-scripts/NonOTA-I2S-16MFlash-sdkconfig.defaults b/build-scripts/NonOTA-I2S-16MFlash-sdkconfig.defaults index 67b1997b..5283b14d 100644 --- a/build-scripts/NonOTA-I2S-16MFlash-sdkconfig.defaults +++ b/build-scripts/NonOTA-I2S-16MFlash-sdkconfig.defaults @@ -614,7 +614,7 @@ CONFIG_LWIP_LOCAL_HOSTNAME="espressif" CONFIG_LWIP_TIMERS_ONDEMAND=y -CONFIG_LWIP_MAX_SOCKETS=10 +CONFIG_LWIP_MAX_SOCKETS=16 CONFIG_LWIP_SO_REUSE=y CONFIG_LWIP_SO_REUSE_RXTOALL=y diff --git a/build-scripts/NonOTA-I2S-4MFlash-sdkconfig.defaults b/build-scripts/NonOTA-I2S-4MFlash-sdkconfig.defaults index c5776c2b..6a3e3196 100644 --- a/build-scripts/NonOTA-I2S-4MFlash-sdkconfig.defaults +++ b/build-scripts/NonOTA-I2S-4MFlash-sdkconfig.defaults @@ -613,7 +613,7 @@ CONFIG_LWIP_LOCAL_HOSTNAME="espressif" CONFIG_LWIP_TIMERS_ONDEMAND=y -CONFIG_LWIP_MAX_SOCKETS=10 +CONFIG_LWIP_MAX_SOCKETS=16 CONFIG_LWIP_SO_REUSE=y CONFIG_LWIP_SO_REUSE_RXTOALL=y diff --git a/build-scripts/NonOTA-SqueezeAmp-sdkconfig.defaults b/build-scripts/NonOTA-SqueezeAmp-sdkconfig.defaults index 88bf4454..37e8ad92 100644 --- a/build-scripts/NonOTA-SqueezeAmp-sdkconfig.defaults +++ b/build-scripts/NonOTA-SqueezeAmp-sdkconfig.defaults @@ -602,7 +602,7 @@ CONFIG_LWIP_LOCAL_HOSTNAME="espressif" CONFIG_LWIP_TIMERS_ONDEMAND=y -CONFIG_LWIP_MAX_SOCKETS=10 +CONFIG_LWIP_MAX_SOCKETS=16 CONFIG_LWIP_SO_REUSE=y CONFIG_LWIP_SO_REUSE_RXTOALL=y diff --git a/build-scripts/SqueezeAmp4MBFlash-sdkconfig.defaults b/build-scripts/SqueezeAmp4MBFlash-sdkconfig.defaults index bbf71332..087d38c4 100644 --- a/build-scripts/SqueezeAmp4MBFlash-sdkconfig.defaults +++ b/build-scripts/SqueezeAmp4MBFlash-sdkconfig.defaults @@ -602,7 +602,7 @@ CONFIG_LWIP_LOCAL_HOSTNAME="espressif" CONFIG_LWIP_TIMERS_ONDEMAND=y -CONFIG_LWIP_MAX_SOCKETS=10 +CONFIG_LWIP_MAX_SOCKETS=16 CONFIG_LWIP_SO_REUSE=y CONFIG_LWIP_SO_REUSE_RXTOALL=y diff --git a/build-scripts/SqueezeAmp8MBFlash-sdkconfig.defaults b/build-scripts/SqueezeAmp8MBFlash-sdkconfig.defaults index ea8d44de..36c9c8cb 100644 --- a/build-scripts/SqueezeAmp8MBFlash-sdkconfig.defaults +++ b/build-scripts/SqueezeAmp8MBFlash-sdkconfig.defaults @@ -295,7 +295,7 @@ CONFIG_LOG_DEFAULT_LEVEL=3 CONFIG_LOG_COLORS=y CONFIG_LWIP_LOCAL_HOSTNAME="espressif" CONFIG_LWIP_TIMERS_ONDEMAND=y -CONFIG_LWIP_MAX_SOCKETS=10 +CONFIG_LWIP_MAX_SOCKETS=16 CONFIG_LWIP_SO_REUSE=y CONFIG_LWIP_SO_REUSE_RXTOALL=y CONFIG_LWIP_ESP_GRATUITOUS_ARP=y diff --git a/build-scripts/squeezelite-esp32-16M-sdkconfig.defaults b/build-scripts/squeezelite-esp32-16M-sdkconfig.defaults index 262f5568..7af4b57e 100644 --- a/build-scripts/squeezelite-esp32-16M-sdkconfig.defaults +++ b/build-scripts/squeezelite-esp32-16M-sdkconfig.defaults @@ -115,6 +115,7 @@ CONFIG_ESP32_PHY_MAX_WIFI_TX_POWER=20 CONFIG_ESP32_PHY_MAX_TX_POWER=20 CONFIG_FREERTOS_HZ=100 CONFIG_LWIP_TCPIP_RECVMBOX_SIZE=32 +CONFIG_LWIP_MAX_SOCKETS=16 CONFIG_LWIP_NETIF_LOOPBACK=y CONFIG_LWIP_TCP_MSL=60000 CONFIG_LWIP_TCP_SND_BUF_DEFAULT=8192 diff --git a/build-scripts/squeezelite-esp32-I2S-16MFlash-sdkconfig.defaults b/build-scripts/squeezelite-esp32-I2S-16MFlash-sdkconfig.defaults index daecfd87..8c15698c 100644 --- a/build-scripts/squeezelite-esp32-I2S-16MFlash-sdkconfig.defaults +++ b/build-scripts/squeezelite-esp32-I2S-16MFlash-sdkconfig.defaults @@ -613,7 +613,7 @@ CONFIG_LWIP_LOCAL_HOSTNAME="espressif" CONFIG_LWIP_TIMERS_ONDEMAND=y -CONFIG_LWIP_MAX_SOCKETS=10 +CONFIG_LWIP_MAX_SOCKETS=16 CONFIG_LWIP_SO_REUSE=y CONFIG_LWIP_SO_REUSE_RXTOALL=y diff --git a/build-scripts/squeezelite-esp32-I2S-4MFlash-NOAirplay-sdkconfig.defaults b/build-scripts/squeezelite-esp32-I2S-4MFlash-NOAirplay-sdkconfig.defaults index 2bf90186..7165d208 100644 --- a/build-scripts/squeezelite-esp32-I2S-4MFlash-NOAirplay-sdkconfig.defaults +++ b/build-scripts/squeezelite-esp32-I2S-4MFlash-NOAirplay-sdkconfig.defaults @@ -608,7 +608,7 @@ CONFIG_LWIP_LOCAL_HOSTNAME="espressif" CONFIG_LWIP_TIMERS_ONDEMAND=y -CONFIG_LWIP_MAX_SOCKETS=10 +CONFIG_LWIP_MAX_SOCKETS=16 CONFIG_LWIP_SO_REUSE=y CONFIG_LWIP_SO_REUSE_RXTOALL=y diff --git a/build-scripts/squeezelite-esp32-I2S-4MFlash-sdkconfig.defaults b/build-scripts/squeezelite-esp32-I2S-4MFlash-sdkconfig.defaults index 0ecf2098..add723cc 100644 --- a/build-scripts/squeezelite-esp32-I2S-4MFlash-sdkconfig.defaults +++ b/build-scripts/squeezelite-esp32-I2S-4MFlash-sdkconfig.defaults @@ -637,7 +637,7 @@ CONFIG_LWIP_LOCAL_HOSTNAME="espressif" CONFIG_LWIP_TIMERS_ONDEMAND=y -CONFIG_LWIP_MAX_SOCKETS=10 +CONFIG_LWIP_MAX_SOCKETS=16 CONFIG_LWIP_SO_REUSE=y CONFIG_LWIP_SO_REUSE_RXTOALL=y diff --git a/build-scripts/squeezelite-esp32-SqueezeAmp-sdkconfig.defaults b/build-scripts/squeezelite-esp32-SqueezeAmp-sdkconfig.defaults index b551dd65..86a5244d 100644 --- a/build-scripts/squeezelite-esp32-SqueezeAmp-sdkconfig.defaults +++ b/build-scripts/squeezelite-esp32-SqueezeAmp-sdkconfig.defaults @@ -601,7 +601,7 @@ CONFIG_LWIP_LOCAL_HOSTNAME="espressif" CONFIG_LWIP_TIMERS_ONDEMAND=y -CONFIG_LWIP_MAX_SOCKETS=10 +CONFIG_LWIP_MAX_SOCKETS=16 CONFIG_LWIP_SO_REUSE=y CONFIG_LWIP_SO_REUSE_RXTOALL=y diff --git a/components/io/component.mk b/components/io/component.mk deleted file mode 100644 index e0e9f4c1..00000000 --- a/components/io/component.mk +++ /dev/null @@ -1,10 +0,0 @@ -# -# Component Makefile -# -# This Makefile should, at the very least, just include $(SDK_PATH)/Makefile. By default, -# this will take the sources in the src/ directory, compile them and link them into -# lib(subdirectory_name).a in the build directory. This behaviour is entirely configurable, -# please read the SDK documents if you need to do this. -# - -COMPONENT_ADD_INCLUDEDIRS := . diff --git a/components/raop/raop_sink.c b/components/raop/raop_sink.c index ff1ee484..7dd9c336 100644 --- a/components/raop/raop_sink.c +++ b/components/raop/raop_sink.c @@ -111,7 +111,7 @@ void raop_sink_init(raop_cmd_cb_t cmd_cb, raop_data_cb_t data_cb) { ESP_ERROR_CHECK( mdns_init() ); ESP_ERROR_CHECK( mdns_hostname_set(hostname) ); - char * sink_name_buffer= (char *)config_alloc_get(NVS_TYPE_STR,"AirPlay_name"); + char * sink_name_buffer= (char *)config_alloc_get(NVS_TYPE_STR,"airplay_name"); if(sink_name_buffer != NULL){ memset(sink_name, 0x00, sizeof(sink_name)); strncpy(sink_name,sink_name_buffer,sizeof(sink_name)-1 ); diff --git a/components/io/CMakeLists.txt b/components/services/CMakeLists.txt similarity index 100% rename from components/io/CMakeLists.txt rename to components/services/CMakeLists.txt diff --git a/components/audio_controls/audio_controls.c b/components/services/audio_controls.c similarity index 94% rename from components/audio_controls/audio_controls.c rename to components/services/audio_controls.c index 1e5a1cb5..7d3029fb 100644 --- a/components/audio_controls/audio_controls.c +++ b/components/services/audio_controls.c @@ -27,7 +27,7 @@ #include "buttons.h" #include "audio_controls.h" -static const char * TAG = "audio_controls"; +static const char * TAG = "audio controls"; static actrls_t default_controls, current_controls; @@ -88,7 +88,7 @@ void down(void *id, button_event_e event, button_press_e press, bool longpress) */ void actrls_init(int n, const actrls_config_t *config) { for (int i = 0; i < n; i++) { - button_create(config + i, config[i].gpio, config[i].type, config[i].pull, control_handler, config[i].long_press, config[i].shifter_gpio); + button_create((void*) (config + i), config[i].gpio, config[i].type, config[i].pull, control_handler, config[i].long_press, config[i].shifter_gpio); } } diff --git a/components/audio_controls/audio_controls.h b/components/services/audio_controls.h similarity index 100% rename from components/audio_controls/audio_controls.h rename to components/services/audio_controls.h diff --git a/components/services/battery.c b/components/services/battery.c new file mode 100644 index 00000000..5ad36608 --- /dev/null +++ b/components/services/battery.c @@ -0,0 +1,57 @@ +/* + This example code is in the Public Domain (or CC0 licensed, at your option.) + + Unless required by applicable law or agreed to in writing, this + software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR + CONDITIONS OF ANY KIND, either express or implied. +*/ + +#include +#include +#include +#include +#include "freertos/FreeRTOS.h" +#include "freertos/timers.h" +#include "esp_system.h" +#include "esp_log.h" +#include "driver/adc.h" +#include "battery.h" + +#define BATTERY_TIMER (10*1000) + +static const char TAG[] = "battery"; + +#ifdef CONFIG_SQUEEZEAMP +static struct { + float sum, avg; + int count; + TimerHandle_t timer; +} battery; +#endif + +/**************************************************************************************** + * + */ +static void battery_callback(TimerHandle_t xTimer) { + battery.sum += adc1_get_raw(ADC1_CHANNEL_7) / 4095. * (10+174)/10. * 1.1; + if (++battery.count == 30) { + battery.avg = battery.sum / battery.count; + battery.sum = battery.count = 0; + ESP_LOGI(TAG, "Voltage %.2fV", battery.avg); + } +} + +/**************************************************************************************** + * + */ +void battery_svc_init(void) { +#ifdef CONFIG_SQUEEZEAMP + ESP_LOGI(TAG, "Initializing battery"); + + adc1_config_width(ADC_WIDTH_BIT_12); + adc1_config_channel_atten(ADC1_CHANNEL_7, ADC_ATTEN_DB_0); + + battery.timer = xTimerCreate("battery", BATTERY_TIMER / portTICK_RATE_MS, pdTRUE, NULL, battery_callback); + xTimerStart(battery.timer, portMAX_DELAY); +#endif +} diff --git a/components/services/battery.h b/components/services/battery.h new file mode 100644 index 00000000..c1b8dc5b --- /dev/null +++ b/components/services/battery.h @@ -0,0 +1,10 @@ +/* + This example code is in the Public Domain (or CC0 licensed, at your option.) + + Unless required by applicable law or agreed to in writing, this + software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR + CONDITIONS OF ANY KIND, either express or implied. +*/ + +#pragma once + diff --git a/components/audio_controls/buttons.c b/components/services/buttons.c similarity index 99% rename from components/audio_controls/buttons.c rename to components/services/buttons.c index 821af4c2..a2ce1cb5 100644 --- a/components/audio_controls/buttons.c +++ b/components/services/buttons.c @@ -32,7 +32,7 @@ #include "driver/gpio.h" #include "buttons.h" -static const char * TAG = "audio_controls"; +static const char * TAG = "buttons"; static int n_buttons = 0; diff --git a/components/audio_controls/buttons.h b/components/services/buttons.h similarity index 100% rename from components/audio_controls/buttons.h rename to components/services/buttons.h diff --git a/components/audio_controls/component.mk b/components/services/component.mk similarity index 100% rename from components/audio_controls/component.mk rename to components/services/component.mk diff --git a/components/io/led.c b/components/services/led.c similarity index 98% rename from components/io/led.c rename to components/services/led.c index 065a8acf..bddb882e 100644 --- a/components/io/led.c +++ b/components/services/led.c @@ -33,6 +33,10 @@ static struct led_s { TimerHandle_t timer; } leds[MAX_LED]; +void led_svc_init(void) { + ESP_LOGI(TAG, "Initializing led"); +} + static void vCallbackFunction( TimerHandle_t xTimer ) { struct led_s *led = (struct led_s*) pvTimerGetTimerID (xTimer); diff --git a/components/io/led.h b/components/services/led.h similarity index 100% rename from components/io/led.h rename to components/services/led.h diff --git a/components/services/monitor.c b/components/services/monitor.c new file mode 100644 index 00000000..b17f102d --- /dev/null +++ b/components/services/monitor.c @@ -0,0 +1,44 @@ +/* + This example code is in the Public Domain (or CC0 licensed, at your option.) + + Unless required by applicable law or agreed to in writing, this + software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR + CONDITIONS OF ANY KIND, either express or implied. +*/ + +#include +#include +#include +#include +#include "freertos/FreeRTOS.h" +#include "freertos/timers.h" +#include "esp_system.h" +#include "esp_log.h" +#include "monitor.h" + +#define MONITOR_TIMER (10*1000) + +static const char TAG[] = "monitor"; + +static TimerHandle_t monitor_timer; + +/**************************************************************************************** + * + */ +static void monitor_callback(TimerHandle_t xTimer) { + ESP_LOGI(TAG, "Heap internal:%zu (min:%zu) external:%zu (min:%zu)", + heap_caps_get_free_size(MALLOC_CAP_INTERNAL), + heap_caps_get_minimum_free_size(MALLOC_CAP_INTERNAL), + heap_caps_get_free_size(MALLOC_CAP_SPIRAM), + heap_caps_get_minimum_free_size(MALLOC_CAP_SPIRAM)); +} + +/**************************************************************************************** + * + */ +void monitor_svc_init(void) { + ESP_LOGI(TAG, "Initializing monitoring"); + + monitor_timer = xTimerCreate("monitor", MONITOR_TIMER / portTICK_RATE_MS, pdTRUE, NULL, monitor_callback); + xTimerStart(monitor_timer, portMAX_DELAY); +} diff --git a/components/services/monitor.h b/components/services/monitor.h new file mode 100644 index 00000000..f6712855 --- /dev/null +++ b/components/services/monitor.h @@ -0,0 +1,22 @@ +/* + * Squeezelite for esp32 + * + * (c) Philippe G. 2019, philippe_44@outlook.com + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +#pragma once + diff --git a/components/services/services.c b/components/services/services.c new file mode 100644 index 00000000..4704fe2d --- /dev/null +++ b/components/services/services.c @@ -0,0 +1,27 @@ +/* + This example code is in the Public Domain (or CC0 licensed, at your option.) + + Unless required by applicable law or agreed to in writing, this + software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR + CONDITIONS OF ANY KIND, either express or implied. +*/ + +#include +#include "battery.h" +#include "led.h" +#include "monitor.h" + +extern void battery_svc_init(void); +extern void monitor_svc_init(void); +extern void led_svc_init(void); + +static const char TAG[] = "services"; + +/**************************************************************************************** + * + */ +void services_init(void) { + battery_svc_init(); + monitor_svc_init(); + led_svc_init(); +} diff --git a/components/squeezelite/component.mk b/components/squeezelite/component.mk index b5e1d015..ef59f34e 100644 --- a/components/squeezelite/component.mk +++ b/components/squeezelite/component.mk @@ -15,7 +15,7 @@ CFLAGS += -O3 -DLINKALL -DLOOPBACK -DNO_FAAD -DRESAMPLE16 -DEMBEDDED -DTREMOR_ON -I$(COMPONENT_PATH)/../codecs/inc/opusfile \ -I$(COMPONENT_PATH)/../driver_bt \ -I$(COMPONENT_PATH)/../raop \ - -I$(COMPONENT_PATH)/../audio_controls + -I$(COMPONENT_PATH)/../services # -I$(COMPONENT_PATH)/../codecs/inc/faad2 diff --git a/components/squeezelite/controls.c b/components/squeezelite/controls.c index 924541c4..c257d6ed 100644 --- a/components/squeezelite/controls.c +++ b/components/squeezelite/controls.c @@ -69,7 +69,7 @@ static void lms_next(void) { cli_send_cmd("button fwd"); } -const static actrls_t controls = { +const actrls_t LMS_controls = { lms_volume_up, lms_volume_down, // volume up, volume down lms_toggle, lms_play, // toggle, play lms_pause, lms_stop, // pause, stop @@ -121,7 +121,7 @@ static void notify(in_addr_t ip, u16_t hport, u16_t cport) { */ void cli_controls_init(void) { get_mac(mac); - actrls_set_default(controls); + actrls_set_default(LMS_controls); chained_notify = server_notify; server_notify = notify; } \ No newline at end of file diff --git a/components/squeezelite/controls.h b/components/squeezelite/controls.h new file mode 100644 index 00000000..4ea04818 --- /dev/null +++ b/components/squeezelite/controls.h @@ -0,0 +1,8 @@ +#ifndef CONTROLS_H +#define CONTROLS_H + +#include "audio_controls.h" + +const extern actrls_t LMS_controls[]; + +#endif // CONTROLS_H diff --git a/components/squeezelite/output_i2s.c b/components/squeezelite/output_i2s.c index 8c69bc9d..cfc669d0 100644 --- a/components/squeezelite/output_i2s.c +++ b/components/squeezelite/output_i2s.c @@ -162,11 +162,6 @@ 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; @@ -583,18 +578,7 @@ static void *output_thread_i2s() { * Stats output thread */ static void *output_thread_i2s_stats() { - int memory_count = 0; - while (running) { -#ifdef TAS57xx - 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; @@ -618,14 +602,6 @@ static void *output_thread_i2s_stats() { LOG_INFO(" ----------+----------+-----------+-----------+"); RESET_ALL_MIN_MAX; } - if (loglevel == lDEBUG || !memory_count--) { - LOG_INFO("Heap internal:%zu (min:%zu) external:%zu (min:%zu)", - heap_caps_get_free_size(MALLOC_CAP_INTERNAL), - heap_caps_get_minimum_free_size(MALLOC_CAP_INTERNAL), - heap_caps_get_free_size(MALLOC_CAP_SPIRAM), - heap_caps_get_minimum_free_size(MALLOC_CAP_SPIRAM)); - memory_count = (60*1000) / STATS_PERIOD_MS; - } usleep(STATS_PERIOD_MS *1000); } return NULL; diff --git a/components/wifi-manager/wifi_manager.c b/components/wifi-manager/wifi_manager.c index fec346e6..f4df961f 100644 --- a/components/wifi-manager/wifi_manager.c +++ b/components/wifi-manager/wifi_manager.c @@ -1093,7 +1093,7 @@ void wifi_manager( void * pvParameters ){ BaseType_t xStatus; EventBits_t uxBits; uint8_t retries = 0; - esp_err_t err=ESP_OK; + /* start http server */ http_server_start(); diff --git a/main/esp_app_main.c b/main/esp_app_main.c index 76689418..0578964b 100644 --- a/main/esp_app_main.c +++ b/main/esp_app_main.c @@ -76,6 +76,8 @@ static bool bWifiConnected=false; extern const uint8_t server_cert_pem_start[] asm("_binary_github_pem_start"); extern const uint8_t server_cert_pem_end[] asm("_binary_github_pem_end"); +extern void services_init(void); + static const actrls_config_t board_1[] = { // normal long shifted long shifted { 4, BUTTON_LOW, true, 1000, -1, {ACTRLS_VOLUP, ACTRLS_NONE}, {ACTRLS_PREV, ACTRLS_NONE}, {ACTRLS_NONE, ACTRLS_NONE}, {ACTRLS_NONE, ACTRLS_NONE} }, @@ -393,15 +395,19 @@ void app_main() bypass_wifi_manager=(strcmp(bypass_wm,"1")==0 ||strcasecmp(bypass_wm,"y")==0); } + services_init(); + ESP_LOGD(TAG,"Configuring Green led"); led_config(LED_GREEN, LED_GREEN_GPIO, 0); ESP_LOGD(TAG,"Configuring Red led"); led_config(LED_RED, LED_RED_GPIO, 0); - char *board_index = config_alloc_get_default(NVS_TYPE_STR, "board_index", "0", 0); - ESP_LOGD(TAG,"Initializing audio control buttons index %u", atoi(board_index)); - actrls_init(board_configs[atoi(board_index)].n, (actrls_config_t*) board_configs[atoi(board_index)].config); - free(board_index); + char *board_index = config_alloc_get_default(NVS_TYPE_STR, "board_index", NULL, 0); + if (board_index) { + ESP_LOGD(TAG,"Initializing audio control buttons index %u", atoi(board_index)); + actrls_init(board_configs[atoi(board_index)].n, (actrls_config_t*) board_configs[atoi(board_index)].config); + free(board_index); + } /* start the wifi manager */ ESP_LOGD(TAG,"Blinking led");