JZ_speaker.c
7.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
/* Includes ------------------------------------------------------------------*/
#include "JZ_speaker.h"
#include "JZ_lamp.h"
#include "music.h"
#include "JZ_TempControl.h"
#include <unistd.h>
#include <stdio.h>
#include "version_choose.h"
#include <stdarg.h>
#include <time.h>
#if SPECIAL_VERSION == SPECIAL_GDU
#include "test_widget.h"
#include "gdu_logger.h"
#endif
/* Private constants ---------------------------------------------------------*/
/* Private types -------------------------------------------------------------*/
/* Private values -------------------------------------------------------------*/
extern int tts_add;
extern int tts_tone;
extern int tts_speed;
extern int readyflag;//喊话器准备就绪标志
extern int tempControlFlag;
extern TempControlData *tempData;//温度控制数据
/* Private functions declaration ---------------------------------------------*/
/* Exported functions definition ---------------------------------------------*/
/************************************
*文本喊话语速控制功能
*函数名:JZ_SpeechSpeedControlFeature
*函数参数:
@speed : 喊话速度 0-3
*返回值:
*函数作者:wzy
*************************************/
void JZ_SpeechSpeedControlFeature(uint8_t speed)
{
switch(speed){
case 0:
tts_speed=25;
break;
case 1:
tts_speed=50;
break;
case 2:
tts_speed=75;
break;
case 3:
tts_speed=100;
break;
default:
tts_speed=50;
break;
}
}
/************************************
*文本喊话音色控制功能
*函数名:JZ_TtsToneColorFeature
*函数参数:
@tone: 音色选择列表
0---中文女生---1
1---中文男生---2
2---英文女生---11
3---英文男生---12
4---东北话-----31
5---四川话-----32
6---河南话-----33
7---湖南话-----34
8---陕西话-----35
9---广东话-----36
*返回值:
*函数作者:wzy
*************************************/
void JZ_TtsToneColorFeature(uint8_t tone)
{
switch(tone){
case 0:
tts_tone=1;
break;
case 1:
tts_tone=2;
break;
case 2:
tts_tone=11;
break;
case 3:
tts_tone=12;
break;
case 4:
tts_tone=31;
break;
case 5:
tts_tone=32;
break;
case 6:
tts_tone=33;
break;
case 7:
tts_tone=34;
break;
case 8:
tts_tone=35;
break;
case 9:
tts_tone=36;
break;
default:
tts_tone=1;
break;
}
}
/************************************
*文本播放功能
*函数名:JZ_TtsPlayFeature
*函数参数:
@len:文本长度
@data:文本数据
*返回值:
*函数作者:wzy
*************************************/
int JZ_TtsPlayFeature(int len,char* data)
{
if(readyflag == 0)
{
return -1;
}
while (GetRecordStatus() == 1 || GetTtsStatus() == 1)
{
usleep(100*1000);
}
usleep(700*1000);
if(GetSpeakerMode() == 2)
{
TTS(tts_tone,100,tts_speed,len,data);
}
}
/************************************
*亮度控制功能
*函数名:Jz_LampLumenControlFeature
*函数参数:
@value1: 左灯亮度(十进制) 0~100
@value2: 右灯亮度(十进制) 0~100
*返回值:
*函数作者:wzy
*************************************/
void JZ_LampLumenControlFeature(uint8_t value1,uint8_t value2)
{
int value = 0;
if(value1 > value2)
{
value = value1;
}
else
{
value = value2;
}
// value = value1 > value2 ? value1 : value2;
tempData->InputLumen = value;//改变温控输入亮度
JZ_LightSetInitialLumen(value);//改变设置的亮度初值
tempControlFlag = TEMP_NOTTRIGGER;//防止温度跳回去
Jz_LampLumenControl(value1,value2);//控制探照灯亮度
}
/************************************
*云台控制功能
*函数名:Jz_LampGimbalControlFeature
*函数参数:
@value: 从飞机得到的云台角度
*返回值:
*函数作者:wzy
*************************************/
void Jz_LampGimbalControlFeature(int value)
{
if(value <= 0)
{
int angle = -value;
Jz_Lamp_Gimbal_Control(angle);
}
else
{
Jz_Lamp_Gimbal_Control(0);//U3S云台角度为0~90
}
}
/************************************
*提取 . 之前的字符串
*函数名:JZ_GetBeforeChar
*函数参数:
@dest: 被截取的字符串
@src: 截取后的字符串
*返回值:
*函数作者:wzy
*************************************/
void JZ_GetBeforeChar(const char *dest,char *src)
{
size_t len;
len = strrchr(dest, '.') - dest;//计算文件名长度
memcpy(src, "\0", 256);
strncpy(src, dest, len);//取文件名
src[len] = '\0';
}
/************************************
*延时执行任务线程创建
*函数名: JZ_DelayThreadCreate
*函数参数:
@delayTime: 延时时间
@function: 延时执行的任务
*返回值:
*函数作者:wzy
*************************************/
void JZ_DelayThreadCreate(int delayTime)
{
pthread_t thread;
pthread_attr_t task_attr;
pthread_attr_init(&task_attr); //初始化线程属性
pthread_attr_setdetachstate(&task_attr, PTHREAD_CREATE_DETACHED); //设置线程分离属性
pthread_t tid;
int ret;
if(delayTime > 0)
{
//创建线程,延时执行
ret = pthread_create(&tid,&task_attr,JZ_TempControlFlag,(void *)&delayTime);
if (ret != 0)
{
printf("线程创建失败\n");
}
}
}
/************************************
*设置UI控件值
*函数名: Jz_set_widget_value
*函数参数:
@index: 控件编号
@value: 控件值
*返回值:
*函数作者:wzy
*************************************/
void Jz_set_widget_value(int index,int value)
{
//如不是道通,则设置控件的值
#if SPECIAL_VERSION != SPECIAL_UAV
set_widget_value(index,value);
#endif
}
/************************************
*输出信息
*函数名: JZ_LOG_INFO
*函数参数:
*返回值:
*函数作者:wzy
*************************************/
void JZ_LOG_INFO(const char *format, ...)
{
#if SPECIAL_VERSION == SPECIAL_GDU
va_list args;
va_start(args, format);
USER_LOG_INFO(format, args); // 传递参数给 USER_LOG_INFO
va_end(args);
#else
FILE *file = fopen("/root/sdcard/debuglog.txt", "a"); // "a" 模式表示追加内容到文件末尾
if (file == NULL) {
perror("无法打开日志文件");
return;
}
// 获取当前时间
time_t now;
time(&now);
struct tm *local = localtime(&now);
// 写入时间戳和消息到文件
fprintf(file, "[%04d-%02d-%02d %02d:%02d:%02d] %s\n",
local->tm_year + 1900, local->tm_mon + 1, local->tm_mday,
local->tm_hour, local->tm_min, local->tm_sec, format);
// 关闭文件
fclose(file);
#endif
}