Compare commits

..

5 Commits

6 changed files with 31 additions and 15 deletions

View File

@@ -5,7 +5,6 @@
software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
CONDITIONS OF ANY KIND, either express or implied. CONDITIONS OF ANY KIND, either express or implied.
*/ */
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <unistd.h> #include <unistd.h>
@@ -85,7 +84,7 @@ static void vCallbackFunction( TimerHandle_t xTimer ) {
bool led_blink_core(int idx, int ontime, int offtime, bool pushed) { bool led_blink_core(int idx, int ontime, int offtime, bool pushed) {
if (!leds[idx].gpio || leds[idx].gpio < 0 ) return false; if (!leds[idx].gpio || leds[idx].gpio < 0 ) return false;
ESP_LOGD(TAG,"led_blink_core"); ESP_LOGD(TAG,"led_blink_core led idx %d, ontime %d, offtime %d, pushing %s. Led state: pushedon %d, pushedoff %d, timer %s, pushed %s", idx,ontime,offtime,pushed?"TRUE":"FALSE", leds[idx].pushedon,leds[idx].pushedoff,leds[idx].timer?"TRUE":"FALSE", leds[idx].pushed?"TRUE":"FALSE");
if (leds[idx].timer) { if (leds[idx].timer) {
// normal requests waits if a pop is pending // normal requests waits if a pop is pending
if (!pushed && leds[idx].pushed) { if (!pushed && leds[idx].pushed) {
@@ -98,15 +97,18 @@ bool led_blink_core(int idx, int ontime, int offtime, bool pushed) {
// save current state if not already pushed // save current state if not already pushed
if (!leds[idx].pushed) { if (!leds[idx].pushed) {
ESP_LOGD(TAG,"Pushing state. Ontime %d->%d. Offtime %d->%d",leds[idx].pushedon,leds[idx].ontime, leds[idx].pushedoff,leds[idx].offtime);
leds[idx].pushedon = leds[idx].ontime; leds[idx].pushedon = leds[idx].ontime;
leds[idx].pushedoff = leds[idx].offtime; leds[idx].pushedoff = leds[idx].offtime;
leds[idx].pushed = pushed; leds[idx].pushed = pushed;
} }
// then set new one // then set new one
leds[idx].ontime = ontime; leds[idx].ontime = ontime;
leds[idx].offtime = offtime; leds[idx].offtime = offtime;
if (ontime == 0) { if (ontime == 0) {
ESP_LOGD(TAG,"led %d, setting reverse level", idx); ESP_LOGD(TAG,"led %d, setting reverse level", idx);
set_level(leds + idx, false); set_level(leds + idx, false);
@@ -124,6 +126,7 @@ bool led_blink_core(int idx, int ontime, int offtime, bool pushed) {
ESP_LOGD(TAG,"led %d, Setting gpio %d and starting timer", idx, leds[idx].gpio); ESP_LOGD(TAG,"led %d, Setting gpio %d and starting timer", idx, leds[idx].gpio);
if (xTimerStart(leds[idx].timer, BLOCKTIME) == pdFAIL) return false; if (xTimerStart(leds[idx].timer, BLOCKTIME) == pdFAIL) return false;
} }
ESP_LOGD(TAG,"led_blink_core END led idx %d, ontime %d, offtime %d, pushing %s. Led state: pushedon %d, pushedoff %d, timer %s, pushed %s", idx,ontime,offtime,pushed?"TRUE":"FALSE", leds[idx].pushedon,leds[idx].pushedoff,leds[idx].timer?"TRUE":"FALSE", leds[idx].pushed?"TRUE":"FALSE");
return true; return true;
@@ -231,15 +234,13 @@ void led_svc_init(void) {
#ifndef CONFIG_LED_LOCKED #ifndef CONFIG_LED_LOCKED
parse_set_GPIO(set_led_gpio); parse_set_GPIO(set_led_gpio);
#endif #endif
ESP_LOGI(TAG,"Configuring LEDs green:%d (active:%d %d%%), red:%d (active:%d %d%%)", green.gpio, green.active, green.pwm, green.gpio, green.active, green.pwm );
char *nvs_item = config_alloc_get(NVS_TYPE_STR, "led_brightness"), *p; char *nvs_item = config_alloc_get(NVS_TYPE_STR, "led_brightness"), *p;
if (nvs_item) { if (nvs_item) {
if ((p = strcasestr(nvs_item, "green")) != NULL) green.pwm = atoi(strchr(p, '=') + 1); if ((p = strcasestr(nvs_item, "green")) != NULL) green.pwm = atoi(strchr(p, '=') + 1);
if ((p = strcasestr(nvs_item, "red")) != NULL) red.pwm = atoi(strchr(p, '=') + 1); if ((p = strcasestr(nvs_item, "red")) != NULL) red.pwm = atoi(strchr(p, '=') + 1);
free(nvs_item); free(nvs_item);
} }
ESP_LOGI(TAG,"Configuring LEDs green:%d (active:%d %d%%), red:%d (active:%d %d%%)", green.gpio, green.active, green.pwm, red.gpio, red.active, red.pwm );
led_config(LED_GREEN, green.gpio, green.active, green.pwm); led_config(LED_GREEN, green.gpio, green.active, green.pwm);
led_config(LED_RED, red.gpio, red.active, red.pwm); led_config(LED_RED, red.gpio, red.active, red.pwm);
} }

View File

@@ -128,7 +128,7 @@ static esp_err_t i2c_write_reg(uint8_t reg, uint8_t val) {
i2c_cmd_handle_t cmd = i2c_cmd_link_create(); i2c_cmd_handle_t cmd = i2c_cmd_link_create();
i2c_master_start(cmd); i2c_master_start(cmd);
i2c_master_write_byte(cmd, i2c_addr | I2C_MASTER_WRITE, I2C_MASTER_NACK); i2c_master_write_byte(cmd, (i2c_addr << 1) | I2C_MASTER_WRITE, I2C_MASTER_NACK);
i2c_master_write_byte(cmd, reg, I2C_MASTER_NACK); i2c_master_write_byte(cmd, reg, I2C_MASTER_NACK);
i2c_master_write_byte(cmd, val, I2C_MASTER_NACK); i2c_master_write_byte(cmd, val, I2C_MASTER_NACK);
@@ -153,11 +153,11 @@ static uint8_t i2c_read_reg(uint8_t reg) {
i2c_cmd_handle_t cmd = i2c_cmd_link_create(); i2c_cmd_handle_t cmd = i2c_cmd_link_create();
i2c_master_start(cmd); i2c_master_start(cmd);
i2c_master_write_byte(cmd, i2c_addr | I2C_MASTER_WRITE, I2C_MASTER_NACK); i2c_master_write_byte(cmd, (i2c_addr << 1) | I2C_MASTER_WRITE, I2C_MASTER_NACK);
i2c_master_write_byte(cmd, reg, I2C_MASTER_NACK); i2c_master_write_byte(cmd, reg, I2C_MASTER_NACK);
i2c_master_start(cmd); i2c_master_start(cmd);
i2c_master_write_byte(cmd, i2c_addr | I2C_MASTER_READ, I2C_MASTER_NACK); i2c_master_write_byte(cmd, (i2c_addr << 1) | I2C_MASTER_READ, I2C_MASTER_NACK);
i2c_master_read_byte(cmd, &data, I2C_MASTER_NACK); i2c_master_read_byte(cmd, &data, I2C_MASTER_NACK);
i2c_master_stop(cmd); i2c_master_stop(cmd);

View File

@@ -462,7 +462,11 @@ cJSON * wifi_manager_get_basic_info(cJSON **old){
cJSON_AddNumberToObject(root,"Voltage", battery_value_svc()); cJSON_AddNumberToObject(root,"Voltage", battery_value_svc());
cJSON_AddNumberToObject(root,"disconnect_count", num_disconnect ); cJSON_AddNumberToObject(root,"disconnect_count", num_disconnect );
cJSON_AddNumberToObject(root,"avg_conn_time", num_disconnect>0?(total_connected_time/num_disconnect):0 ); cJSON_AddNumberToObject(root,"avg_conn_time", num_disconnect>0?(total_connected_time/num_disconnect):0 );
#if CONFIG_I2C_LOCKED
cJSON_AddTrueToObject(root, "is_i2c_locked");
#else
cJSON_AddFalseToObject(root, "is_i2c_locked");
#endif
ESP_LOGV(TAG, "wifi_manager_get_basic_info done"); ESP_LOGV(TAG, "wifi_manager_get_basic_info done");
return root; return root;
} }
@@ -689,6 +693,8 @@ static void event_handler(void* arg, esp_event_base_t event_base, int32_t event_
ESP_LOGD(TAG, "WIFI_EVENT_AP_STACONNECTED. aid: %d, mac: %s",stac->aid,STR_OR_BLANK(mac)); ESP_LOGD(TAG, "WIFI_EVENT_AP_STACONNECTED. aid: %d, mac: %s",stac->aid,STR_OR_BLANK(mac));
FREE_AND_NULL(mac); FREE_AND_NULL(mac);
xEventGroupSetBits(wifi_manager_event_group, WIFI_MANAGER_AP_STA_CONNECTED_BIT); xEventGroupSetBits(wifi_manager_event_group, WIFI_MANAGER_AP_STA_CONNECTED_BIT);
wifi_manager_send_message(EVENT_STA_CONNECTED, NULL);
} }
break; break;
case WIFI_EVENT_AP_STADISCONNECTED: case WIFI_EVENT_AP_STADISCONNECTED:
@@ -1476,6 +1482,9 @@ void wifi_manager( void * pvParameters ){
/* callback */ /* callback */
if(cb_ptr_arr[msg.code]) (*cb_ptr_arr[msg.code])(NULL); if(cb_ptr_arr[msg.code]) (*cb_ptr_arr[msg.code])(NULL);
break; break;
case EVENT_STA_CONNECTED:
if(cb_ptr_arr[msg.code]) (*cb_ptr_arr[msg.code])(NULL);
break;
case UPDATE_CONNECTION_OK: case UPDATE_CONNECTION_OK:
/* refresh JSON */ /* refresh JSON */
if(wifi_manager_lock_json_buffer( portMAX_DELAY )){ if(wifi_manager_lock_json_buffer( portMAX_DELAY )){

View File

@@ -191,7 +191,8 @@ typedef enum message_code_t {
ORDER_RESTART_RECOVERY = 16, ORDER_RESTART_RECOVERY = 16,
ORDER_RESTART_OTA_URL = 17, ORDER_RESTART_OTA_URL = 17,
ORDER_RESTART = 18, ORDER_RESTART = 18,
MESSAGE_CODE_COUNT = 19 /* important for the callback array */ EVENT_STA_CONNECTED = 19,
MESSAGE_CODE_COUNT = 20 /* important for the callback array */
}message_code_t; }message_code_t;

View File

@@ -44,7 +44,7 @@ menu "Squeezelite-ESP32"
string string
default "model=TAS57xx,bck=33,ws=25,do=32,sda=27,scl=26,mute=14:0" if SQUEEZEAMP default "model=TAS57xx,bck=33,ws=25,do=32,sda=27,scl=26,mute=14:0" if SQUEEZEAMP
default "model=AC101,bck=27,ws=26,do=25,di=35,sda=33,scl=32" if A1S default "model=AC101,bck=27,ws=26,do=25,di=35,sda=33,scl=32" if A1S
default "model=I2S,bck=26,ws=25,do=33,i2c=106,sda=21,scl=22" if TWATCH2020 default "model=I2S,bck=26,ws=25,do=33,i2c=53,sda=21,scl=22" if TWATCH2020
default "" default ""
config SPDIF_CONFIG config SPDIF_CONFIG
string string

View File

@@ -95,6 +95,10 @@ void cb_connection_sta_disconnected(void *pvParameter){
bWifiConnected=false; bWifiConnected=false;
xEventGroupClearBits(wifi_event_group, CONNECTED_BIT); xEventGroupClearBits(wifi_event_group, CONNECTED_BIT);
} }
void cb_connection_sta_connected(void *pvParameter){
}
bool wait_for_wifi(){ bool wait_for_wifi(){
bool connected=(xEventGroupGetBits(wifi_event_group) & CONNECTED_BIT)!=0; bool connected=(xEventGroupGetBits(wifi_event_group) & CONNECTED_BIT)!=0;
if(!connected){ if(!connected){
@@ -447,7 +451,7 @@ void app_main()
/* start the wifi manager */ /* start the wifi manager */
ESP_LOGD(TAG,"Blinking led"); ESP_LOGD(TAG,"Blinking led");
led_blink(LED_GREEN, 250, 250); led_blink_pushed(LED_GREEN, 250, 250);
if(bypass_wifi_manager){ if(bypass_wifi_manager){
ESP_LOGW(TAG,"*******************************************************************************************"); ESP_LOGW(TAG,"*******************************************************************************************");
@@ -463,6 +467,7 @@ void app_main()
* This can be either after we're started the AP mode, or after we've started the STA mode */ * This can be either after we're started the AP mode, or after we've started the STA mode */
wifi_manager_set_callback(ORDER_START_AP, &start_telnet); wifi_manager_set_callback(ORDER_START_AP, &start_telnet);
wifi_manager_set_callback(ORDER_CONNECT_STA, &start_telnet); wifi_manager_set_callback(ORDER_CONNECT_STA, &start_telnet);
wifi_manager_set_callback(EVENT_STA_CONNECTED, &cb_connection_sta_connected);
} }
console_start(); console_start();