29 #ifndef JQ8400Serial_h
30 #define JQ8400Serial_h
32 #define MP3_EQ_NORMAL 0
36 #define MP3_EQ_CLASSIC 4
39 #define MP3_SRC_SDCARD 1
40 #define MP3_SRC_FLASH 2
41 #define MP3_SRC_BUILTIN MP3_SRC_FLASH
48 #define MP3_LOOP_ALL 0
49 #define MP3_LOOP_ALL_STOP 7
50 #define MP3_LOOP_ALL_RANDOM 3
52 #define MP3_LOOP_ONE 1
53 #define MP3_LOOP_ONE_STOP 2
55 #define MP3_LOOP_FOLDER 4
56 #define MP3_LOOP_FOLDER_RANDOM 5
57 #define MP3_LOOP_FOLDER_STOP 6
59 #define MP3_LOOP_NONE 2
61 #define MP3_STATUS_STOPPED 0
62 #define MP3_STATUS_PLAYING 1
63 #define MP3_STATUS_PAUSED 2
67 #define MP3_STATUS_CHECKS_IN_AGREEMENT 1
71 #define HEX_PRINT(a) if(a < 16) Serial.print(0); Serial.print(a, HEX);
181 void rewind(uint16_t seconds = 5);
346 void abLoopPlay(uint16_t secondsStart, uint16_t secondsEnd);
666 void sendCommandData(uint8_t command, uint8_t *requestBuffer, uint8_t requestLength, uint8_t *responseBuffer, uint8_t bufferLength);
673 inline void sendCommand(uint8_t command, uint8_t *responseBuffer = 0, uint8_t bufferLength = 0)
684 inline void sendCommand(uint8_t command, uint8_t arg, uint8_t *responseBuffer = 0, uint8_t bufferLength = 0)
695 inline void sendCommand(uint8_t command, uint16_t arg, uint8_t *responseBuffer = 0, uint8_t bufferLength = 0)
697 #if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
698 sendCommandData(command, ((uint8_t *)(&arg)), 2, responseBuffer, bufferLength);
700 uint8_t buf[] = { *(((uint8_t *)(&arg))+1), *((uint8_t *)(&arg)) };
749 static const uint8_t MP3_CMD_BEGIN = 0xAA;
752 static const uint8_t MP3_CMD_PLAY = 0x02;
753 static const uint8_t MP3_CMD_PAUSE = 0x03;
755 static const uint8_t MP3_CMD_FFWD = 0x23;
756 static const uint8_t MP3_CMD_RWND = 0x22;
758 static const uint8_t MP3_CMD_STOP = 0x10;
760 static const uint8_t MP3_CMD_NEXT = 0x06;
761 static const uint8_t MP3_CMD_PREV = 0x05;
762 static const uint8_t MP3_CMD_PLAY_IDX = 0x07;
763 static const uint8_t MP3_CMD_SEEK_IDX = 0x1F;
764 static const uint8_t MP3_CMD_INSERT_IDX = 0x16;
766 static const uint8_t MP3_CMD_AB_PLAY = 0x20;
767 static const uint8_t MP3_CMD_AB_PLAY_STOP = 0x21;
769 static const uint8_t MP3_CMD_NEXT_FOLDER = 0x0F;
770 static const uint8_t MP3_CMD_PREV_FOLDER = 0x0E;
772 static const uint8_t MP3_CMD_PLAY_FILE_FOLDER = 0x08;
774 static const uint8_t MP3_CMD_VOL_UP = 0x14;
775 static const uint8_t MP3_CMD_VOL_DN = 0x15;
776 static const uint8_t MP3_CMD_VOL_SET = 0x13;
778 static const uint8_t MP3_CMD_EQ_SET = 0x1A;
779 static const uint8_t MP3_CMD_LOOP_SET = 0x18;
780 static const uint8_t MP3_CMD_SOURCE_SET = 0x0B;
782 static const uint8_t MP3_CMD_SLEEP = 0x04;
783 static const uint8_t MP3_CMD_RESET = 0x04;
785 static const uint8_t MP3_CMD_STATUS = 0x01;
787 static const uint8_t MP3_CMD_GET_SOURCES = 0x09;
788 static const uint8_t MP3_CMD_GET_SOURCE = 0x0A;
790 static const uint8_t MP3_CMD_COUNT_FILES = 0x0C;
791 static const uint8_t MP3_CMD_COUNT_IN_FOLDER = 0x12;
793 static const uint8_t MP3_CMD_CURRENT_FILE_IDX = 0x0D;
794 static const uint8_t MP3_CMD_FIRST_FILE_IN_FOLDER_IDX = 0x11;
796 static const uint8_t MP3_CMD_CURRENT_FILE_LEN = 0x24;
797 static const uint8_t MP3_CMD_CURRENT_FILE_POS = 0x25;
798 static const uint8_t MP3_CMD_CURRENT_FILE_POS_STOP = 0x26;
799 static const uint8_t MP3_CMD_CURRENT_FILE_NAME = 0x1E;
801 static const uint8_t MP3_CMD_PLAYLIST = 0x1B;
int waitUntilAvailable(uint16_t maxWaitTime=1000)
Blocking wait with a timeout for serial input.
Definition: JQ8400_Serial.cpp:533
void abLoopPlay(uint16_t secondsStart, uint16_t secondsEnd)
A-B Loop for the file currently playing.
Definition: JQ8400_Serial.cpp:81
void seekFileByIndexNumber(uint16_t fileNumber)
Seek to a specific file based on it's FAT index number.
Definition: JQ8400_Serial.cpp:75
void setSource(byte source)
Set the source to read mp3 data from.
Definition: JQ8400_Serial.cpp:245
void prevFolder()
Play the previous folder.
Definition: JQ8400_Serial.cpp:109
uint8_t currentLoop
Record of current loop mode (JQ8400 has no way to query)
Definition: JQ8400_Serial.h:744
void setLoopMode(byte loopMode)
Set the looping mode.
Definition: JQ8400_Serial.cpp:233
Definition: JQ8400_Serial.h:73
void pause()
Pause the current file.
Definition: JQ8400_Serial.cpp:43
uint8_t currentEq
Record of current equalizer (JQ8400 has no way to query)
Definition: JQ8400_Serial.h:743
uint16_t countFiles()
Count the number of files on the current media.
Definition: JQ8400_Serial.cpp:336
void sendCommandData(uint8_t command, uint8_t *requestBuffer, uint8_t requestLength, uint8_t *responseBuffer, uint8_t bufferLength)
Send a command to the JQ8400 module,.
Definition: JQ8400_Serial.cpp:393
Stream * _Serial
Set in the constructor, the stream (eg HardwareSerial or SoftwareSerial object) that connects us to t...
Definition: JQ8400_Serial.h:76
void volumeDn()
Decrease the volume by 1 (volume ranges 0 to 30).
Definition: JQ8400_Serial.cpp:215
void fastForward(uint16_t seconds=5)
Fast Forward by a number of seconds (default 5).
Definition: JQ8400_Serial.cpp:92
void sleep()
Put the device to sleep.
Definition: JQ8400_Serial.cpp:256
void stop()
Stop the current playing (if any).
Definition: JQ8400_Serial.cpp:48
byte getLoopMode()
Get loop mode.
Definition: JQ8400_Serial.cpp:333
uint8_t busy()
Return if the device is busy (playing) or not.
Definition: JQ8400_Serial.h:488
uint8_t getSource()
Return the currently selected source.
Definition: JQ8400_Serial.cpp:250
uint16_t sendCommandWithUnsignedIntResponse(byte command)
Send a command to the JQ8400 module, and get a 16 bit integer response.
Definition: JQ8400_Serial.cpp:379
void playFileByIndexNumber(uint16_t fileNumber)
Play a specific file based on it's FAT index number.
Definition: JQ8400_Serial.cpp:63
void setEqualizer(byte equalizerMode)
Set the equalizer to one of 6 preset modes.
Definition: JQ8400_Serial.cpp:227
JQ8400_Serial(Stream &_Stream)
Create JQ8400 object with a given serial object to communicate to the JQ8400.
Definition: JQ8400_Serial.h:145
uint8_t sourceAvailable(uint8_t source)
Return boolean indicating if the given source is available (can be selected using setSource()) ...
Definition: JQ8400_Serial.h:444
uint8_t getAvailableSources()
Return a bitmask of the available sources.
Definition: JQ8400_Serial.cpp:240
byte getEqualizer()
Get the equalizer mode.
Definition: JQ8400_Serial.cpp:332
uint8_t currentVolume
Record of current volume level (JQ8400 has no way to query)
Definition: JQ8400_Serial.h:742
void next()
Play the next file.
Definition: JQ8400_Serial.cpp:53
void sendCommand(uint8_t command, uint8_t arg, uint8_t *responseBuffer=0, uint8_t bufferLength=0)
Send a command with a single 8 bit argument and no response.
Definition: JQ8400_Serial.h:684
void rewind(uint16_t seconds=5)
Rewind by a number of seconds (default 5).
Definition: JQ8400_Serial.cpp:98
void nextFolder()
Play the next folder.
Definition: JQ8400_Serial.cpp:104
byte getVolume()
Get the current volume level.
Definition: JQ8400_Serial.cpp:331
void setVolume(byte volumeFrom0To30)
Set the volume to a specific level (0 to 30).
Definition: JQ8400_Serial.cpp:221
void playSequenceByFileNumber(uint8_t playList[], uint8_t listLength)
Play a sequence of files, which must all exist in a folder called "ZH" and be named 00...
Definition: JQ8400_Serial.cpp:178
void interjectFileByIndexNumber(uint16_t fileNumber)
Interject the currently playing file (if any) with the given FAT index number file.
Definition: JQ8400_Serial.cpp:69
uint8_t sendCommandWithByteResponse(uint8_t command)
Send a command to the JQ8400 module, and get an 8 bit integer response.
Definition: JQ8400_Serial.cpp:386
void reset()
Reset the device (softly).
Definition: JQ8400_Serial.cpp:270
uint16_t currentFileLengthInSeconds()
For the currently playing or paused file, return the total length of the file in seconds.
Definition: JQ8400_Serial.cpp:359
uint16_t currentFilePositionInSeconds()
For the currently playing or paused file, return the current position in seconds. ...
Definition: JQ8400_Serial.cpp:346
void play()
Start playing the current file, if paused the playing is resumed.
Definition: JQ8400_Serial.cpp:32
void playSequenceByFileName(const char *playList[], uint8_t listLength)
Play a sequence of files, which must all exist in a folder called "ZH" and have 2 character names...
Definition: JQ8400_Serial.cpp:195
void restart()
Restart the current track from the beginning.
Definition: JQ8400_Serial.cpp:37
void abLoopClear()
Use this to break a currently running A-B loop.
Definition: JQ8400_Serial.cpp:87
void sendCommand(uint8_t command, uint8_t *responseBuffer=0, uint8_t bufferLength=0)
Send a command with no arguments and no response.
Definition: JQ8400_Serial.h:673
byte getStatus()
Get the status from the device.
Definition: JQ8400_Serial.cpp:307
void currentFileName(char *buffer, uint16_t bufferLength)
Get the name of the "current" file.
Definition: JQ8400_Serial.cpp:370
void playFileNumberInFolderNumber(uint16_t folderNumber, uint16_t fileNumber)
Play a specific file in a specific folder based on the name of those folder and file.
Definition: JQ8400_Serial.cpp:114
void sendCommand(uint8_t command, uint16_t arg, uint8_t *responseBuffer=0, uint8_t bufferLength=0)
Send a command with a 16 bit integer argument.
Definition: JQ8400_Serial.h:695
void volumeUp()
Increase the volume by 1 (volume ranges 0 to 30).
Definition: JQ8400_Serial.cpp:209
void playInFolderNumber(uint16_t folderNumber)
Play the first (?) file in a specific folder 00 to 99.
Definition: JQ8400_Serial.cpp:158
uint16_t currentFileIndexNumber()
For the currently playing (or paused, or file that would be played next if stopped) file...
Definition: JQ8400_Serial.cpp:341
void prev()
Play the previous file.
Definition: JQ8400_Serial.cpp:58