优化代码结构,声音改为播放romfs里边的MP3文件
This commit is contained in:
parent
9d6c0206e4
commit
2caa172960
@ -23,9 +23,9 @@
|
||||
#include "saradc_pub.h"
|
||||
|
||||
#include "ring_queue.h"
|
||||
|
||||
#include "opus_encoder.h"
|
||||
static app_temperature_info_t temperature_info;
|
||||
static app_dev_info_t dev_info;
|
||||
//static app_dev_info_t dev_info;
|
||||
|
||||
|
||||
static beken_timer_t timer_detect;
|
||||
@ -50,6 +50,11 @@ rt_thread_t tid_show_detect_temp;
|
||||
|
||||
static RingQueue ring_queue;
|
||||
|
||||
|
||||
/**
|
||||
* 当前绑定的设备
|
||||
*/
|
||||
uint8_t box_bind_mac[32];
|
||||
/**
|
||||
* 待绑定的设备
|
||||
*/
|
||||
@ -100,10 +105,12 @@ int temperature_adv_get_name(recv_adv_t *r_ind,char *name){
|
||||
}
|
||||
return name_len;
|
||||
}
|
||||
|
||||
/**
|
||||
* 搜索广播回调
|
||||
*/
|
||||
void temperature_adv_callback(recv_adv_t *r_ind)
|
||||
{
|
||||
|
||||
//获取BLE 设备名称
|
||||
char str_name[12] ={0};
|
||||
int ret = temperature_adv_get_name(r_ind,str_name);
|
||||
signed char rssi = (signed char)r_ind->rssi;
|
||||
@ -117,9 +124,8 @@ void temperature_adv_callback(recv_adv_t *r_ind)
|
||||
//没有名称的 跳过!
|
||||
return;
|
||||
}
|
||||
|
||||
//不等于 IT12 跳过!
|
||||
if(strstr(str_name,BLE_TEMPERATURE_DEVICE_IT12) == NULL){
|
||||
//不等于 IT12的 跳过!
|
||||
return;
|
||||
}
|
||||
|
||||
@ -140,29 +146,25 @@ void temperature_adv_callback(recv_adv_t *r_ind)
|
||||
}
|
||||
return;
|
||||
}
|
||||
// 绑定的设备
|
||||
if (r_ind->adv_addr[0] != dev_info.bind_mac[0]
|
||||
&&r_ind->adv_addr[1] != dev_info.bind_mac[1]
|
||||
&&r_ind->adv_addr[2] != dev_info.bind_mac[2]
|
||||
&&r_ind->adv_addr[3] != dev_info.bind_mac[3]
|
||||
&&r_ind->adv_addr[4] != dev_info.bind_mac[4]
|
||||
&&r_ind->adv_addr[5] != dev_info.bind_mac[5])
|
||||
{
|
||||
|
||||
bk_printf("bind dev : %s \r\n", box_bind_mac);
|
||||
// 判断是否是绑定的设备 如果不是则跳出
|
||||
//bind: box_bind_mac
|
||||
//current:
|
||||
|
||||
char str_current [32];
|
||||
rt_memset(str_current,0,sizeof(str_current));
|
||||
rt_sprintf(str_current,"%02x:%02x:%02x:%02x:%02x:%02x",r_ind->adv_addr[0],r_ind->adv_addr[1],r_ind->adv_addr[2],r_ind->adv_addr[3],r_ind->adv_addr[4],r_ind->adv_addr[5]);
|
||||
|
||||
|
||||
if(rt_strcmp((char*)str_current, (char*)box_bind_mac) != 0){
|
||||
return;
|
||||
}else{
|
||||
bk_printf("same : %s \r\n",str_current);
|
||||
}
|
||||
//复制设备名称
|
||||
rt_memset(temperature_info.device_name,0,sizeof(temperature_info.device_name));
|
||||
rt_memcpy(temperature_info.device_name,str_name,sizeof(str_name));
|
||||
//rt_strcmp((char*)str_name,(char*)temperature_info.device_name);
|
||||
bk_printf("!!!ble_device : %s %s \r\n",str_name,temperature_info.device_name);
|
||||
rtos_reload_timer(&timer_idle);
|
||||
|
||||
//在超时或者等待温度页面 第一次接受到温度 显示设备信息
|
||||
if(app_mode == UI_IDLE || app_mode == UI_WAIT_TEMPERATURE || app_mode == UI_SHOW_MEMORY_INFO){
|
||||
|
||||
bk_printf("!app_mode : %d \r\n",app_mode);
|
||||
app_enter_ui(UI_SHOW_DEVICE_INFO);
|
||||
}
|
||||
|
||||
//int i;
|
||||
//for (i = 0; i < r_ind->data_len; i++)
|
||||
//{
|
||||
@ -221,7 +223,20 @@ void temperature_adv_callback(recv_adv_t *r_ind)
|
||||
|
||||
p += data_len; // p之前已经移动到数据部分开始处,此时加上数据长度让指针移动到下一个AD结构
|
||||
}
|
||||
//复制设备名称
|
||||
rt_memset(temperature_info.device_name,0,sizeof(temperature_info.device_name));
|
||||
rt_memcpy(temperature_info.device_name,str_name,sizeof(str_name));
|
||||
//rt_strcmp((char*)str_name,(char*)temperature_info.device_name);
|
||||
bk_printf("!!!ble_device : %s %s \r\n",str_name,temperature_info.device_name);
|
||||
rtos_reload_timer(&timer_idle);
|
||||
|
||||
//在超时或者等待温度页面 第一次接受到温度 显示设备信息
|
||||
if(app_mode == UI_IDLE || app_mode == UI_WAIT_TEMPERATURE || app_mode == UI_SHOW_MEMORY_INFO || app_mode == UI_SHOW_DEVICE_INFO){
|
||||
|
||||
bk_printf("!app_mode : %d \r\n",app_mode);
|
||||
app_enter_ui(UI_SHOW_DEVICE_INFO);
|
||||
voice_player_play_tts(VOICE_CN_DETECT_START);
|
||||
}
|
||||
|
||||
//如果当前温度和之前相同 不刷新温度
|
||||
uint16_t temp_body = temperature_info.temperature_body;
|
||||
@ -229,6 +244,7 @@ void temperature_adv_callback(recv_adv_t *r_ind)
|
||||
//return;
|
||||
}
|
||||
last_body_temp = temp_body;
|
||||
app_enter_ui(UI_SHOW_TEMPERATURE);
|
||||
|
||||
//添加数据到队列,数量足够后取出所有温度数据 计算方差 如果小于 N N可以趋近于0 暂定小于100 则表示温度稳定
|
||||
RingQueue_enqueue(&ring_queue,(int)last_body_temp);
|
||||
@ -252,6 +268,13 @@ void temperature_adv_callback(recv_adv_t *r_ind)
|
||||
}
|
||||
int mean_value = sum / MAX_SIZE;
|
||||
bk_printf("mean_value:%d \r\n", mean_value);
|
||||
|
||||
|
||||
//判断温度是否在规定范围
|
||||
//if(mean_value < BLE_TEMPERATURE_LIMIT_MIN || mean_value > BLE_TEMPERATURE_LIMIT_MAX){
|
||||
// return;
|
||||
//}
|
||||
|
||||
//计算方差
|
||||
double sumOfSquares = 0;
|
||||
for (int i = 0; i < MAX_SIZE; i++) {
|
||||
@ -259,28 +282,27 @@ void temperature_adv_callback(recv_adv_t *r_ind)
|
||||
}
|
||||
int variance_value = sumOfSquares / MAX_SIZE; // 注意这里是n,而不是n-1(对于样本方差)
|
||||
bk_printf("variance_value:%d \r\n", variance_value);
|
||||
//方差小于 20 表示温度稳定 //10
|
||||
if(variance_value <= 20){
|
||||
//测量完成
|
||||
temperature_info.device_state = STATE_DETECT_FINISH;
|
||||
bk_printf("detect Finish :%d \r\n", mean_value);
|
||||
app_detect_record_t record;
|
||||
record.temperature_value = (uint16)mean_value;
|
||||
temperature_save_record(&record);
|
||||
voice_player_play_tts(VOICE_CN_DETECT_FINISH);
|
||||
rt_thread_mdelay(1500);
|
||||
voice_player_play_temperature(mean_value);
|
||||
}
|
||||
app_enter_ui(UI_SHOW_TEMPERATURE);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
void timer_temp_run_callback(void *arg){
|
||||
|
||||
//如果当前进入了绑定模式 则不刷新温度
|
||||
if(app_mode == UI_BOX_BIND){
|
||||
return;
|
||||
}
|
||||
|
||||
if(app_mode == UI_BOX_BATTERY){
|
||||
return;
|
||||
}
|
||||
|
||||
//if(app_mode == UI_SHOW_DEVICE_INFO){
|
||||
// return;
|
||||
//}
|
||||
|
||||
|
||||
|
||||
//extern long list_memheap(void);
|
||||
//list_memheap();
|
||||
}
|
||||
|
||||
|
||||
@ -356,13 +378,24 @@ void app_show_box_battery(){
|
||||
*/
|
||||
void app_show_memory_detect_info(){
|
||||
rt_kprintf("UI->app_show_last_detect_info\r\n");
|
||||
app_detect_record_t record;
|
||||
rt_memset(&record,0,sizeof(app_detect_record_t));
|
||||
temperature_read_record(&record);
|
||||
if(record.temperature_value == 0){
|
||||
rt_kprintf("no record\r\n");
|
||||
return;
|
||||
}
|
||||
|
||||
OLED_Clear();
|
||||
OLED_ShowString(2,1,(u8 *)"M1",16,1);
|
||||
|
||||
OLED_ShowString(0,18,(u8 *)"36.5 C",24,1);
|
||||
char str_temp[12]={0};
|
||||
rt_sprintf(str_temp,"%d.%d C\n",record.temperature_value/100,record.temperature_value/10%10);
|
||||
//rt_sprintf(str_temp,"")
|
||||
//OLED_ShowString(0,18,(u8 *)"36.5 C",24,1);
|
||||
OLED_ShowString(0,18,(u8 *)str_temp,24,1);
|
||||
OLED_DrawCircle(55,15,4);
|
||||
|
||||
OLED_Refresh();
|
||||
rt_thread_mdelay(1000);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -430,11 +463,14 @@ static void app_temperature_ui_detect_entry(void *parameter)
|
||||
rt_memset(str_temp,0,sizeof(str_temp));
|
||||
rt_sprintf(str_temp,"%d",temp_body/10%10);//小数点后一位
|
||||
OLED_ShowString(40,0+10,(u8*)str_temp,32,1);
|
||||
OLED_ShowChar(61,16,'C',24,1);
|
||||
//屏幕上的点(度) 闪烁
|
||||
if(ui_show_point){
|
||||
OLED_DrawCircle(62,10,4);
|
||||
OLED_ShowChar(61,16,'C',24,1);
|
||||
//未测量完成才允许闪烁
|
||||
if(temperature_info.device_state == STATE_DETECT_ING){
|
||||
ui_show_point = 0;
|
||||
}
|
||||
}else{
|
||||
ui_show_point = 1;
|
||||
}
|
||||
@ -586,7 +622,14 @@ void app_enter_ui(app_ui_mode mode){
|
||||
*/
|
||||
void temperature_save_record(app_detect_record_t *record){
|
||||
EfErrCode result = EF_NO_ERR;
|
||||
result = ef_set_env(BLE_TEMPERATURE_FLASH_RECORD_KEY, (char *)record);
|
||||
//char t[sizeof(app_detect_record_t)] = {0x88,0x86,0x89};
|
||||
//app_detect_record_t record;
|
||||
//record.temperature_value = t_value;
|
||||
char data[32];
|
||||
rt_memset(data,0,sizeof(data));
|
||||
rt_sprintf(data,"%d",record->temperature_value);
|
||||
|
||||
result = ef_set_env(BLE_TEMPERATURE_FLASH_RECORD_KEY_TEMPERATURE, data);
|
||||
result = ef_save_env();
|
||||
if (result == EF_NO_ERR)
|
||||
{
|
||||
@ -600,11 +643,14 @@ void temperature_save_record(app_detect_record_t *record){
|
||||
* 读取最新的一次记录
|
||||
*/
|
||||
void temperature_read_record(app_detect_record_t *record){
|
||||
rt_memset(record,0,sizeof(app_dev_info_t));
|
||||
rt_memset(record,0,sizeof(app_detect_record_t));
|
||||
/*获取easy flash存入的数据*/
|
||||
char *t = ef_get_env(BLE_TEMPERATURE_FLASH_RECORD_KEY);
|
||||
char *t = ef_get_env(BLE_TEMPERATURE_FLASH_RECORD_KEY_TEMPERATURE);
|
||||
if(t != NULL){
|
||||
rt_memcpy(&dev_info,t,sizeof(app_dev_info_t));
|
||||
//rt_kprintf("%02X %02X %02X %02X %02X %02X %02X %02X %02X %02X\r\n",t[0],t[1],t[2],t[3],t[4],t[5],t[6],t[7],t[8],t[9]);
|
||||
//rt_memcpy(record,t,sizeof(app_detect_record_t));
|
||||
uint16 temp = atoi(t);
|
||||
record->temperature_value = temp;
|
||||
}else{
|
||||
rt_kprintf("temperature_read_record error\r\n");
|
||||
}
|
||||
@ -627,26 +673,32 @@ void box_poweroff_timeout_callback(void *arg){
|
||||
}
|
||||
|
||||
/**
|
||||
* 绑定扫描设备时间到 判断有无找到设备 有则写入FLASH
|
||||
* 绑定扫描设备时间到 判断有无找到设备 有则写入FLASH xx:xx:xx:xx:xx:xx
|
||||
*/
|
||||
void box_bind_timeout_callback(void *arg){
|
||||
rtos_stop_timer(&timer_bind);
|
||||
rt_kprintf("box_bind callback\r\n");
|
||||
if(ble_found_bind_dev){
|
||||
bk_printf("BIND: %02x:%02x:%02x:%02x:%02x:%02x \r\n",ble_device_mac[0],ble_device_mac[1], ble_device_mac[2],
|
||||
ble_device_mac[3], ble_device_mac[4],ble_device_mac[5]);
|
||||
rt_memcpy(dev_info.bind_mac,ble_device_mac,sizeof(ble_device_mac));
|
||||
|
||||
char str_bind_mac[32];
|
||||
rt_memset(str_bind_mac,0,sizeof(str_bind_mac));
|
||||
rt_sprintf(str_bind_mac,"%02x:%02x:%02x:%02x:%02x:%02x",ble_device_mac[0], ble_device_mac[1], ble_device_mac[2],
|
||||
ble_device_mac[3], ble_device_mac[4], ble_device_mac[5]);
|
||||
bk_printf("BIND: %s\r\n",str_bind_mac);
|
||||
EfErrCode result = EF_NO_ERR;
|
||||
//将要写入的数据存放到 easy flash 环境变量
|
||||
result = ef_set_env(BLE_TEMPERATURE_FLASH_CONFIG_KEY, (char*)&dev_info);
|
||||
//保存数据
|
||||
// 将要写入的数据存放到 easy flash 环境变量
|
||||
result = ef_set_env(BLE_TEMPERATURE_FLASH_CONFIG_KEY_BIND_MAC, str_bind_mac);
|
||||
// 保存数据
|
||||
result = ef_save_env();
|
||||
if(result == EF_NO_ERR)
|
||||
if (result == EF_NO_ERR)
|
||||
{
|
||||
|
||||
rt_strncpy((char*)box_bind_mac,(char*)str_bind_mac,rt_strlen(str_bind_mac));
|
||||
voice_player_play_tts(VOICE_CN_BIND_SUCC);
|
||||
OLED_Clear();
|
||||
//OLED_ShowString(0+15,0+5,(u8 *)"OK",32,1);
|
||||
OLED_ShowChinese(3,3,5,32,1); //成
|
||||
OLED_ShowChinese(35,3,6,32,1);//功
|
||||
// OLED_ShowString(0+15,0+5,(u8 *)"OK",32,1);
|
||||
OLED_ShowChinese(3, 3, 5, 32, 1); // 成
|
||||
OLED_ShowChinese(35, 3, 6, 32, 1); // 功
|
||||
OLED_Refresh();
|
||||
rt_thread_mdelay(1000);
|
||||
}
|
||||
@ -666,6 +718,7 @@ void timer_app_idle_callback(void *arg){
|
||||
return;
|
||||
}
|
||||
//app_enter_bind_mode(false);
|
||||
temperature_info.device_state = STATE_DETECT_ING;
|
||||
app_enter_ui(UI_IDLE);
|
||||
rt_kprintf("back idle mode !!!\r\n");
|
||||
}
|
||||
@ -711,6 +764,7 @@ void timer_hall_detect_callback(void *arg){
|
||||
//app_enter_bind_mode(true);
|
||||
//进入绑定模式 并启动超时退出
|
||||
app_enter_ui(UI_BOX_BIND);
|
||||
voice_player_play_tts(VOICE_CN_SEARCH_DEVICE);
|
||||
rtos_start_timer(&timer_bind);
|
||||
}
|
||||
}
|
||||
@ -746,16 +800,15 @@ int box_switch_init(void)
|
||||
}
|
||||
|
||||
void temperature_dev_config_init(){
|
||||
easyflash_init();
|
||||
rt_memset(&dev_info,0,sizeof(app_dev_info_t));
|
||||
|
||||
rt_memset(&box_bind_mac,0,sizeof(box_bind_mac));
|
||||
|
||||
/*获取easy flash存入的数据*/
|
||||
char *t = ef_get_env(BLE_TEMPERATURE_FLASH_CONFIG_KEY);
|
||||
char *t = ef_get_env(BLE_TEMPERATURE_FLASH_CONFIG_KEY_BIND_MAC);
|
||||
if(t != NULL){
|
||||
rt_memcpy(&dev_info,t,sizeof(app_dev_info_t));
|
||||
rt_memcpy(&box_bind_mac,t,strlen(t));
|
||||
rt_kprintf("\r\n");
|
||||
rt_kprintf("BIND TDEVICE:%02X %02X %02X %02X %02X %02X\r\n",dev_info.bind_mac[0],dev_info.bind_mac[1],dev_info.bind_mac[2],dev_info.bind_mac[3],dev_info.bind_mac[4],dev_info.bind_mac[5]);
|
||||
//rt_kprintf("DETECT %d\r\n",dev_info.detect_interval);
|
||||
rt_kprintf("BIND TDEVICE:%s\r\n",box_bind_mac);
|
||||
rt_kprintf("\r\n");
|
||||
}else{
|
||||
rt_kprintf("easy_flash read error\r\n");
|
||||
@ -813,10 +866,12 @@ static void charger_module_enable(UINT32 enable)
|
||||
|
||||
|
||||
void temperature_init(void){
|
||||
// 查询绑定设备
|
||||
uint8_t test_device_mac[6] = {0xe5, 0xe6, 0xb6, 0x09, 0x28, 0x37};
|
||||
rt_memcmp(dev_info.bind_mac, test_device_mac, sizeof(test_device_mac));
|
||||
|
||||
extern long list_memheap(void);
|
||||
list_memheap();
|
||||
// 查询绑定设备
|
||||
//uint8_t test_device_mac[6] = {0xe5, 0xe6, 0xb6, 0x09, 0x28, 0x37};
|
||||
//rt_memcmp(dev_info.bind_mac, test_device_mac, sizeof(test_device_mac));
|
||||
box_init_power();
|
||||
//初始化GPIO
|
||||
gpio_init();
|
||||
@ -832,6 +887,8 @@ void temperature_init(void){
|
||||
}
|
||||
app_enter_ui(UI_BOX_BATTERY);
|
||||
rt_thread_mdelay(2000);
|
||||
easyflash_init();
|
||||
ef_print_env();
|
||||
temperature_dev_config_init();
|
||||
//app_enter_bind_mode(false);
|
||||
RingQueue_init(&ring_queue);
|
||||
@ -869,6 +926,9 @@ void temperature_init(void){
|
||||
voice_player_mute(1);
|
||||
voice_player_init();
|
||||
|
||||
list_memheap();
|
||||
|
||||
|
||||
//app_tcp_init();
|
||||
//app_tcp_connect();
|
||||
|
||||
|
@ -31,7 +31,7 @@
|
||||
/**
|
||||
* 温度定时更新间隔时间
|
||||
*/
|
||||
#define BLE_TEMPERATURE_DETECT_INTERVAL 1000
|
||||
#define BLE_TEMPERATURE_DETECT_INTERVAL 5000
|
||||
|
||||
/**
|
||||
* 显示温度最小值 低于该值显示LOW
|
||||
@ -76,6 +76,21 @@
|
||||
*/
|
||||
#define BLE_TEMPERATURE_FLASH_RECORD_KEY "dev_record"
|
||||
|
||||
|
||||
/**
|
||||
* 配置文件easyflah KEY BIND MAC
|
||||
*/
|
||||
#define BLE_TEMPERATURE_FLASH_CONFIG_KEY_BIND_MAC "bind_mac"
|
||||
|
||||
/**
|
||||
* 测温记录 easyflah KEY temperature
|
||||
*/
|
||||
#define BLE_TEMPERATURE_FLASH_RECORD_KEY_TEMPERATURE "m1_temperature"
|
||||
/**
|
||||
* 测温记录 easyflah KEY time
|
||||
*/
|
||||
#define BLE_TEMPERATURE_FLASH_RECORD_KEY_TIMESTAMP "m1_timestamp"
|
||||
|
||||
typedef enum
|
||||
{
|
||||
APP_MODE_NORMAL,
|
||||
@ -93,6 +108,15 @@ typedef struct
|
||||
uint16_t device_state;
|
||||
}app_temperature_info_t;
|
||||
|
||||
|
||||
typedef enum
|
||||
{
|
||||
//正在测量
|
||||
STATE_DETECT_ING,
|
||||
//测量完成
|
||||
STATE_DETECT_FINISH,
|
||||
} app_detect_state_t;
|
||||
|
||||
/**
|
||||
* BOX 参数
|
||||
*/
|
||||
@ -106,7 +130,7 @@ typedef struct
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint64_t timestamp;
|
||||
uint8_t timestamp[8];
|
||||
uint16_t temperature_value;
|
||||
}app_detect_record_t;
|
||||
|
||||
@ -130,6 +154,7 @@ void app_enter_bind_mode(bool enter);
|
||||
* 保存最新的一次记录
|
||||
*/
|
||||
void temperature_save_record(app_detect_record_t *record);
|
||||
//void temperature_save_record(uint16_t t_value);
|
||||
/**
|
||||
* 读取最新的一次记录
|
||||
*/
|
||||
|
File diff suppressed because one or more lines are too long
@ -3,8 +3,28 @@
|
||||
|
||||
#include <rtthread.h>
|
||||
|
||||
#define VOICE_NUM0 "/flash0/0.mp3"
|
||||
#define VOICE_NUM1 "/flash0/1.mp3"
|
||||
#define VOICE_NUM2 "/flash0/2.mp3"
|
||||
#define VOICE_NUM3 "/flash0/3.mp3"
|
||||
#define VOICE_NUM4 "/flash0/4.mp3"
|
||||
#define VOICE_NUM5 "/flash0/5.mp3"
|
||||
#define VOICE_NUM6 "/flash0/6.mp3"
|
||||
#define VOICE_NUM7 "/flash0/7.mp3"
|
||||
#define VOICE_NUM8 "/flash0/8.mp3"
|
||||
#define VOICE_NUM9 "/flash0/9.mp3"
|
||||
#define VOICE_NUM10 "/flash0/10.mp3"
|
||||
|
||||
#define VOICE_CN_DU "/flash0/du.mp3"
|
||||
#define VOICE_CN_DIAN "/flash0/dian.mp3"
|
||||
#define VOICE_CN_SEARCH_DEVICE "/flash0/search_device.mp3"
|
||||
#define VOICE_CN_BIND_SUCC "/flash0/bind_succ.mp3"
|
||||
#define VOICE_CN_DETECT_FINISH "/flash0/detect_finish.mp3"
|
||||
#define VOICE_CN_DETECT_START "/flash0/start_detect.mp3"
|
||||
|
||||
void voice_player_init(void);
|
||||
void voice_play(int index);
|
||||
void voice_player_mute(int en);
|
||||
|
||||
void voice_player_play_temperature(uint16_t t_value);
|
||||
void voice_player_play_tts(char *file_path);
|
||||
#endif //_APP_VOICE_PLAYER_H_
|
||||
|
@ -123,14 +123,14 @@ int main(int argc, char **argv)
|
||||
wlan_app_init();
|
||||
#if defined(PKG_USING_PLAYER)
|
||||
extern int player_codec_helixmp3_register(void);
|
||||
extern int player_codec_beken_aac_register(void);
|
||||
extern int player_codec_beken_m4a_register(void);
|
||||
extern int player_codec_opencore_amr_register(void);
|
||||
//extern int player_codec_beken_aac_register(void);
|
||||
//extern int player_codec_beken_m4a_register(void);
|
||||
//extern int player_codec_opencore_amr_register(void);
|
||||
|
||||
player_codec_helixmp3_register();
|
||||
player_codec_beken_aac_register();
|
||||
player_codec_beken_m4a_register();
|
||||
player_codec_opencore_amr_register();
|
||||
//player_codec_beken_aac_register();
|
||||
//player_codec_beken_m4a_register();
|
||||
//player_codec_opencore_amr_register();
|
||||
player_system_init();
|
||||
#endif
|
||||
#ifdef XIAOYA_OS
|
||||
@ -166,6 +166,13 @@ static int wlan_app_init(void)
|
||||
app_start();
|
||||
//iic_bus_attach();
|
||||
temperature_init();
|
||||
//opous_encoder_start();
|
||||
|
||||
//rt_pin_mode(5, PIN_MODE_OUTPUT);
|
||||
//rt_pin_write(5, PIN_HIGH);
|
||||
|
||||
//rt_pin_mode(36, PIN_MODE_OUTPUT);
|
||||
//rt_pin_write(36, PIN_HIGH);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
75
beken_rtt_sdk_release-SDK_3.0.76/applications/opus_encoder.c
Normal file
75
beken_rtt_sdk_release-SDK_3.0.76/applications/opus_encoder.c
Normal file
@ -0,0 +1,75 @@
|
||||
#include <rtthread.h>
|
||||
#include <finsh.h>
|
||||
#include "common.h"
|
||||
#include "param_config.h"
|
||||
#include "ble_pub.h"
|
||||
#include "drv_oled.h"
|
||||
#include <rtdevice.h>
|
||||
#include "app_temperature.h"
|
||||
#ifdef PKG_USING_EASYFLASH
|
||||
#include "easyflash.h"
|
||||
#endif
|
||||
#include "audio_device.h"
|
||||
#include "app_voice_player.h"
|
||||
#include "opus.h"
|
||||
#include "opus_encoder.h"
|
||||
|
||||
// 设置常量
|
||||
#define SAMPLE_RATE 16000
|
||||
#define CHANNELS 1
|
||||
#define FRAME_SIZE 960 // 20ms的帧大小
|
||||
#define MAX_PACKET_SIZE 4000 // 最大的OPUS数据包大小
|
||||
|
||||
// PCM缓冲区
|
||||
int16_t pcm_buffer[FRAME_SIZE];
|
||||
uint8_t encoded_data[MAX_PACKET_SIZE]; // 用于存储编码后的OPUS数据
|
||||
|
||||
OpusEncoder *encoder = NULL;
|
||||
|
||||
//static const char *TAG = "PCM_to_Opus";
|
||||
|
||||
// 初始化Opus编码器
|
||||
int initialize_opus_encoder() {
|
||||
int error;
|
||||
encoder = opus_encoder_create(SAMPLE_RATE, CHANNELS, OPUS_APPLICATION_AUDIO, &error);
|
||||
if (error != OPUS_OK) {
|
||||
rt_kprintf( "opus_encoder_create fail: %s", opus_strerror(error));
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
// 编码PCM到Opus
|
||||
int encode_pcm_to_opus(int16_t *pcm_data, uint8_t *opus_data, int frame_size) {
|
||||
int encoded_size = opus_encode(encoder, pcm_data, frame_size, opus_data, MAX_PACKET_SIZE);
|
||||
if (encoded_size < 0) {
|
||||
rt_kprintf( "opus_encode fail: %s", opus_strerror(encoded_size));
|
||||
return encoded_size;
|
||||
}
|
||||
return encoded_size;
|
||||
}
|
||||
|
||||
/* 播放一个文件*/
|
||||
void opus_work(void *p)
|
||||
{
|
||||
|
||||
while(1){
|
||||
|
||||
rt_memset(pcm_buffer , 0, FRAME_SIZE);
|
||||
// PCM数据编码成Opus
|
||||
int ret = encode_pcm_to_opus(pcm_buffer, encoded_data, FRAME_SIZE);
|
||||
// 将编码后的OPUS数据写入文件
|
||||
//fwrite(encoded_data, sizeof(uint8_t), MAX_PACKET_SIZE, opus_file);
|
||||
rt_kprintf( "encode_pcm_to_opus : %d", ret);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void opous_encoder_start(){
|
||||
rt_thread_t thread = RT_NULL;
|
||||
thread = rt_thread_create("opus_work", opus_work, RT_NULL, 1024 *8, 10, 5);
|
||||
if(thread != RT_NULL)
|
||||
{
|
||||
rt_thread_startup(thread);
|
||||
}
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#define MAX_SIZE 50
|
||||
|
||||
void opous_encoder_start();
|
File diff suppressed because one or more lines are too long
181
beken_rtt_sdk_release-SDK_3.0.76/applications/tts_player.c
Normal file
181
beken_rtt_sdk_release-SDK_3.0.76/applications/tts_player.c
Normal file
@ -0,0 +1,181 @@
|
||||
/*
|
||||
* File: tts_player.c
|
||||
* COPYRIGHT (C) 2012-2018, Shanghai Real-Thread Technology Co., Ltd
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2019-05-05 liu2guang add play tts function(Block and Break).
|
||||
*/
|
||||
|
||||
#include "tts_player.h"
|
||||
|
||||
#include "player.h"
|
||||
#include "data_work.h"
|
||||
#include "audio_codec.h"
|
||||
|
||||
#include "dfs.h"
|
||||
#include "dfs_posix.h"
|
||||
|
||||
/**
|
||||
* play tts file list with Block mode, Wait for the last play to finish before playing
|
||||
*
|
||||
* @param files: the two-dimensional array for tts file list
|
||||
* @param num: the num of tts file list, it has to be greater than zero
|
||||
*
|
||||
* @return == RT_EOK: play success
|
||||
* ==-RT_EINVAL: invalid parameter
|
||||
*/
|
||||
rt_err_t tts_player_block(char *files[], rt_uint8_t num)
|
||||
{
|
||||
rt_uint8_t index = 0;
|
||||
static char buffer[2048] = {0};
|
||||
|
||||
rt_kprintf("start tts play.\n");
|
||||
|
||||
/* 检查传入 TTS 文件数量,数量不能为 0 */
|
||||
if(num == 0)
|
||||
{
|
||||
rt_kprintf("the number of songs cannot be zero.");
|
||||
return (-RT_EINVAL);
|
||||
}
|
||||
|
||||
/* 检查传入 TTS 文件是否为空 */
|
||||
while(1)
|
||||
{
|
||||
if(files[index] == RT_NULL)
|
||||
{
|
||||
rt_kprintf("the files cannot be empty.");
|
||||
return (-RT_EINVAL);
|
||||
}
|
||||
else
|
||||
{
|
||||
rt_kprintf("list[%d] = %s.\n", index, files[index]);
|
||||
}
|
||||
|
||||
index++;
|
||||
if(index >= num)
|
||||
{
|
||||
index = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* 等待上一次 TTS 或者歌曲播放完毕 */
|
||||
while(player_get_state() == PLAYER_STAT_PLAYING)
|
||||
{
|
||||
rt_thread_mdelay(1);
|
||||
}
|
||||
|
||||
/* 启动 TTS 播放 */
|
||||
player_play_data(CODEC_MP3, -1);
|
||||
|
||||
/* 循环打开列表文件写入音频数据到 player的 pipe中 */
|
||||
while(1)
|
||||
{
|
||||
int len = (-1);
|
||||
int fd = (-1);
|
||||
|
||||
fd = open(files[index], O_RDONLY);
|
||||
do{
|
||||
len = read(fd, buffer, 2048);
|
||||
if(len > 0)
|
||||
{
|
||||
player_write_data(buffer, len);
|
||||
}
|
||||
}
|
||||
while(len > 0);
|
||||
close(fd);
|
||||
|
||||
index++;
|
||||
if(index >= num)
|
||||
{
|
||||
index = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
data_work_set_content_length(1);
|
||||
|
||||
rt_kprintf("start tts play finish.\n");
|
||||
|
||||
return RT_EOK;
|
||||
}
|
||||
|
||||
/**
|
||||
* play tts file list with Break mode, break and does not resume the previous playback
|
||||
*
|
||||
* @param files: the two-dimensional array for tts file list
|
||||
* @param num: the num of tts file list, it has to be greater than zero
|
||||
*
|
||||
* @return == RT_EOK: play success
|
||||
* ==-RT_EINVAL: invalid parameter
|
||||
*/
|
||||
rt_err_t tts_player_break(char *files[], rt_uint8_t num)
|
||||
{
|
||||
rt_uint8_t index = 0;
|
||||
static char buffer[2048] = {0};
|
||||
|
||||
rt_kprintf("start tts play.\n");
|
||||
|
||||
/* 检查传入 TTS 文件数量,数量不能为 0 */
|
||||
if(num == 0)
|
||||
{
|
||||
rt_kprintf("the number of songs cannot be zero.");
|
||||
return (-RT_EINVAL);
|
||||
}
|
||||
|
||||
/* 检查传入 TTS 文件是否为空 */
|
||||
while(1)
|
||||
{
|
||||
if(files[index] == RT_NULL)
|
||||
{
|
||||
rt_kprintf("the files cannot be empty.");
|
||||
return (-RT_EINVAL);
|
||||
}
|
||||
else
|
||||
{
|
||||
rt_kprintf("list[%d] = %s.\n", index, files[index]);
|
||||
}
|
||||
|
||||
index++;
|
||||
if(index >= num)
|
||||
{
|
||||
index = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* 启动 TTS 播放 */
|
||||
player_play_data(CODEC_MP3, -1);
|
||||
|
||||
/* 循环打开列表文件写入音频数据到 player的 pipe中 */
|
||||
while(1)
|
||||
{
|
||||
int len = (-1);
|
||||
int fd = (-1);
|
||||
|
||||
fd = open(files[index], O_RDONLY);
|
||||
do{
|
||||
len = read(fd, buffer, 2048);
|
||||
if(len > 0)
|
||||
{
|
||||
player_write_data(buffer, len);
|
||||
}
|
||||
}
|
||||
while(len > 0);
|
||||
close(fd);
|
||||
|
||||
index++;
|
||||
if(index >= num)
|
||||
{
|
||||
index = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
data_work_set_content_length(1);
|
||||
|
||||
rt_kprintf("start tts play finish.\n");
|
||||
|
||||
return RT_EOK;
|
||||
}
|
37
beken_rtt_sdk_release-SDK_3.0.76/applications/tts_player.h
Normal file
37
beken_rtt_sdk_release-SDK_3.0.76/applications/tts_player.h
Normal file
@ -0,0 +1,37 @@
|
||||
/*
|
||||
* File: tts_player.h
|
||||
* COPYRIGHT (C) 2012-2018, Shanghai Real-Thread Technology Co., Ltd
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2019-05-05 liu2guang add play tts function(Block and Break).
|
||||
*/
|
||||
|
||||
#ifndef __TTS_PLAYER_H__
|
||||
#define __TTS_PLAYER_H__
|
||||
|
||||
#include "rtthread.h"
|
||||
|
||||
/**
|
||||
* play tts file list with Block mode, wait for the last play to finish before playing
|
||||
*
|
||||
* @param files: the two-dimensional array for tts file list
|
||||
* @param num: the num of tts file list, it has to be greater than zero
|
||||
*
|
||||
* @return == RT_EOK: play success
|
||||
* ==-RT_EINVAL: invalid parameter
|
||||
*/
|
||||
extern rt_err_t tts_player_block(char *files[], rt_uint8_t num);
|
||||
|
||||
/**
|
||||
* play tts file list with Break mode, break and does not resume the previous playback
|
||||
*
|
||||
* @param files: the two-dimensional array for tts file list
|
||||
* @param num: the num of tts file list, it has to be greater than zero
|
||||
*
|
||||
* @return == RT_EOK: play success
|
||||
* ==-RT_EINVAL: invalid parameter
|
||||
*/
|
||||
extern rt_err_t tts_player_break(char *files[], rt_uint8_t num);
|
||||
|
||||
#endif
|
@ -138,7 +138,7 @@
|
||||
#define CFG_BK_AWARE_OUI "\xC8\x47\x8C"
|
||||
#define CFG_RESTORE_CONNECT 0
|
||||
#define CFG_QUICK_TRACK 0
|
||||
|
||||
#define CFG_USE_BASE64 0
|
||||
/* use mbedtls as wpa crypto functions */
|
||||
#if( ( CFG_SUPPORT_ALIOS ) || ( CFG_SUPPORT_RTT ) )
|
||||
#define CFG_USE_MBEDTLS 0
|
||||
|
Loading…
x
Reference in New Issue
Block a user