-
Notifications
You must be signed in to change notification settings - Fork 3
/
Voice.cpp
321 lines (306 loc) · 7.03 KB
/
Voice.cpp
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
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
#include<Arduino.h>
#include <EEPROM.h>
#include"Voice.h"
#include"readSensor.h"
unsigned int buf[7] = {0x7E, 0x04, 0x44, 0x01, 0x00, 0xEF};
unsigned int buf_sound[5] = {0x7E, 0x03, 0x31, 0x1E, 0xEF};
unsigned int buf_cmd[4] = {0x7E, 0x02, 0x01, 0xEF};
extern int temperature, temperature_low_day1, temperature_high_day1; //实时温度,最低、最高温度
extern int code, code_day1, code_night1; //实时天气,白天、夜晚天气
extern int wind_scale_day1; //风力等级
extern String wind_direction_day1; //风向
extern String dressing, flu, sport, uv;
extern int tem, hum;
Sensor_Class Sensor2;
void Voice_Class::INIT()
{
pinMode(13, INPUT);
Serial2.begin(9600);
buf_sound[3] = EEPROM.read(0);
for (int i = 0; i < 5; i++)
Serial2.write(buf_sound[i]); //读取内存中的数据,并设置音量大小
Serial.println("Voice Init OK");
}
/*播放当前室内温湿度*/
void Voice_Class::playTemHum()
{
if (tem < 0)
buf[4] = (100 - tem);
else
buf[4] = tem;
buf[3] = 0x01;
if (digitalRead(13) == 1)
{
for (int i = 0 ; i < 7 ; i++)
Serial2.write(buf[i]);
}
buf[4] = hum;
buf[3] = 0x02;
if (digitalRead(13) == 1)
{
for (int i = 0 ; i < 7 ; i++)
Serial2.write(buf[i]);
}
}
void Voice_Class::playWeather()
{
buf[3] = 3;
buf[4] = code;
if (digitalRead(13) == 1)
{
for (int i = 0 ; i < 7 ; i++)
Serial2.write(buf[i]);
}
buf[3] = 4;
if (temperature_high_day1 < 0)
buf[4] = (100 - temperature_high_day1);
else
buf[4] = temperature_high_day1;
if (digitalRead(13) == 1)
{
for (int i = 0 ; i < 7 ; i++)
Serial2.write(buf[i]);
}
buf[3] = 5;
if (temperature_low_day1 < 0)
buf[4] = (100 - temperature_low_day1);
else
buf[4] = temperature_low_day1;
if (digitalRead(13) == 1)
{
for (int i = 0 ; i < 7 ; i++)
Serial2.write(buf[i]);
}
buf[3] = 6;
if (wind_direction_day1.indexOf("CLM") == 0)
buf[4] = 0;
if (wind_direction_day1.indexOf("E") == 0)
buf[4] = 1;
if (wind_direction_day1.indexOf("S") == 0)
buf[4] = 2;
if (wind_direction_day1.indexOf("W") == 0)
buf[4] = 3;
if (wind_direction_day1.indexOf("N") == 0)
buf[4] = 4;
if (wind_direction_day1.indexOf("ES") == 0 || wind_direction_day1.indexOf("SE") == 0)
buf[4] = 5;
if (wind_direction_day1.indexOf("EN") == 0 || wind_direction_day1.indexOf("NE") == 0)
buf[4] = 6;
if (wind_direction_day1.indexOf("WS") == 0 || wind_direction_day1.indexOf("SW") == 0)
buf[4] = 7;
if (wind_direction_day1.indexOf("WN") == 0 || wind_direction_day1.indexOf("NW") == 0)
buf[4] = 8;
if (digitalRead(13) == 1)
{
for (int i = 0 ; i < 7 ; i++)
Serial2.write(buf[i]);
}
buf[3] = 7;
buf[4] = wind_scale_day1;
if (digitalRead(13) == 1)
{
for (int i = 0 ; i < 7 ; i++)
Serial2.write(buf[i]);
}
buf[3] = 11;
if (temperature < 0)
buf[4] = 100 - temperature;
else
buf[4] = temperature;
if (digitalRead(13) == 1)
{
for (int i = 0 ; i < 7 ; i++)
Serial2.write(buf[i]);
}
}
void Voice_Class::playSuggestion()
{
/*
室外温度提醒
*/
buf[3] = 11;
if (temperature < 0)
buf[4] = 100 - temperature;
else
buf[4] = temperature;
if (digitalRead(13) == 1)
{
for (int i = 0 ; i < 7 ; i++)
Serial2.write(buf[i]);
}
delay(100);
/*
天气建议提醒
*/
if ((uv.indexOf("High") == 0) || ( uv.indexOf("Very High") == 0))
{
buf[3] = 8;
buf[4] = 2;
if (digitalRead(13) == 1)
{
for (int i = 0 ; i < 7 ; i++)
Serial2.write(buf[i]);
}
}
if ((flu.indexOf("Probably") == 0) || (flu.indexOf("Certainly") == 0))
{
buf[3] = 8;
buf[4] = 6;
if (digitalRead(13) == 1)
{
for (int i = 0 ; i < 7 ; i++)
Serial2.write(buf[i]);
}
}
if ((dressing.indexOf("Hot") == 0 ) || (dressing.indexOf("Very Hot") == 0))
{
buf[3] = 8;
buf[4] = 5;
if (digitalRead(13) == 1)
{
for (int i = 0 ; i < 7 ; i++)
Serial2.write(buf[i]);
}
}
if ((dressing.indexOf("Cold") == 0 ) || (dressing.indexOf("Very Cold") == 0))
{
buf[3] = 8;
buf[4] = 4;
if (digitalRead(13) == 1)
{
for (int i = 0 ; i < 7 ; i++)
Serial2.write(buf[i]);
}
}
if ((sport.indexOf("Good") == 0 ) || (sport.indexOf("Great") == 0))
{
buf[3] = 8;
buf[4] = 0;
if (digitalRead(13) == 1)
{
for (int i = 0 ; i < 7 ; i++)
Serial2.write(buf[i]);
}
}
if ((sport.indexOf("Not Good") == 0) || (sport.indexOf("Unfavorable") == 0))
{
buf[4] = 1;
buf[3] = 8;
if (digitalRead(13) == 1)
{
for (int i = 0 ; i < 7 ; i++)
Serial2.write(buf[i]);
}
}
/*
温差差距提醒
*/
if (abs(temperature - Sensor2.GET_TEM()) > 8)
{
buf[3] = 8;
buf[4] = 7;
if (digitalRead(13) == 1)
{
for (int i = 0 ; i < 7 ; i++)
Serial2.write(buf[i]);
}
}
/*
雨天提醒
*/
if ((code >= 10 ) && ( code <= 20))
{
buf[3] = 3;
buf[4] = code;
if (digitalRead(13) == 1)
{
for (int i = 0 ; i < 7 ; i++)
Serial2.write(buf[i]);
}
buf[3] = 8;
buf[4] = 3;
if (digitalRead(13) == 1)
{
for (int i = 0 ; i < 7 ; i++)
Serial2.write(buf[i]);
}
}
/*
雪天提醒
*/
if ((code >= 21 ) && ( code <= 25))
{
buf[3] = 3;
buf[4] = code;
if (digitalRead(13) == 1)
{
for (int i = 0 ; i < 7 ; i++)
Serial2.write(buf[i]);
}
buf[3] = 8;
buf[4] = 8;
if (digitalRead(13) == 1)
{
for (int i = 0 ; i < 7 ; i++)
Serial2.write(buf[i]);
}
}
}
void Voice_Class::play(int m, int n)
{
buf[3] = m;
buf[4] = n;
if (digitalRead(13) == 1)
{
for (int i = 0; i < 7; i++)
Serial2.write(buf[i]);
}
}
void Voice_Class::setvolume(int volume)
{
buf_sound[3] = volume;
for (int i = 0; i < 5; i++)
Serial2.write(buf_sound[i]);
buf[3] = 10;
buf[4] = 20;
if (digitalRead(13) == 1) //播放试听音效
{
for (int i = 0; i < 7; i++)
Serial2.write(buf[i]);
}
EEPROM.write(0, volume); //写入内存中
}
int Voice_Class::getvolume()
{
// int s;
// for (int i = 0; i < 4; i++)
// Serial2.write(buf_volume[i]);
// while(Serial2.available()>0)
// return Serial2.read();
}
void Voice_Class::VolumeUP()
{
buf_cmd[2] = 5;
for (int i = 0; i < 5; i++)
Serial2.write(buf_cmd[i]);
buf[3] = 10;
buf[4] = 20;
if (digitalRead(13) == 1) //播放试听音效
{
for (int i = 0; i < 7; i++)
Serial2.write(buf[i]);
}
}
void Voice_Class::VolumeReduce()
{
buf_cmd[2] = 6;
for (int i = 0; i < 5; i++)
Serial2.write(buf_cmd[i]);
buf[3] = 10;
buf[4] = 20;
if (digitalRead(13) == 1) //播放试听音效
{
for (int i = 0; i < 7; i++)
Serial2.write(buf[i]);
}
}