forked from hvtil/Wonderfoon_ATTINY85
/
function_general.ino
128 lines (116 loc) · 2.69 KB
/
function_general.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
void checkPlaying()
{
if (digitalRead(busyPin) == 1)
{
if (playingRandom) {
delay(1000);
playTrackInFolder(1, 1);
}
}
}
void clearLastDialed()
{
lastDialed[0] = 20;
lastDialed[1] = 21;
lastDialed[2] = 22;
}
void addLastNumber(int newNumber) {
lastDialed[0] = lastDialed[1];
lastDialed[1] = lastDialed[2];
lastDialed[2] = newNumber;
}
void addLastTime(long newTime) {
lastTime[0] = lastTime[1];
lastTime[1] = lastTime[2];
lastTime[2] = newTime;
}
void checkAll()
{
switch (lastDialed[0])
{
case 1:
//112
if (lastDialed[1] == 1 && checkChangeTime())
{
if ( lastDialed[2] == 2 )
{
playAlarm();
clearLastDialed();
}
}
break;
case 2:
//volume
if (lastDialed[1] == 1 && checkChangeTime())
{
EEPROM_storeVolume(lastDialed[2]);
setMP3Volume(lastDialed[2]);
playVolume();
clearLastDialed();
}
break;
case 3:
//Folder
if (lastDialed[1] == 1 && checkChangeTime())
{
if ( lastDialed[2] < 4 )
{
EEPROM_storeFolder(lastDialed[2]);
playFolder(lastDialed[2]);
folderNumber = lastDialed[2];
clearLastDialed();
}
}
break;
case 4:
///Random
if (lastDialed[1] == 1 && checkChangeTime())
{
if ( lastDialed[2] < 3 )
{
EEPROM_storePlayMode(lastDialed[2] - 1);
playWillekeurig(lastDialed[2] - 1);
playMode = lastDialed[2] - 1;
clearLastDialed();
}
}
break;
case 5:
//continue
if (lastDialed[1] == 1 && checkChangeTime())
{
if ( lastDialed[2] == 1 )
{
playingRandom = true;
playContinu();
clearLastDialed();
}
}
break;
case 9:
//reset
if (lastDialed[1] == 9 && checkChangeTime())
{
if ( lastDialed[2] == 9 )
{
playReset();
EEPROM_init(true);
audioVolume = EEPROM_getValue(6000);
folderNumber = EEPROM_getValue(6001);
playMode = EEPROM_getValue(6002);
mp3Wake();
playVolume(); // play vulume status
playFolder(folderNumber); // play folder number status
playWillekeurig(playMode);
clearLastDialed();
}
}
break;
}
}
bool checkChangeTime() {
if (lastTime[2] - lastTime[0] < 10000)
return true;
else
return false;
}