Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
rwpalmer committed Aug 29, 2018
1 parent 198a3ae commit f29a812
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 10 deletions.
10 changes: 9 additions & 1 deletion examples/PlayList.ino
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
uint16_t plx = 0; // <-- playList index
Selection emptySelection = {0,0,0,0,0}; // <-- empty selection object for clearing Selection objects (as used on the next line)
Selection selection = emptySelection; // <-- selection specified by the "setSelection" Particle Function ...

bool playFailureHandled = false;

void setup() {
Particle.function("Selection", setSelection); // <-- this function is used to enter Selection objects
Expand All @@ -36,8 +36,16 @@ void loop() {

// ------------------------------------------------- Decides what to play next based on Particle Function dfCommand() input
if (dfPlay.isIdle()) {
// if the last play failed, delete the Selection from the playlist
if ((dfPlay.playFailure()) && (!playFailureHandled)) {
playlist.erase(playlist.begin() + --plx);
Serial.printf(" playFailure is true: Selection %d deleted\n\r", plx+1);
playFailureHandled = true;
}
// Play the next Selection in the playlist
if (plx < playlist.size()) {
dfPlay.play(playlist[plx]);
playFailureHandled = false;
Serial.printf("\n\r---------------------------------------- Playing Selection %d:{%d,%d,%d,%d,%d}\n\r", plx+1,
playlist[plx].media,playlist[plx].folder, playlist[plx].track, playlist[plx].volAdj, playlist[plx].equalizer);
plx++;
Expand Down
4 changes: 4 additions & 0 deletions src/DFPlay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ void DFPlay::begin(void) { // initialize class members and query DFPlayer to
this->cState.volume = 30;
this->cState.media = 0;
this->cState.playType = TBD;
this->cState.playFailure = false;
this->cState.usbAttached = false;
this->cState.sdAttached = false;
this->cState.noSubmitsTil = 0;
Expand All @@ -53,6 +54,7 @@ void DFPlay::play(Selection& sel) {
this->dState.skip = false;
this->cState.tracks = 0;
this->cState.changePending = true;
this->cState.playFailure = false;
return;
}
void DFPlay::pause(void) {
Expand Down Expand Up @@ -140,6 +142,7 @@ bool DFPlay::isPlaying(void) { if (this->dState.playState == PLAYING) return t
bool DFPlay::isPaused(void) { if (this->dState.playState == PAUSED) return true; else return false; }
bool DFPlay::isRepeating(void) { if (this->dState.repeat) return true; else return false; }
bool DFPlay::isSleeping(void) { return this->cState.sleeping; }
bool DFPlay::playFailure(void) { return this->cState.playFailure; }


// ----------------------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -284,6 +287,7 @@ void DFPlay::manageDevice(void) {
this->cState.idleMillis = millis();
this->dState.playState = IDLE;
this->cState.changePending = true;
this->cState.playFailure = true;
#ifdef LOGGING
Serial.println("Play Failure ...");
#endif
Expand Down
20 changes: 11 additions & 9 deletions src/DFPlay.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,16 @@ class CurrentState {
uint8_t volume; // the current volume state (0 to 30)
uint8_t media; // identifies the currently selected media (USB, SD, SLEEP)
uint8_t playType; // the current play type (TBD, MEDIA, FOLDER, or TRACK)
bool usbAttached; // true indicates that a USB key is attached to the DFPlayer
bool sdAttached; // true indicates that an SD card is attached to the DFPlayer
bool sleeping; // true indicates that the DFPlayer is in low-power mode
bool changePending; // true tells manageDevice() that a state change is pending
bool firstEot; // true identifies first End-Of-Track frame
uint32_t noSubmitsTil; // the time when the DFPlayer will be ready to accept the next command
uint32_t trackCount; // the number of tracks that have been played in a folder or media selection
uint32_t idleMillis; // millis when cState.playState was set to IDLE
int tracks; // the number of tracks in a folder or media selection
bool playFailure; // true indicates that the last play command returned an error
bool usbAttached; // true indicates that a USB key is attached to the DFPlayer
bool sdAttached; // true indicates that an SD card is attached to the DFPlayer
bool sleeping; // true indicates that the DFPlayer is in low-power mode
bool changePending; // true tells manageDevice() that a state change is pending
bool firstEot; // true identifies first End-Of-Track frame
uint32_t noSubmitsTil; // the time when the DFPlayer will be ready to accept the next command
uint32_t trackCount; // the number of tracks that have been played in a folder or media selection
uint32_t idleMillis; // millis when cState.playState was set to IDLE
int tracks; // the number of tracks in a folder or media selection
};

class DFPlay {
Expand Down Expand Up @@ -117,6 +118,7 @@ class DFPlay {
bool isPaused(void);
bool isRepeating(void);
bool isSleeping(void);
bool playFailure(void);
void manageDevice(void);
};
#endif

0 comments on commit f29a812

Please sign in to comment.