forked from PowerBroker2/DFPlayerMini_Fast
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDFPlayerMini_Fast.cpp
More file actions
98 lines (73 loc) · 1.49 KB
/
DFPlayerMini_Fast.cpp
File metadata and controls
98 lines (73 loc) · 1.49 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
#include "DFPlayerMini_Fast.h"
void DFPlayerMini_Fast::begin(Stream &stream)
{
_serial = &stream;
return;
}
void DFPlayerMini_Fast::findChecksum()
{
uint16_t checksum = (~(VER + LEN + commandValue + FEEDBACK + paramMSB + paramLSB)) + 1;
checksumMSB = checksum >> 8;
checksumLSB = checksum & 0xFF;
return;
}
void DFPlayerMini_Fast::volume(uint8_t volume)
{
commandValue = VOLUME_COMMAND;
paramMSB = 0;
paramLSB = volume;
findChecksum();
sendData();
return;
}
void DFPlayerMini_Fast::play(uint16_t fileNum)
{
commandValue = PLAY_COMMAND;
paramMSB = (fileNum >> 8) & 0xFF;
paramLSB = fileNum & 0xFF;
findChecksum();
sendData();
return;
}
void DFPlayerMini_Fast::EQSelect(uint8_t setting)
{
commandValue = EQ_COMMAND;
paramMSB = 0;
paramLSB = setting;
findChecksum();
sendData();
return;
}
void DFPlayerMini_Fast::pause()
{
commandValue = PAUSE_COMMAND;
paramMSB = 0;
paramLSB = 0;
findChecksum();
sendData();
return;
}
void DFPlayerMini_Fast::resume()
{
commandValue = RESUME_COMMAND;
paramMSB = 0;
paramLSB = 0;
findChecksum();
sendData();
return;
}
void DFPlayerMini_Fast::sendData()
{
_sending[0] = SB;
_sending[1] = VER;
_sending[2] = LEN;
_sending[3] = commandValue;
_sending[4] = FEEDBACK;
_sending[5] = paramMSB;
_sending[6] = paramLSB;
_sending[7] = checksumMSB;
_sending[8] = checksumLSB;
_sending[9] = EB;
_serial->write(_sending, DFPLAYER_SEND_LENGTH);
return;
}