Skip to content

Commit

Permalink
Merge pull request #7 from FedericoBusero/master
Browse files Browse the repository at this point in the history
Arduino AVR chip - logging - compiling error
  • Loading branch information
rwpalmer authored Sep 7, 2018
2 parents 5aec508 + b4ca36b commit 985781f
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 22 deletions.
91 changes: 69 additions & 22 deletions src/DFPlay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,17 @@ void DFPlay::manageDevice(void) {
}
}
#ifdef DFPLAY_DEBUG_SERIAL
DFPLAY_DEBUG_SERIAL.printf("Response: %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x\n\r",
frame[0],frame[1],frame[2],frame[3],frame[4],frame[5],frame[6],frame[7],frame[8],frame[9]);
DFPLAY_DEBUG_SERIAL.print("Response:");
for (int i = 0; i<10; i++) {
#ifdef SPARK
DFPLAY_DEBUG_SERIAL.printf(" %02x", frame[i]);
#else
DFPLAY_DEBUG_SERIAL.print(" ");
DFPLAY_DEBUG_SERIAL.print(frame[i]>>4,HEX);
DFPLAY_DEBUG_SERIAL.print(frame[i]&0x0F,HEX);
#endif
}
DFPLAY_DEBUG_SERIAL.println();
#endif
if (frameError) {
// HANDLE FRAMING ERRORS ... RESYNC TO NEXT POSSIBLE FIRST BYTE CHARACTER
Expand Down Expand Up @@ -409,8 +418,7 @@ void DFPlay::manageDevice(void) {
}
#ifdef DFPLAY_DEBUG_SERIAL
if (this->dState.newSelection == true) {
DFPLAY_DEBUG_SERIAL.printf("\nSelection: {%d,%d,%d,%d,%d}\n\r", this->dState.selection.media, this->dState.selection.folder,
this->dState.selection.track, this->dState.selection.volAdj, this->dState.selection.equalizer);
debug_print_state("\nSelection",false);
}
#endif

Expand Down Expand Up @@ -591,9 +599,7 @@ void DFPlay::manageDevice(void) {
} else if (cState.tracks > 0) {
// Issue the DFPlayer command to play the media
#ifdef DFPLAY_DEBUG_SERIAL
DFPLAY_DEBUG_SERIAL.printf("Play Media: {%d,%d,%d,%d,%d} ... %d Tracks\n\r",
this->dState.selection.media, this->dState.selection.folder, this->dState.selection.track,
this->dState.selection.volAdj, this->dState.selection.equalizer, this->cState.tracks);
debug_print_state("Play Media",true);
#endif
uint16_t cs = 0xFEFB - (0x11 + this->dState.selection.media); // compute checksum
uint8_t request[] = { 0x7E, 0xFF, 0x06, 0x11, 0x00, 0x00, this->dState.selection.media, (uint8_t)(cs / 256), (uint8_t)(cs % 256), 0xEF};
Expand All @@ -615,8 +621,7 @@ void DFPlay::manageDevice(void) {
}
} else { // dState.selection.track is not 0, so we play a track based on a track number.
#ifdef DFPLAY_DEBUG_SERIAL
DFPLAY_DEBUG_SERIAL.printf("Play Track#: {%d,%d,%d,%d,%d}\n\r", this->dState.selection.media, this->dState.selection.folder,
this->dState.selection.track, this->dState.selection.volAdj, this->dState.selection.equalizer);
debug_print_state("Play Track#",false);
#endif
uint16_t cs = 0xFEFB - (0x08 + (this->dState.selection.track / 256) + (this->dState.selection.track % 256)); // compute checksum
uint8_t request[] = { 0x7E, 0xFF, 0x06, 0x08, 0x00, (uint8_t)(this->dState.selection.track / 256),
Expand All @@ -640,9 +645,7 @@ void DFPlay::manageDevice(void) {
} else if (cState.tracks > 0) {
// Issue the DFPlayer command to play the folder
#ifdef DFPLAY_DEBUG_SERIAL
DFPLAY_DEBUG_SERIAL.printf("Play Folder: {%d,%d,%d,%d,%d} ... %d Tracks\n\r",
this->dState.selection.media, this->dState.selection.folder, this->dState.selection.track,
this->dState.selection.volAdj, this->dState.selection.equalizer, this->cState.tracks);
debug_print_state("Play Folder",true);
#endif
uint16_t cs = 0xFEFB - (0x17 + this->dState.selection.folder); // compute checksum
uint8_t request[] = { 0x7E, 0xFF, 0x06, 0x17, 0x00, 0x00, this->dState.selection.folder, (uint8_t)(cs / 256), (uint8_t)(cs % 256), 0xEF};
Expand All @@ -667,8 +670,7 @@ void DFPlay::manageDevice(void) {
// RULE C6 - Play an individual track track from folders 01 to 15 ... Track must have a 4-digit file name prefix
if (this->dState.selection.folder < 16) {
#ifdef DFPLAY_DEBUG_SERIAL
DFPLAY_DEBUG_SERIAL.printf("Play 4-digit prefix: {%d,%d,%d,%d,%d}\n\r", this->dState.selection.media, this->dState.selection.folder,
this->dState.selection.track, this->dState.selection.volAdj, this->dState.selection.equalizer);
debug_print_state("Play 4-digit prefix",false);
#endif
uint16_t dbyte = ((this->dState.selection.folder * 4096) + this->dState.selection.track);
uint16_t cs = 0xFEFB - (0x14 + (dbyte / 256) + (dbyte % 256)); // compute checksum
Expand All @@ -680,8 +682,7 @@ void DFPlay::manageDevice(void) {
// RULE C7 - Play an individual track track from folders 16 to 99 ... Track must have a 3-digit file name prefix
if ((this->dState.selection.folder > 15) && (this->dState.selection.folder < 100)) {
#ifdef DFPLAY_DEBUG_SERIAL
DFPLAY_DEBUG_SERIAL.printf("Play 3-digit prefix: {%d,%d,%d,%d,%d}\n\r", this->dState.selection.media, this->dState.selection.folder,
this->dState.selection.track, this->dState.selection.volAdj, this->dState.selection.equalizer);
debug_print_state("Play 3-digit prefix",false);
#endif
uint16_t cs = 0xFEFB - (0x0F + this->dState.selection.folder + this->dState.selection.track); // compute checksum
uint8_t request[] = { 0x7E, 0xFF, 0x06, 0x0F, 0x00, this->dState.selection.folder, (uint8_t)this->dState.selection.track, (uint8_t)(cs / 256), (uint8_t)(cs % 256), 0xEF};
Expand All @@ -692,8 +693,7 @@ void DFPlay::manageDevice(void) {
// RULE C8 - Play a track from the root folder ... Track must have a 4-digit file name prefix
if (this->dState.selection.folder == 100) {
#ifdef DFPLAY_DEBUG_SERIAL
DFPLAY_DEBUG_SERIAL.printf("Play root: {%d,%d,%d,%d,%d}\n\r", this->dState.selection.media, this->dState.selection.folder,
this->dState.selection.track, this->dState.selection.volAdj, this->dState.selection.equalizer);
debug_print_state("Play root",false);
#endif
uint16_t cs = 0xFEFB - (0x03 + (this->dState.selection.track / 256) + (this->dState.selection.track % 256)); // compute checksum
uint8_t request[] = { 0x7E, 0xFF, 0x06, 0x03, 0x00, (uint8_t)(this->dState.selection.track / 256),
Expand All @@ -705,8 +705,7 @@ void DFPlay::manageDevice(void) {
// RULE C9 - Play a track from the MP3 folder ... Track must have a 4-digit file name prefix
if (this->dState.selection.folder == 101) {
#ifdef DFPLAY_DEBUG_SERIAL
DFPLAY_DEBUG_SERIAL.printf("Play MP3: {%d,%d,%d,%d,%d}\n\r", this->dState.selection.media, this->dState.selection.folder,
this->dState.selection.track, this->dState.selection.volAdj, this->dState.selection.equalizer);
debug_print_state("Play MP3",false);
#endif
uint16_t cs = 0xFEFB - (0x12 + (this->dState.selection.track / 256) + (this->dState.selection.track % 256)); // compute checksum
uint8_t request[] = { 0x7E, 0xFF, 0x06, 0x12, 0x00, (uint8_t)(this->dState.selection.track / 256),
Expand Down Expand Up @@ -741,14 +740,62 @@ void DFPlay::submitRequest(uint8_t request[], uint16_t dlay) {
#ifdef DFPLAY_DEBUG_SERIAL
DFPLAY_DEBUG_SERIAL.print(" Request:");
for (int i = 0; i<requestLength; i++) {
DFPLAY_DEBUG_SERIAL.printf(" %02x", request[i]);
#ifdef SPARK
DFPLAY_DEBUG_SERIAL.printf(" %02x", request[i]);
#else
DFPLAY_DEBUG_SERIAL.print(" ");
DFPLAY_DEBUG_SERIAL.print(request[i]>>4,HEX);
DFPLAY_DEBUG_SERIAL.print(request[i]&0x0F,HEX);
#endif
}
DFPLAY_DEBUG_SERIAL.println();
#endif
stream->write(request,requestLength);
this->cState.noSubmitsTil = millis() + dlay;
}

void DFPlay::debug_print_state(const char *commandstr, bool showtracks)
{
#ifdef DFPLAY_DEBUG_SERIAL
#ifdef SPARK
if (showtracks)
{
DFPLAY_DEBUG_SERIAL.printf("%s: {%d,%d,%d,%d,%d} ... %d Tracks\n\r", commandstr,
this->dState.selection.media, this->dState.selection.folder, this->dState.selection.track,
this->dState.selection.volAdj, this->dState.selection.equalizer, this->cState.tracks);
}
else
{
DFPLAY_DEBUG_SERIAL.printf("%s: {%d,%d,%d,%d,%d}\n\r", commandstr,
this->dState.selection.media, this->dState.selection.folder, this->dState.selection.track,
this->dState.selection.volAdj, this->dState.selection.equalizer);
}
#else
DFPLAY_DEBUG_SERIAL.print(commandstr);
DFPLAY_DEBUG_SERIAL.print(F(": {"));
DFPLAY_DEBUG_SERIAL.print(this->dState.selection.media);
DFPLAY_DEBUG_SERIAL.print(F(","));
DFPLAY_DEBUG_SERIAL.print(this->dState.selection.folder);
DFPLAY_DEBUG_SERIAL.print(F(","));
DFPLAY_DEBUG_SERIAL.print(this->dState.selection.folder);
DFPLAY_DEBUG_SERIAL.print(F(","));
DFPLAY_DEBUG_SERIAL.print(this->dState.selection.track);
DFPLAY_DEBUG_SERIAL.print(F(","));
DFPLAY_DEBUG_SERIAL.print(this->dState.selection.volAdj);
DFPLAY_DEBUG_SERIAL.print(F(","));
DFPLAY_DEBUG_SERIAL.print(this->dState.selection.equalizer);
DFPLAY_DEBUG_SERIAL.print(F("}"));
if (showtracks)
{
DFPLAY_DEBUG_SERIAL.print(F(" ... "));
DFPLAY_DEBUG_SERIAL.print(this->cState.tracks);
DFPLAY_DEBUG_SERIAL.print(F(" Tracks"));
}
DFPLAY_DEBUG_SERIAL.println();
#endif
#endif
}


/* DFPlayer Notes:
Expand All @@ -772,4 +819,4 @@ void DFPlay::submitRequest(uint8_t request[], uint16_t dlay) {





1 change: 1 addition & 0 deletions src/DFPlay.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ class DFPlay {
// PRIVATE METHODS
void submitRequest(uint8_t[] ,uint16_t);
void submitRequest(uint8_t[] ,uint16_t, uint8_t);
void debug_print_state(const char *commandstr, bool showtracks);

// PUBLIC METHODS
public:
Expand Down

0 comments on commit 985781f

Please sign in to comment.