-
Notifications
You must be signed in to change notification settings - Fork 32
/
DYPlayerArduino.cpp
executable file
·63 lines (61 loc) · 1.27 KB
/
DYPlayerArduino.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
/*
This is a hardware abstraction layer, it tells the library how to use the
serial port on an Arduino board (and which port).
*/
#ifdef ARDUINO
#include "DYPlayerArduino.h"
namespace DY
{
Player::Player()
{
this->port = &Serial;
this->isSoftSerial = false;
}
#ifdef HAS_HARDWARE_SERIAL
Player::Player(HardwareSerial *port)
{
this->port = (Stream *)port;
this->isSoftSerial = false;
}
#endif
#ifdef HAS_SOFTWARE_SERIAL
Player::Player(SoftwareSerial *port)
{
this->port = (Stream *)port;
this->isSoftSerial = true;
}
#endif
void Player::begin()
{
if (isSoftSerial)
{
#ifdef HAS_SOFTWARE_SERIAL
((SoftwareSerial *)port)->begin(9600);
while (!((SoftwareSerial *)port))
; // wait for port to be connected
#endif
}
else
{
#ifdef HAS_HARDWARE_SERIAL
((HardwareSerial *)port)->begin(9600);
while (!((HardwareSerial *)port))
; // wait for port to be connected
#endif
}
}
void Player::serialWrite(uint8_t *buffer, uint8_t len)
{
port->write(buffer, len);
}
bool Player::serialRead(uint8_t *buffer, uint8_t len)
{
// Serial.setTimeout(1000); // Default timeout 1000ms.
if (port->readBytes(buffer, len) > 0)
{
return true;
}
return false;
}
}
#endif