Mutila: Mouse's Utilities for Arduino
Oft-used utilities: debouncing buttons, averaging samples, and so on.
Public Types | Public Member Functions | Static Public Attributes | List of all members
DFPReader Class Reference

#include <DFPReader.h>

Inheritance diagram for DFPReader:
Inheritance graph

Public Types

enum  PlaybackState { Idle, Pending, Playing }
 
- Public Types inherited from DFPlayerMini
enum  Cmd {
  Undefined = 0x00, Next = 0x01, Prev = 0x02, PlayPhysical = 0x03,
  SetVolume = 0x06, SetEqalizer = 0x07, SetDevice = 0x09, Sleep = 0x0A,
  Reset = 0x0C, Play = 0x0D, Pause = 0x0E, PlayTf = 0x12,
  Stop = 0x16, SingleLoop = 0x19, GetStatus = 0x42, GetVolume = 0x43,
  GetUSum = 0x47, GetTfSum = 0x48, GetFlashSum = 0x49, GetUCurrent = 0x4B,
  GetTfCurrent = 0x4C, GetFlashCurrent = 0x4D
}
 

Public Member Functions

 DFPReader (Stream &serial, DFPlayerMini::Cmd playCmd=DFPlayerMini::PlayTf, uint8_t busyPin=0, uint8_t readerBufferSize=30)
 
 ~DFPReader ()
 
void begin (bool bootWait=true)
 
void update ()
 
void readNumber (double number, uint8_t dp=0)
 
bool reading ()
 
void resetReaderBuf ()
 
bool appendElement (uint8_t value)
 
- Public Member Functions inherited from DFPlayerMini
 DFPlayerMini (Stream &serial, const uint8_t busyPin=0)
 
void begin (bool bootWait=true)
 
void sendCmd (Cmd cmd, uint16_t arg=0)
 
DFPResponse query (Cmd cmd, uint8_t tries=3)
 
bool busy ()
 
bool check ()
 

Static Public Attributes

static const uint8_t PlaybackStartMs = 120
 
static const uint8_t Mp3TrackZero = 200
 
static const uint8_t Mp3TrackTen = 210
 
static const uint8_t Mp3TrackTwenty = 220
 
static const uint8_t Mp3TrackThirty = 221
 
static const uint8_t Mp3TrackFourty = 222
 
static const uint8_t Mp3TrackFifty = 223
 
static const uint8_t Mp3TrackSixty = 224
 
static const uint8_t Mp3TrackSeventy = 225
 
static const uint8_t Mp3TrackEighty = 226
 
static const uint8_t Mp3TrackNinety = 227
 
static const uint8_t Mp3TrackHundred = 228
 
static const uint8_t Mp3TrackThousand = 229
 
static const uint8_t Mp3TrackMillion = 230
 
static const uint8_t Mp3TrackBillion = 231
 
static const uint8_t Mp3TrackTrillion = 232
 
static const uint8_t Mp3TrackPoint = 233
 
static const uint8_t Mp3TrackMinus = 234
 
static const uint8_t Mp3TrackYear = 235
 
static const uint8_t Mp3TrackYears = 236
 
static const uint8_t Mp3TrackMonth = 237
 
static const uint8_t Mp3TrackMonths = 238
 
static const uint8_t Mp3TrackWeek = 239
 
static const uint8_t Mp3TrackWeeks = 240
 
static const uint8_t Mp3TrackDay = 241
 
static const uint8_t Mp3TrackDays = 242
 
static const uint8_t Mp3TrackHour = 243
 
static const uint8_t Mp3TrackHours = 244
 
static const uint8_t Mp3TrackMinute = 245
 
static const uint8_t Mp3TrackMinutes = 246
 
static const uint8_t Mp3TrackSecond = 247
 
static const uint8_t Mp3TrackSeconds = 248
 
static const uint8_t Mp3TrackMillisecond = 249
 
static const uint8_t Mp3TrackMilliseconds = 250
 
static const uint8_t Mp3TrackAnd = 251
 
- Static Public Attributes inherited from DFPlayerMini
static const uint8_t BufferLength = 10
 
static const uint8_t MinimumTimeMs = 20
 
static const uint8_t ResponseTimeoutMs = 20
 
static const uint8_t PacketOffsetCmd = 3
 
static const uint8_t PacketOffsetArg = 5
 
static const uint8_t PacketOffsetCkSum = 7
 

Detailed Description

DFPlayerMini controller with numeric readout functions.

This class is intended for use with the samples in the audio/ directory of the main Mutila repository. Copy these files to an SD card in a directory called "mp3".

Definition at line 12 of file DFPReader.h.

Member Enumeration Documentation

◆ PlaybackState

Enumerator
Idle 

Reader is idle.

Pending 

Reader is not playing, but is waiting for an audio file to play.

Playing 

Reader is playing an audio file.

Definition at line 55 of file DFPReader.h.

Constructor & Destructor Documentation

◆ DFPReader()

DFPReader::DFPReader ( Stream &  serial,
DFPlayerMini::Cmd  playCmd = DFPlayerMini::PlayTf,
uint8_t  busyPin = 0,
uint8_t  readerBufferSize = 30 
)

Constructor.

Parameters
seriala software serial object set at 9600 baud connected to the DFPlayerMini device.
busyPinthe pin on the arduino connected to the BUSY pin of the DFPlayerMini. See the busy() documentation for more details.

Definition at line 27 of file DFPReader.cpp.

◆ ~DFPReader()

DFPReader::~DFPReader ( )

Destructor.

Definition at line 35 of file DFPReader.cpp.

Member Function Documentation

◆ appendElement()

bool DFPReader::appendElement ( uint8_t  value)

Append a sample to play.

Add a sample to the end of the run buffer to play as soon as other elements in the buffer have been played.

Definition at line 151 of file DFPReader.cpp.

Here is the caller graph for this function:

◆ begin()

void DFPReader::begin ( bool  bootWait = true)

Initialize.

Typically called from setup().

Parameters
bootWaitif true, wait 600ms for the DFPlayer to boot.

Definition at line 40 of file DFPReader.cpp.

Here is the call graph for this function:

◆ reading()

bool DFPReader::reading ( )

Find out if still reading.

Returns
true if a sound is being played, or if there are still samples to play after the current sample (i.e. if we're still reading out a number), else return false

Definition at line 119 of file DFPReader.cpp.

Here is the call graph for this function:

◆ readNumber()

void DFPReader::readNumber ( double  number,
uint8_t  dp = 0 
)

Queue up digits of a number to read.

When called, the ring buffer is populated with the IDs of samples which are required to read the number. For example if number=3.14159, and dp=2, the samples for "three", "point" "one", and "four" would be appened to the ring buffer.

During update(), samples are played in order such that they do not overlap.

Definition at line 78 of file DFPReader.cpp.

Here is the call graph for this function:

◆ resetReaderBuf()

void DFPReader::resetReaderBuf ( )

Stop playback and reset the run buffer to an empty state.

Definition at line 130 of file DFPReader.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ update()

void DFPReader::update ( )

Allocate Timeslice.

Should be called frequently - typically from loop().

Definition at line 48 of file DFPReader.cpp.

Here is the call graph for this function:

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