LCC Fusion Project 1.0
LCC Automation
Loading...
Searching...
No Matches
SoundCardPlayer Class Reference

Controls a DFPlayer Mini via SoftwareSerial, with save/restore functionality. More...

#include <SoundCardPlayer.h>

Public Member Functions

 SoundCardPlayer ()
 Construct a new SoundCardPlayer instance. More...
 
bool isPlaying ()
 Check if the DFPlayer is currently playing audio. More...
 
void play (uint8_t fileNum, uint8_t volume)
 Play a single file once at the given volume. More...
 
void loop (uint8_t fileNum, uint8_t volume)
 Loop playback of a file indefinitely at the given volume. More...
 
void pause ()
 Pause current playback.
 
void reset ()
 Reset the DFPlayer and clear saved state file.
 
void save ()
 Persist current playback state (request, file, volume, playing flag) to SPIFFS.
 
void restore ()
 Restore playback state from SPIFFS and resume if it was playing.
 
void testPlayer (uint8_t volumePct=25)
 Perform ready checks and play the first track if present. More...
 

Private Member Functions

void openSaveFile_ ()
 Open or create the SPIFFS save file for this player. More...
 
bool _isSdCardFound ()
 Heuristic check for SD card presence using a lightweight play probe. More...
 
bool _isTrackFound (uint16_t track=1)
 Check whether a specific track exists and can be played. More...
 

Private Attributes

SoftwareSerial swSerial_
 UART to DFPlayer.
 
uint8_t playerNum_
 Unique player instance number.
 
uint8_t currentFileNum_
 Last requested file index.
 
uint8_t currentVolume_
 Last requested volume.
 
requestTypes currentRequest_
 Last requested command type.
 
ESPFlash< uint8_t > saveFile_
 Persistent storage for state.
 
DFPlayerMini_Fast DF_Player_
 Underlying DFPlayer handle.
 
bool isConnected
 True if DFPlayer init succeeded.
 

Detailed Description

Controls a DFPlayer Mini via SoftwareSerial, with save/restore functionality.

Definition at line 75 of file SoundCardPlayer.h.

Constructor & Destructor Documentation

◆ SoundCardPlayer()

SoundCardPlayer::SoundCardPlayer ( )
inline

Construct a new SoundCardPlayer instance.

Configures SoftwareSerial pins for this player, initializes DFPlayer, and sets default EQ and source.

Definition at line 82 of file SoundCardPlayer.h.

Here is the call graph for this function:

Member Function Documentation

◆ _isSdCardFound()

bool SoundCardPlayer::_isSdCardFound ( )
inlineprivate

Heuristic check for SD card presence using a lightweight play probe.

DFPlayerMini_Fast does not expose a direct "card present" flag universally, so we attempt a quick play of track 1 and observe whether the device reports "playing". If it starts, we immediately pause and report true.

Returns
true if a card with playable content appears to be present; false otherwise.

Definition at line 267 of file SoundCardPlayer.h.

Here is the caller graph for this function:

◆ _isTrackFound()

bool SoundCardPlayer::_isTrackFound ( uint16_t  track = 1)
inlineprivate

Check whether a specific track exists and can be played.

Parameters
track1-based file number to probe.
Returns
true if the DFPlayer reports "playing" after issuing play(track); false otherwise.

Definition at line 285 of file SoundCardPlayer.h.

Here is the caller graph for this function:

◆ isPlaying()

bool SoundCardPlayer::isPlaying ( )
inline

Check if the DFPlayer is currently playing audio.

Must call swSerial_.listen() before status query.

Returns
true if audio is playing

Definition at line 122 of file SoundCardPlayer.h.

◆ loop()

void SoundCardPlayer::loop ( uint8_t  fileNum,
uint8_t  volume 
)
inline

Loop playback of a file indefinitely at the given volume.

Parameters
fileNumFile index to loop
volumeVolume level (0..30)

Definition at line 152 of file SoundCardPlayer.h.

◆ openSaveFile_()

void SoundCardPlayer::openSaveFile_ ( )
inlineprivate

Open or create the SPIFFS save file for this player.

File name is SAVE_FILE_NAME + binary representation of playerNum_.

Definition at line 251 of file SoundCardPlayer.h.

Here is the caller graph for this function:

◆ play()

void SoundCardPlayer::play ( uint8_t  fileNum,
uint8_t  volume 
)
inline

Play a single file once at the given volume.

Parameters
fileNumFile index to play (1-based)
volumeVolume level (0..30)

Definition at line 133 of file SoundCardPlayer.h.

Here is the caller graph for this function:

◆ testPlayer()

void SoundCardPlayer::testPlayer ( uint8_t  volumePct = 25)
inline

Perform ready checks and play the first track if present.

Parameters
volumePctVolume in percent (0..100). Mapped to DF volume 0..30.

Definition at line 217 of file SoundCardPlayer.h.

Here is the call graph for this function:

The documentation for this class was generated from the following file: