1.修复没有播声音 2.修正音量调整失败

This commit is contained in:
helloyifa 2025-07-17 01:24:37 +08:00
parent cb124078bd
commit 78110607c0
6 changed files with 100 additions and 133 deletions

View File

@ -215,10 +215,10 @@ static void cli_factory_read(char *pcWriteBuffer, int xWriteBufferLen, int argc,
{
uint32_t volume;
int ret = bk_config_read("volume", (void *)&volume, sizeof(volume));
LOGI("sram volume = %u, ret = %d\r\n", volume, ret);
LOGE("sram volume = %u, ret = %d\r\n", volume, ret);
ret = bk_get_env_enhance("volume", (void *)&volume, sizeof(volume));
LOGI("flash volume = %u, ret = %d\r\n", volume, ret);
LOGE("flash volume = %u, ret = %d\r\n", volume, ret);
}
@ -257,7 +257,7 @@ void bk_factory_init(void)
LOGI("first initialize factory config\r\n");
bk_factory_reset();
} else {
LOGI("factory config already initialized\r\n");
LOGE("factory config already initialized\r\n");
bk_factory_cache_init();
}

View File

@ -141,125 +141,8 @@ void prepare_config_network_main()
rtos_delete_thread(NULL);
}
// 按键 1 的回调函数
void volume_init(void)
{
int volume_size = bk_config_read("volume", (void *)&volume, 4);
if (volume_size != 4)
{
BK_LOGE(TAG, "read volume config fail, use default config volume_size:%d\n", volume_size);
}
if (volume > (SPK_VOLUME_LEVEL - 1))
{
volume = SPK_VOLUME_LEVEL - 1;
if (0 != bk_config_write("volume", (void *)&volume, 4))
{
BK_LOGE(TAG, "storage volume: %d fail\n", volume);
}
}
/* SPK_GAIN_MAX * [(exp(i/(SPK_VOLUME_LEVEL-1)-1)/(exp(1)-1)] */
uint32_t step[SPK_VOLUME_LEVEL] = {0, 6, 12, 20, 28, 37, 47, 58, 71, 84, 100};
for (uint32_t i = 0; i < SPK_VOLUME_LEVEL; i++)
{
g_volume_gain[i] = SPK_GAIN_MAX * step[i] / 100;
}
}
void volume_increase()
{
BK_LOGI(TAG, " volume up\r\n");
if (volume == (SPK_VOLUME_LEVEL - 1))
{
BK_LOGI(TAG, "volume have reached maximum volume: %d\n", SPK_GAIN_MAX);
return;
}
if (BK_OK == bk_aud_intf_set_spk_gain(g_volume_gain[volume + 1]))
{
volume += 1;
if (0 != bk_config_write("volume", (void *)&volume, 4))
{
BK_LOGE(TAG, "storage volume: %d fail\n", volume);
}
BK_LOGI(TAG, "current volume: %d\n", volume);
}
else
{
BK_LOGI(TAG, "set volume fail\n");
}
}
void volume_decrease()
{
BK_LOGI(TAG, " volume down\r\n");
if (volume == 0)
{
BK_LOGI(TAG, "volume have reached minimum volume: 0\n");
return;
}
if (BK_OK == bk_aud_intf_set_spk_gain(g_volume_gain[volume - 1]))
{
volume -= 1;
if (0 != bk_config_write("volume", (void *)&volume, 4))
{
BK_LOGE(TAG, "storage volume: %d fail\n", volume);
}
BK_LOGI(TAG, "current volume: %d\n", volume);
}
else
{
BK_LOGI(TAG, "set volume fail\n");
}
}
void volume_set_abs(uint8_t level, uint8_t has_precision)
{
bk_err_t ret = 0;
BK_LOGI(TAG, "%s volume abs %d %d\n", __func__, level, has_precision);
if (level > SPK_VOLUME_LEVEL - 1)
{
BK_LOGE(TAG, "%s invalid level %d >= %d\n", __func__, level, SPK_VOLUME_LEVEL);
level = SPK_VOLUME_LEVEL - 1;
}
if (level == 0 && has_precision)
{
BK_LOGW(TAG, "%s set raw gain 2 because precision\n", __func__);
ret = bk_aud_intf_set_spk_gain(2);
}
else
{
ret = bk_aud_intf_set_spk_gain(g_volume_gain[level]);
}
if (BK_OK == ret)
{
volume = level;
if (0 != bk_config_write("volume", (void *)&volume, sizeof(volume)))
{
BK_LOGE(TAG, "%s storage volume: %d fail\n", __func__, level);
}
BK_LOGI(TAG, "%s current volume: %d\n", __func__, level);
}
else
{
BK_LOGE(TAG, "%s set volume %d fail\n", __func__, level);
}
}
uint32_t volume_get_current()
{
return volume;
}
uint32_t volume_get_level_count()
{
return SPK_VOLUME_LEVEL;
}
void power_off()
{
BK_LOGI(TAG, " power_off\r\n");
@ -608,8 +491,6 @@ static void handle_system_event(key_event_t event)
#if (CONFIG_SYS_CPU0)
app_event_init();
volume_init();
#if CONFIG_AUD_INTF_SUPPORT_PROMPT_TONE
extern bk_err_t audio_turn_on(void);
int ret = audio_turn_on();

View File

@ -21,6 +21,14 @@
#include "mcp/mcp_server.h"
#include "beken_rtc.h"
#if (CONFIG_SYS_CPU0)
#include "beken_config.h"
#include "aud_intf.h"
#include "bk_factory_config.h"
#if CONFIG_NETWORK_AUTO_RECONNECT
#include "bk_genie_smart_config.h"
#endif
#endif
#include "iot_lamp.h"
#include "iot_speaker.h"
#include "iot_sleep_helper.h"
@ -187,6 +195,49 @@ static ReturnValue sleep_helper_get_device_status_callback(const PropertyList* p
return ret;
}
// 获取体温数据回调
static ReturnValue health_get_temperature_callback(const PropertyList* properties) {
#if 0
cJSON* status = cJSON_CreateObject();
cJSON* health = cJSON_CreateObject();
cJSON_AddNumberToObject(health, "body_temperature", 38.5);
cJSON_AddItemToObject(status, "health", health);
char *jsonString = cJSON_PrintUnformatted(status);
ReturnValue ret = return_value_create_string(jsonString);
cJSON_Delete(status);
return ret;
#endif
return return_value_create_string("{\"success\":false,\"error\":\"获取体温功能正在完善,敬请期待\"}");
}
// 获取血压数据回调
static ReturnValue health_get_bloodpressure_callback(const PropertyList* properties) {
#if 0
cJSON* status = cJSON_CreateObject();
cJSON* health = cJSON_CreateObject();
cJSON_AddNumberToObject(health, "bloodpressure", 120);
cJSON_AddItemToObject(status, "health", health);
char *jsonString = cJSON_PrintUnformatted(status);
ReturnValue ret = return_value_create_string(jsonString);
cJSON_Delete(status);
return ret;
#endif
return return_value_create_string("{\"success\":false,\"error\":\"获取血压功能正在完善,敬请期待\"}");
}
static ReturnValue health_analysis_report_callback(const PropertyList* properties) {
#if 0
cJSON* status = cJSON_CreateObject();
cJSON* health = cJSON_CreateObject();
cJSON_AddNumberToObject(health, "bloodpressure", 120);
cJSON_AddItemToObject(status, "health", health);
char *jsonString = cJSON_PrintUnformatted(status);
ReturnValue ret = return_value_create_string(jsonString);
cJSON_Delete(status);
return ret;
#endif
return return_value_create_string("{\"success\":false,\"error\":\"分析健康报告功能正在完善,敬请期待\"}");
}
void app_mcp_init(){
McpServer* mcp_server = mcp_server_get_instance();
@ -261,6 +312,20 @@ void app_mcp_init(){
PropertyList* props = property_list_create();
mcp_server_add_tool_with_params(mcp_server, "self.ota.update_device", "更新拍拍灯乐小牛软件,执行该指令需要和用户二次确认才允许下发这个指令,并提示大约等待3分钟后手动重启设备", props, ota_update_device_callback);
}
{
PropertyList* props = property_list_create();
mcp_server_add_tool_with_params(mcp_server, "self.health.get_temperature", "获取用户最近温度数据", props, health_get_temperature_callback);
}
{
PropertyList* props = property_list_create();
mcp_server_add_tool_with_params(mcp_server, "self.health.get_bloodpressure", "获取用户最近血压数据", props, health_get_bloodpressure_callback);
}
{
PropertyList* props = property_list_create();
mcp_server_add_tool_with_params(mcp_server, "self.health.analysis_report", "获取用户最近健康分析报告", props, health_analysis_report_callback);
}
}
@ -301,6 +366,24 @@ void app_on_incoming_json(char *json_text, unsigned int size){
DeviceState app_get_device_state(){
return deviceState;
}
void app_config_init(){
//读取OTA地址
char ota_url[128] = {0};
int ret_size = bk_config_read("ai_ota_url", (void *)&ota_url, sizeof(ota_url));
if(ret_size > 0){
LOGE("bk_config_read ai_ota_url:%s\n",ota_url);
//bk_ota_set_ota_url(ota_url);
}else{
LOGE("bk_config_read ai_ota_url fail\n");
memset(ota_url, 0, sizeof(ota_url));
sprintf(ota_url, "%s",APPLICATION_DEFULT_OTA_URL);
if (0 != bk_config_write("ai_ota_url", (void *)&ota_url, sizeof(ota_url)))
{
BK_LOGE(TAG, "storage ai_ota_url: %s fail\n", ota_url);
}
}
}
void app_start(){
app_mcp_init();
}

View File

@ -17,6 +17,7 @@
#include "beken_config.h"
#include "aud_intf.h"
#include "bk_factory_config.h"
#include "bk_ef.h"
#if CONFIG_NETWORK_AUTO_RECONNECT
#include "bk_genie_smart_config.h"
#endif
@ -39,6 +40,8 @@ static uint32_t g_volume_gain[SPK_VOLUME_LEVEL] = {0, 0x21, 0x22, 0x23, 0x24, 0x
void speaker_volume_init(void)
{
int volume_size = bk_config_read("volume", (void *)&volume, 4);
BK_LOGE(TAG, "bk_config_read volume level:%d \n", volume);
if (volume_size != 4)
{
BK_LOGE(TAG, "read volume config fail, use default config volume_size:%d\n", volume_size);
@ -50,13 +53,11 @@ void speaker_volume_init(void)
{
BK_LOGE(TAG, "storage volume: %d fail\n", volume);
}
}else{
volume = volume_size;
}
}
//volume = 10;
bk_aud_intf_set_spk_gain(g_volume_gain[volume]); // 0x30
BK_LOGE(TAG, "g_volume_gain: %02X \n", g_volume_gain[volume]);
BK_LOGE(TAG, "volume level:%d g_volume_gain: %02X \n", volume, g_volume_gain[volume]);
//bk_config_write("volume", (void *)&volume, 4);
/* SPK_GAIN_MAX * [(exp(i/(SPK_VOLUME_LEVEL-1)-1)/(exp(1)-1)] */
@ -140,12 +141,15 @@ void speaker_volume_set_abs(uint8_t level, uint8_t has_precision)
{
volume = level;
if (0 != bk_config_write("volume", (void *)&volume, sizeof(volume)))
if (0 != bk_config_write("volume", (void *)&volume, 4))
{
BK_LOGE(TAG, "%s storage volume: %d fail\n", __func__, level);
}
BK_LOGI(TAG, "%s current volume: %d\n", __func__, level);
ef_set_env_blob("volume", (void *)&volume, sizeof(volume));
//bk_config_sync_flash_safely();
BK_LOGE(TAG, "%s current volume: %d\n", __func__, level);
}
else
{

View File

@ -689,7 +689,6 @@ static int bk_genie_sconf_netif_event_cb(void *arg, event_module_t event_module,
{
case EVENT_NETIF_GOT_IP4:
// helloyifa
BK_LOGE(TAG, "!!!!!!!!!!!!!!!!!!!!!!!\n");
result = rtos_init_timer(&led_wifi_connected_timer,
5000,
led_wifi_connected,

View File

@ -853,7 +853,7 @@ void rtc_websocket_event_handler(void *event_handler_arg, char *event_base, int3
break;
case WEBSOCKET_EVENT_DATA:
LOGD("data from WebSocket server, len:%d op:%d\r\n", data->data_len, data->op_code);
//LOGE("data from WebSocket server, len:%d op:%d\r\n", data->data_len, data->op_code);
if (data->op_code == WS_TRANSPORT_OPCODES_BINARY)
{
#if CONFIG_USE_G722_CODEC
@ -861,7 +861,7 @@ void rtc_websocket_event_handler(void *event_handler_arg, char *event_base, int3
#elif CONFIG_USE_OPUS_CODEC
binary_data_status = 0; // 状态置为0表示正在接收数据
last_binary_data_ms = bk_aon_rtc_get_ms(); // 记录当前毫秒数
//poka_audio_receive_data_opus(__get_beken_rtc(), (uint8_t *)data->data_ptr, data->data_len);
poka_audio_receive_data_opus(__get_beken_rtc(), (uint8_t *)data->data_ptr, data->data_len);
// rtc_websocket_audio_receive_data_opus(__get_beken_rtc(), (uint8_t *)data->data_ptr, data->data_len);
#else
#endif