refactor step 1 - BT

This commit is contained in:
philippe44
2019-06-28 23:08:46 -07:00
parent 0e3bc18748
commit 6c5ce6ba80
21 changed files with 452 additions and 1120 deletions

View File

@@ -1,54 +1,32 @@
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include "esp_log.h"
#include "esp_system.h"
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include "esp_log.h"
#include "esp_bt.h"
#include "esp_bt_device.h"
#include "esp_bt_main.h"
#include "esp_gap_bt_api.h"
#include "esp_a2dp_api.h"
#include "esp_avrc_api.h"
#include "esp_console.h"
#include "esp_pthread.h"
#include "esp_system.h"
#include "esp_wifi.h"
#include "freertos/FreeRTOS.h"
#include "freertos/event_groups.h"
#include "freertos/task.h"
#include "freertos/timers.h"
#include "nvs.h"
#include "nvs_flash.h"
#include "nvs_utilities.h"
#include "pthread.h"
#include "string.h"
//#include "esp_event.h"
#include "sys/socket.h"
#include <signal.h>
#include <signal.h>
#include "platform_esp32.h"
#include "../../main/squeezelite.h"
#include "argtable3/argtable3.h"
#define STATS_REPORT_DELAY_MS 15000
#include "bt_app_core.h"
#include "platform_esp32.h"
static const char * TAG = "platform";
extern char * get_output_state_desc(output_state state);
extern struct outputstate output;
extern struct buffer *outputbuf;
extern struct buffer *streambuf;
extern uint8_t * btout;
time_t disconnect_time=0;
#define LOCK_S pthread_mutex_lock(&(streambuf->mutex))
#define UNLOCK_S pthread_mutex_unlock(&(streambuf->mutex))
extern int32_t output_bt_data(uint8_t *data, int32_t len);
extern void output_bt_tick(void);
extern char* output_state_str(void);
extern bool output_stopped(void);
#define LOCK pthread_mutex_lock(&(outputbuf->mutex))
#define UNLOCK pthread_mutex_unlock(&(outputbuf->mutex))
int64_t connecting_timeout = 0;
static const char * art_a2dp_connected[]={"\n",
@@ -76,34 +54,8 @@ static void bt_app_av_state_connecting(uint16_t event, void *param);
#define A2DP_TIMER_INIT connecting_timeout = esp_timer_get_time() +(CONFIG_A2DP_CONNECT_TIMEOUT_MS * 1000)
#define IS_A2DP_TIMER_OVER esp_timer_get_time() >= connecting_timeout
#define FRAME_TO_BYTES(f) f*BYTES_PER_FRAME
#define BYTES_TO_FRAME(b) b/BYTES_PER_FRAME
#define RESET_ALL_MIN_MAX RESET_MIN_MAX(req); RESET_MIN_MAX(rec); RESET_MIN_MAX(bt);RESET_MIN_MAX(under); RESET_MIN_MAX_DURATION(stream_buf); RESET_MIN_MAX_DURATION(lock_out_time)
DECLARE_MIN_MAX(stream_buf);
DECLARE_MIN_MAX(req);
DECLARE_MIN_MAX(rec);
DECLARE_MIN_MAX(bt);
DECLARE_MIN_MAX(under);
DECLARE_MIN_MAX_DURATION(lock_out_time);
static void filter_inquiry_scan_result(esp_bt_gap_cb_param_t *param);
void get_mac(u8_t mac[]) {
esp_read_mac(mac, ESP_MAC_WIFI_STA);
}
_sig_func_ptr signal(int sig, _sig_func_ptr func) {
return NULL;
}
void *audio_calloc(size_t nmemb, size_t size) {
return calloc(nmemb, size);
}
/* event for handler "bt_av_hdl_stack_up */
enum {
BT_APP_EVT_STACK_UP = 0,
@@ -181,16 +133,12 @@ static struct {
void hal_bluetooth_init(const char * options)
{
ESP_LOGD(TAG,"Initializing Bluetooth HAL");
//CONFIG_A2DP_SINK_NAME
//CONFIG_A2DP_CONTROL_DELAY_MS
//CONFIG_A2DP_CONNECT_TIMEOUT_MS
squeezelite_args.sink_name = arg_str1("n", "name", "<sink name>", "the name of the bluetooth to connect to");
squeezelite_args.control_delay = arg_int0("d", "delay", "<control delay>", "the delay between each pass at the A2DP control loop");
squeezelite_args.connect_timeout_delay = arg_int0("t","timeout", "<timeout>", "the timeout duration for connecting to the A2DP sink");
squeezelite_args.end = arg_end(2);
ESP_LOGD(TAG,"Copying parameters");
char * opts = strdup(options);
char **argv = malloc(sizeof(char**)*15);
@@ -280,42 +228,7 @@ void hal_bluetooth_init(const char * options)
esp_bt_gap_set_pin(pin_type, 0, pin_code);
}
static int32_t bt_app_a2d_data_cb(uint8_t *data, int32_t len)
{
int32_t avail_data=0,wanted_len=0, start_timer=0;
if (len < 0 || data == NULL ) {
return 0;
}
btout=data;
// This is how the BTC layer calculates the number of bytes to
// for us to send. (BTC_SBC_DEC_PCM_DATA_LEN * sizeof(OI_INT16) - availPcmBytes
wanted_len=len;
SET_MIN_MAX(len,req);
TIME_MEASUREMENT_START(start_timer);
LOCK;
output.device_frames = 0; // todo: check if this is the right way do to this.
output.updated = gettime_ms();
output.frames_played_dmp = output.frames_played;
SET_MIN_MAX_SIZED(_buf_used(outputbuf),bt,outputbuf->size);
do {
avail_data = _output_frames( wanted_len/BYTES_PER_FRAME )*BYTES_PER_FRAME; // Keep the transfer buffer full
wanted_len-=avail_data;
} while (wanted_len > 0 && avail_data != 0);
if(wanted_len>0)
{
SET_MIN_MAX(wanted_len, under);
}
UNLOCK;
SET_MIN_MAX(TIME_MEASUREMENT_GET(start_timer),lock_out_time);
SET_MIN_MAX((len-wanted_len), rec);
TIME_MEASUREMENT_START(start_timer);
output_bt_check_buffer();
return len-wanted_len;
}
static void bt_app_a2d_cb(esp_a2d_cb_event_t event, esp_a2d_cb_param_t *param)
{
bt_app_work_dispatch(bt_app_av_sm_hdlr, event, param, sizeof(esp_a2d_cb_param_t), NULL);
@@ -415,10 +328,10 @@ static void bt_app_av_sm_hdlr(uint16_t event, void *param)
{
switch (s_a2d_state) {
case APP_AV_STATE_DISCOVERING:
ESP_LOGV(TAG,"state %s, evt 0x%x, output state: %s", APP_AV_STATE_DESC[s_a2d_state], event, get_output_state_desc(output.state));
ESP_LOGV(TAG,"state %s, evt 0x%x, output state: %s", APP_AV_STATE_DESC[s_a2d_state], event, output_state_str());
break;
case APP_AV_STATE_DISCOVERED:
ESP_LOGV(TAG,"state %s, evt 0x%x, output state: %s", APP_AV_STATE_DESC[s_a2d_state], event, get_output_state_desc(output.state));
ESP_LOGV(TAG,"state %s, evt 0x%x, output state: %s", APP_AV_STATE_DESC[s_a2d_state], event, output_state_str());
break;
case APP_AV_STATE_UNCONNECTED:
bt_app_av_state_unconnected(event, param);
@@ -562,7 +475,6 @@ static void filter_inquiry_scan_result(esp_bt_gap_cb_param_t *param)
}
}
static void bt_av_hdl_stack_evt(uint16_t event, void *p_param)
{
@@ -579,7 +491,7 @@ static void bt_av_hdl_stack_evt(uint16_t event, void *p_param)
/* initialize A2DP source */
esp_a2d_register_callback(&bt_app_a2d_cb);
esp_a2d_source_register_data_callback(bt_app_a2d_data_cb);
esp_a2d_source_register_data_callback(&output_bt_data);
esp_a2d_source_init();
/* set discoverable and connectable mode */
@@ -605,39 +517,15 @@ static void bt_av_hdl_stack_evt(uint16_t event, void *p_param)
}
}
#ifdef BTAUDIO
bool test_open(const char *device, unsigned rates[], bool userdef_rates) {
// running_test = true;
// while(running_test)
// {
// // wait until BT playback has started
// // this will allow querying the sample rate
// usleep(100000);
// }
memset(rates, 0, MAX_SUPPORTED_SAMPLERATES * sizeof(unsigned));
if (!strcmp(device, "BT")) {
rates[0] = 44100;
} else {
unsigned _rates[] = { 96000, 88200, 48000, 44100, 32000, 0 };
memcpy(rates, _rates, sizeof(_rates));
}
return true;
}
#endif
static void bt_app_av_media_proc(uint16_t event, void *param)
{
esp_a2d_cb_param_t *a2d = NULL;
LOCK;
output_state out_state=output.state;
UNLOCK;
switch (s_media_state) {
case APP_AV_MEDIA_STATE_IDLE: {
if (event == BT_APP_HEART_BEAT_EVT) {
if(out_state > OUTPUT_STOPPED)
if(!output_stopped())
{
ESP_LOGI(TAG,"Output state is %s, Checking if A2DP is ready.", get_output_state_desc(out_state));
ESP_LOGI(TAG,"Output state is %s, Checking if A2DP is ready.", output_state_str());
esp_a2d_media_ctrl(ESP_A2D_MEDIA_CTRL_CHECK_SRC_RDY);
}
@@ -671,40 +559,12 @@ static void bt_app_av_media_proc(uint16_t event, void *param)
}
case APP_AV_MEDIA_STATE_STARTED: {
if (event == BT_APP_HEART_BEAT_EVT) {
if(out_state <= OUTPUT_STOPPED) {
ESP_LOGI(TAG,"Output state is %s. Stopping a2dp media ...", get_output_state_desc(out_state));
if(output_stopped()) {
ESP_LOGI(TAG,"Output state is %s. Stopping a2dp media ...", output_state_str());
s_media_state = APP_AV_MEDIA_STATE_STOPPING;
esp_a2d_media_ctrl(ESP_A2D_MEDIA_CTRL_STOP);
}
else
{
LOCK_S;
SET_MIN_MAX_SIZED(_buf_used(streambuf),stream_buf,streambuf->size);
UNLOCK_S;
static time_t lastTime=0;
if (lastTime <= gettime_ms() )
{
lastTime = gettime_ms() + 15000;
ESP_LOGD(TAG, "Statistics over %u secs. " , STATS_REPORT_DELAY_MS/1000);
ESP_LOGD(TAG, " +==========+==========+================+=====+================+");
ESP_LOGD(TAG, " | max | min | average | avg | count |");
ESP_LOGD(TAG, " | (bytes) | (bytes) | (bytes) | pct | |");
ESP_LOGD(TAG, " +==========+==========+================+=====+================+");
ESP_LOGD(TAG,LINE_MIN_MAX_FORMAT,LINE_MIN_MAX("stream avl",stream_buf));
ESP_LOGD(TAG,LINE_MIN_MAX_FORMAT,LINE_MIN_MAX("output avl",bt));
ESP_LOGD(TAG,LINE_MIN_MAX_FORMAT,LINE_MIN_MAX("requested",req));
ESP_LOGD(TAG,LINE_MIN_MAX_FORMAT,LINE_MIN_MAX("received",rec));
ESP_LOGD(TAG,LINE_MIN_MAX_FORMAT,LINE_MIN_MAX("underrun",under));
ESP_LOGD(TAG, " +==========+==========+================+=====+================+");
ESP_LOGD(TAG,"\n");
ESP_LOGD(TAG," ==========+==========+===========+===========+ ");
ESP_LOGD(TAG," max (us) | min (us) | avg(us) | count | ");
ESP_LOGD(TAG," ==========+==========+===========+===========+ ");
ESP_LOGD(TAG,LINE_MIN_MAX_DURATION_FORMAT,LINE_MIN_MAX_DURATION("Out Buf Lock",lock_out_time));
ESP_LOGD(TAG," ==========+==========+===========+===========+");
RESET_ALL_MIN_MAX;
}
} else {
output_bt_tick();
}
}
break;
@@ -716,16 +576,7 @@ static void bt_app_av_media_proc(uint16_t event, void *param)
if (a2d->media_ctrl_stat.cmd == ESP_A2D_MEDIA_CTRL_STOP &&
a2d->media_ctrl_stat.status == ESP_A2D_MEDIA_CTRL_ACK_SUCCESS) {
ESP_LOGI(TAG,"a2dp media stopped successfully...");
//s_media_state = APP_AV_MEDIA_STATE_WAIT_DISCONNECT;
// if(CONFIG_A2DP_DISCONNECT_MS==0){
// we're not going to disconnect.
s_media_state = APP_AV_MEDIA_STATE_IDLE;
// }
// else
// {
// disconnect_time = gettime_ms()+CONFIG_A2DP_DISCONNECT_MS;
// s_media_state = APP_AV_MEDIA_STATE_WAIT_DISCONNECT;
// }
s_media_state = APP_AV_MEDIA_STATE_IDLE;
} else {
ESP_LOGI(TAG,"a2dp media stopping...");
esp_a2d_media_ctrl(ESP_A2D_MEDIA_CTRL_STOP);
@@ -735,20 +586,15 @@ static void bt_app_av_media_proc(uint16_t event, void *param)
}
case APP_AV_MEDIA_STATE_WAIT_DISCONNECT:{
if(gettime_ms()>disconnect_time){
// we've reached timeout
esp_a2d_source_disconnect(s_peer_bda);
s_a2d_state = APP_AV_STATE_DISCONNECTING;
}
esp_a2d_source_disconnect(s_peer_bda);
s_a2d_state = APP_AV_STATE_DISCONNECTING;
ESP_LOGI(TAG,"a2dp disconnecting...");
}
}
}
static void bt_app_av_state_unconnected(uint16_t event, void *param)
{
// LOCK;
// output_state out_state= output.state;
// UNLOCK;
switch (event) {
case ESP_A2D_CONNECTION_STATE_EVT:
ESP_LOG_DEBUG_EVENT(TAG,QUOTE(ESP_A2D_CONNECTION_STATE_EVT));
@@ -772,8 +618,6 @@ static void bt_app_av_state_unconnected(uint16_t event, void *param)
ESP_LOG_DEBUG_EVENT(TAG,QUOTE(ESP_A2D_MEDIA_CTRL_ACK_EVT));
break;
case BT_APP_HEART_BEAT_EVT: {
// uint8_t *p = s_peer_bda;
// ESP_LOGI(TAG,"BT_APP_HEART_BEAT_EVT a2dp connecting to peer: %02x:%02x:%02x:%02x:%02x:%02x",p[0], p[1], p[2], p[3], p[4], p[5]);
switch (esp_bluedroid_get_status()) {
case ESP_BLUEDROID_STATUS_UNINITIALIZED:
ESP_LOGV(TAG,"BlueDroid Status is ESP_BLUEDROID_STATUS_UNINITIALIZED.");
@@ -787,21 +631,18 @@ static void bt_app_av_state_unconnected(uint16_t event, void *param)
default:
break;
}
// if(out_state > OUTPUT_STOPPED){
// only attempt a connect when playback isn't stopped
for(uint8_t l=0;art_a2dp_connecting[l][0]!='\0';l++){
ESP_LOGI(TAG,"%s",art_a2dp_connecting[l]);
}
ESP_LOGI(TAG,"Device: %s", s_peer_bdname);
if(esp_a2d_source_connect(s_peer_bda)==ESP_OK) {
A2DP_TIMER_INIT;
s_a2d_state = APP_AV_STATE_CONNECTING;
}
else {
// there was an issue connecting... continue to discover
ESP_LOGE(TAG,"Attempt at connecting failed, restart at discover...");
esp_bt_gap_start_discovery(ESP_BT_INQ_MODE_GENERAL_INQUIRY, 10, 0);
// }
for(uint8_t l=0;art_a2dp_connecting[l][0]!='\0';l++){
ESP_LOGI(TAG,"%s",art_a2dp_connecting[l]);
}
ESP_LOGI(TAG,"Device: %s", s_peer_bdname);
if(esp_a2d_source_connect(s_peer_bda)==ESP_OK) {
A2DP_TIMER_INIT;
s_a2d_state = APP_AV_STATE_CONNECTING;
}
else {
// there was an issue connecting... continue to discover
ESP_LOGE(TAG,"Attempt at connecting failed, restart at discover...");
esp_bt_gap_start_discovery(ESP_BT_INQ_MODE_GENERAL_INQUIRY, 10, 0);
}
break;
}
@@ -928,18 +769,4 @@ static void bt_app_av_state_disconnecting(uint16_t event, void *param)
ESP_LOGE(TAG,"%s unhandled evt %d", __func__, event);
break;
}
}
const char *loc_logtime(void) {
static char buf[100];
#if WIN
SYSTEMTIME lt;
GetLocalTime(&lt);
sprintf(buf, "[%02d:%02d:%02d.%03d]", lt.wHour, lt.wMinute, lt.wSecond, lt.wMilliseconds);
#else
struct timeval tv;
gettimeofday(&tv, NULL);
strftime(buf, sizeof(buf), "[%T.", localtime(&tv.tv_sec));
sprintf(buf+strlen(buf), "%06ld]", (long)tv.tv_usec);
#endif
return buf;
}
}

View File

@@ -7,6 +7,7 @@
#include "esp_log.h"
#include "esp_console.h"
#include "esp_pthread.h"
#include "argtable3/argtable3.h"
#include "freertos/FreeRTOS.h"
#include "freertos/event_groups.h"

View File

@@ -6,5 +6,4 @@
# lib(subdirectory_name).a in the build directory. This behaviour is entirely configurable,
# please read the SDK documents if you need to do this.
#
CFLAGS += -Os -DPOSIX -DLINKALL -DLOOPBACK -DNO_FAAD -DEMBEDDED -DTREMOR_ONLY -DBYTES_PER_FRAME=4
CFLAGS += -D LOG_LOCAL_LEVEL=ESP_LOG_DEBUG

View File

@@ -1,147 +1,27 @@
/* Scan Example
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.
*/
/*
This example shows how to use the All Channel Scan or Fast Scan to connect
to a Wi-Fi network.
In the Fast Scan mode, the scan will stop as soon as the first network matching
the SSID is found. In this mode, an application can set threshold for the
authentication mode and the Signal strength. Networks that do not meet the
threshold requirements will be ignored.
In the All Channel Scan mode, the scan will end only after all the channels
are scanned, and connection will start with the best network. The networks
can be sorted based on Authentication Mode or Signal Strength. The priority
for the Authentication mode is: WPA2 > WPA > WEP > Open
*/
/*
* Squeezelite for esp32
*
* (c) Sebastien 2019
* 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 <http://www.gnu.org/licenses/>.
*
*/
#include "platform_esp32.h"
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include "esp_bt.h"
#include "esp_bt_device.h"
#include "esp_bt_main.h"
#include "esp_gap_bt_api.h"
#include "esp_a2dp_api.h"
#include "esp_avrc_api.h"
#include "esp_log.h"
#include "esp_pthread.h"
#include "esp_system.h"
#include "esp_wifi.h"
#include "freertos/FreeRTOS.h"
#include "freertos/event_groups.h"
#include "freertos/task.h"
#include "freertos/timers.h"
#include "nvs.h"
#include "nvs_flash.h"
#include "nvs_utilities.h"
#include "pthread.h"
#include "string.h"
#include "sys/socket.h"
#include <signal.h>
#include "esp_system.h"
#include <signal.h>
/*Set the SSID and Password via "make menuconfig"*/
#define DEFAULT_SSID CONFIG_WIFI_SSID
#define DEFAULT_PWD CONFIG_WIFI_PASSWORD
#if CONFIG_WIFI_ALL_CHANNEL_SCAN
#define DEFAULT_SCAN_METHOD WIFI_ALL_CHANNEL_SCAN
#elif CONFIG_WIFI_FAST_SCAN
#define DEFAULT_SCAN_METHOD WIFI_FAST_SCAN
#else
#define DEFAULT_SCAN_METHOD WIFI_FAST_SCAN
#endif /*CONFIG_SCAN_METHOD*/
#if CONFIG_WIFI_CONNECT_AP_BY_SIGNAL
#define DEFAULT_SORT_METHOD WIFI_CONNECT_AP_BY_SIGNAL
#elif CONFIG_WIFI_CONNECT_AP_BY_SECURITY
#define DEFAULT_SORT_METHOD WIFI_CONNECT_AP_BY_SECURITY
#else
#define DEFAULT_SORT_METHOD WIFI_CONNECT_AP_BY_SIGNAL
#endif /*CONFIG_SORT_METHOD*/
#if CONFIG_FAST_SCAN_THRESHOLD
#define DEFAULT_RSSI CONFIG_FAST_SCAN_MINIMUM_SIGNAL
#if CONFIG_EXAMPLE_OPEN
#define DEFAULT_AUTHMODE WIFI_AUTH_OPEN
#elif CONFIG_EXAMPLE_WEP
#define DEFAULT_AUTHMODE WIFI_AUTH_WEP
#elif CONFIG_EXAMPLE_WPA
#define DEFAULT_AUTHMODE WIFI_AUTH_WPA_PSK
#elif CONFIG_EXAMPLE_WPA2
#define DEFAULT_AUTHMODE WIFI_AUTH_WPA2_PSK
#else
#define DEFAULT_AUTHMODE WIFI_AUTH_OPEN
#endif
#else
#define DEFAULT_RSSI -127
#define DEFAULT_AUTHMODE WIFI_AUTH_OPEN
#endif /*CONFIG_FAST_SCAN_THRESHOLD*/
extern char current_namespace[];
static const char * TAG = "platform_esp32";
//static void event_handler(void* arg, esp_event_base_t event_base,
// int32_t event_id, void* event_data)
//{
// if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_STA_START) {
// esp_wifi_connect();
// } else if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_STA_DISCONNECTED) {
// esp_wifi_connect();
// } else if (event_base == IP_EVENT && event_id == IP_EVENT_STA_GOT_IP) {
// ip_event_got_ip_t* event = (ip_event_got_ip_t*) event_data;
// ESP_LOGI(TAG, "got ip: %s.", ip4addr_ntoa(&event->ip_info.ip));
// ESP_LOGD(TAG,"Signaling wifi connected. Locking.\n");
// pthread_mutex_lock(&wifi_connect_suspend_mutex);
// ESP_LOGD(TAG,"Signaling wifi connected. Broadcasting.\n");
// pthread_cond_broadcast(&wifi_connect_suspend_cond);
// ESP_LOGD(TAG,"Signaling wifi connected. Unlocking.\n");
// pthread_mutex_unlock(&wifi_connect_suspend_mutex);
// }
//}
//
///* Initialize Wi-Fi as sta and set scan method */
//static void wifi_scan(void)
//{
//
// tcpip_adapter_init();
// ESP_ERROR_CHECK(esp_event_loop_create_default());
//
// wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
// ESP_ERROR_CHECK(esp_wifi_init(&cfg));
//
// ESP_ERROR_CHECK(esp_event_handler_register(WIFI_EVENT, ESP_EVENT_ANY_ID, &event_handler, NULL));
// ESP_ERROR_CHECK(esp_event_handler_register(IP_EVENT, IP_EVENT_STA_GOT_IP, &event_handler, NULL));
//
// wifi_config_t wifi_config = {
// .sta = {
// .ssid = DEFAULT_SSID,
// .password = DEFAULT_PWD,
// .scan_method = DEFAULT_SCAN_METHOD,
// .sort_method = DEFAULT_SORT_METHOD,
// .threshold.rssi = DEFAULT_RSSI,
// .threshold.authmode = DEFAULT_AUTHMODE,
// },
// };
// ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_STA));
// ESP_ERROR_CHECK(esp_wifi_set_config(ESP_IF_WIFI_STA, &wifi_config));
// ESP_ERROR_CHECK(esp_wifi_start());
//}
void app_main()
{
console_start();
}

View File

@@ -1,8 +1,28 @@
/*
* Squeezelite for esp32
*
* (c) Sebastien 2019
* 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 <http://www.gnu.org/licenses/>.
*
*/
#pragma once
#include "time.h"
#include "sys/time.h"
#include "esp_system.h"
#define PERF_MAX LONG_MAX
#define MIN_MAX_VAL(x) x==PERF_MAX?0:x
#define CURR_SAMPLE_RATE output.current_sample_rate>0?output.current_sample_rate:1

View File

@@ -1,93 +1,44 @@
/*
* Squeezelite for esp32
*
* (c) Sebastien 2019
* 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 <http://www.gnu.org/licenses/>.
*
*/
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
#include "bt_app_core.h"
#include "perf_trace.h"
#include "esp_pthread.h"
#ifndef QUOTE
#define QUOTE(name) #name
#define STR(macro) QUOTE(macro)
#endif
#define ESP_LOG_DEBUG_EVENT(tag,e) ESP_LOGD(tag,"evt: " e)
extern void run_command(char * line);
extern bool wait_for_wifi();
//typedef struct {
// char opt_slimproto_logging[11];
// char opt_stream_logging[11];
// char opt_decode_logging[11];
// char opt_output_logging[11];
// char opt_player_name[11];
// char opt_output_rates[21];
// char opt_buffer[11];
//} str_squeezelite_options ;
extern void console_start();
extern pthread_cond_t wifi_connect_suspend_cond;
extern pthread_t wifi_connect_suspend_mutex;
//static const char * art_wifi[]={
// "\n",
// "o `O ooOoOOo OOooOoO ooOoOOo\n",
// "O o O o O \n",
// "o O o O o \n",
// "O O O oOooO O \n",
// "o o o o O o \n",
// "O O O O o O \n",
// "`o O o O' O o O \n",
// " `OoO' `OoO' ooOOoOo O' ooOOoOo\n",
// "\n",
// ""
//};
//static const char * art_wifi_connecting[]={
// " .oOOOo.",
// ".O o o \n",
// "o O \n",
// "o oOo \n",
// "o .oOo. 'OoOo. 'OoOo. .oOo. .oOo o O 'OoOo. .oOoO \n",
// "O O o o O o O OooO' O O o o O o O \n",
// "`o .o o O O o O o O o o O O o O o \n",
// " `OoooO' `OoO' o O o O `OoO' `OoO' `oO o' o O `OoOo \n",
// " O \n",
// " OoO' \n",
// "\n",
// ""
//};
//static const char * art_wifi_connected[]={
// " .oOOOo. o oO\n",
// ".O o O OO\n",
// "o O o oO\n",
// "o oOo o Oo\n",
// "o .oOo. 'OoOo. 'OoOo. .oOo. .oOo o .oOo. .oOoO oO\n",
// "O O o o O o O OooO' O O OooO' o O \n",
// "`o .o o O O o O o O o o O O o Oo\n",
// " `OoooO' `OoO' o O o O `OoO' `OoO' `oO `OoO' `OoO'o oO\n",
// "\n",
// ""
//};
#define ESP_LOG_DEBUG_EVENT(tag,e) ESP_LOGD(tag,"evt: " e)
const char *loc_logtime(void);
//#define MY_ESP_LOG
#ifdef MY_ESP_LOG
#ifdef ESP_LOGI
#undef ESP_LOGI
#define ESP_LOGI(tag, format, ... ) ESP_LOG_LEVEL_LOCAL(ESP_LOG_INFO, tag, "%s %d " format,loc_logtime(), __LINE__, ##__VA_ARGS__)
#endif
#ifdef ESP_LOGE
#undef ESP_LOGE
#define ESP_LOGE(tag, format, ... ) ESP_LOG_LEVEL_LOCAL(ESP_LOG_ERROR, tag, "%s %d " format,loc_logtime(), __LINE__, ##__VA_ARGS__)
#endif
#ifdef ESP_LOGW
#undef ESP_LOGW
#define ESP_LOGW(tag, format, ... ) ESP_LOG_LEVEL_LOCAL(ESP_LOG_WARN, tag, "%s %d " format,loc_logtime(), __LINE__, ##__VA_ARGS__)
#endif
#ifdef ESP_LOGD
#undef ESP_LOGD
#define ESP_LOGD(tag, format, ... ) ESP_LOG_LEVEL_LOCAL(ESP_LOG_DEBUG, tag, "%s %d " format,loc_logtime(), __LINE__, ##__VA_ARGS__)
#endif
#ifdef ESP_LOGV
#undef ESP_LOGV
#define ESP_LOGV(tag, format, ... ) ESP_LOG_LEVEL_LOCAL(ESP_LOG_VERBOSE, tag, "%s %d " format,loc_logtime(), __LINE__, ##__VA_ARGS__)
#endif
#endif
#ifdef __cplusplus
}
#endif