-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmp3.ino
145 lines (128 loc) · 3.33 KB
/
mp3.ino
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
void initMP3() {
mp3Serial.begin(9600);
mp3Player.begin(mp3Serial);
PRINTLNF("trying init DFPlayer");
mp3Player.volume(30); //set volume value. From 0 to 30
mp3Player.pause();
}
void playGSM() {
if (workFlag) { //play switch on/off
addAudio(34);
thermostatFlag ? addAudio(55) : addAudio(56); //play switch on/off //play thermostat on/off
}
else {
addAudio(35);
}
playTemp(0); //play temp home
playTemp(1); //play temp heater
playBalance();
//playSignalStrength(); //TODO
playAudio();
}
bool isMP3Busy() {
return digitalRead(MP3_BUSY) == LOW; //resistors! https://github.com/DFRobot/DFRobotDFPlayerMini/issues/20
}
bool addAudio(uint8_t num_track) {
if (!audioQueue.isFull())
return audioQueue.push(num_track);
else { PRINTLNF("audioQueue isFull");
return false;}
}
void playAudio() {
if (isMP3Busy() ) {
timer.setTimeout(40L, playAudio);
return;
}
if (audioQueue.isEmpty()) {
PRINTLNF("audioQueue isEmpty");
if (GSMonAirFlag)
hangUpGSM();
return;
}
// PRINTLN("audioQueue ",audioQueue.size());
mp3Player.play(audioQueue.shift());
timer.setTimeout(40L, playAudio);
}
void playTemp(uint8_t temp_sens_num) {
if (temp[temp_sens_num]==-99) // has no data
return;
if (temp_sens_num==0) { //play temp source (temp1 or temp2)
addAudio(37); // home temp
}
else {
addAudio(36); // heater temp
}
//play zero temp
uint8_t abs_temp = abs(temp[temp_sens_num]);
if (abs_temp == 0) {
addAudio(28);
}
else { //if not zero
playNumber(abs_temp);
}
//play 'degree'
uint8_t first_digit = abs_temp % 10;
uint8_t second_digit = (abs_temp / 10) % 10;
if ((abs_temp != 11) && (first_digit == 1)) {
addAudio(31);// градус
}
else if (first_digit >= 2 && first_digit <=4 && second_digit != 1) {
addAudio(33);// градуса
}
else
addAudio(32);// градусов
//play sign
if (temp[temp_sens_num] > 0) //if zero - not playing sign
addAudio(30);
else if (temp[temp_sens_num] < 0)
addAudio(29);
}
void playBalance() {
if (balance == -32768) //no data, int16_t balance = -32768;
return;
if (balance < 0) //play sign
addAudio(29);
addAudio(38); // play 'balance'
uint8_t abs_balance = abs(balance);
playNumber(abs_balance);
//play 'ruble'
uint8_t two_first_digit = abs_balance % 100;
uint8_t first_digit = two_first_digit % 10;
uint8_t second_digit = (two_first_digit / 10) % 10;
if ((two_first_digit != 11) && (first_digit == 1)) {
addAudio(39); //рубль
}
else if (first_digit >= 2 && first_digit <=4 && second_digit != 1) {
addAudio(41);//рубля
}
else
addAudio(40);//рублей
}
void playNumber(uint16_t num) {
//play zero temp
if (num==0) {
addAudio(28);
return;
}
else { //if not zero
//play hundreds
if (num/100 > 0)
addAudio(45+(num / 100));
//play tens and units
if ((num > 0) && (num <= 20)) {
addAudio(num); //play temp 1 - 20
}
else {
for (uint8_t i = 2; i < 9; i++) //play temp 21 - 99
{
uint8_t first_digit = i*10;
uint8_t last_digit = first_digit+10;
if ( (num >= first_digit) && (num < last_digit)) {
uint8_t digits = num - first_digit;
addAudio(18+i);
if (digits !=0 ) addAudio(digits);
}
}
}
}
}