/bigdrive/home/boffin/sketchbook/libraries/JQ6500_Serial/JQ6500_Serial.h
Go to the documentation of this file.
// Please note, the Arduino IDE is a bit retarded, if the below define has an
// underscore other than _h, it goes mental. Wish it wouldn't mess
// wif ma files!
#ifndef JQ6500Serial_h
#define JQ6500Serial_h
#include <SoftwareSerial.h>
#define MP3_EQ_NORMAL 0
#define MP3_EQ_POP 1
#define MP3_EQ_ROCK 2
#define MP3_EQ_JAZZ 3
#define MP3_EQ_CLASSIC 4
#define MP3_EQ_BASS 5
#define MP3_SRC_SDCARD 1
#define MP3_SRC_BUILTIN 4
// Looping options, ALL, FOLDER, ONE and ONE_STOP are the
// only ones that appear to do much interesting
// ALL plays all the tracks in a repeating loop
// FOLDER plays all the tracks in the same folder in a repeating loop
// ONE plays the same track repeating
// ONE_STOP does not loop, plays the track and stops
// RAM seems to play one track and someties disables the ability to
// move to next/previous track, really weird.
#define MP3_LOOP_ALL 0
#define MP3_LOOP_FOLDER 1
#define MP3_LOOP_ONE 2
#define MP3_LOOP_RAM 3
#define MP3_LOOP_ONE_STOP 4
#define MP3_LOOP_NONE 4
#define MP3_STATUS_STOPPED 0
#define MP3_STATUS_PLAYING 1
#define MP3_STATUS_PAUSED 2
// The response from a status query we get is for some reason
// a bit... iffy, most of the time it is reliable, but sometimes
// instead of a playing (1) response, we get a paused (2) response
// even though it is playing. Stopped responses seem reliable.
// So to work around this when getStatus() is called we actually
// request the status this many times and only if one of them is STOPPED
// or they are all in agreement that it is playing or paused then
// we return that status. If some of them differ, we do another set
// of tests etc...
#define MP3_STATUS_CHECKS_IN_AGREEMENT 4
#define MP3_DEBUG 0
class JQ6500_Serial : public SoftwareSerial
{
public:
JQ6500_Serial(short rxPin, short txPin) : SoftwareSerial(rxPin,txPin) { };
void play();
void restart();
void pause();
void next();
void prev();
void nextFolder();
void prevFolder();
void playFileByIndexNumber(unsigned int fileNumber);
void playFileNumberInFolderNumber(unsigned int folderNumber, unsigned int fileNumber);
void volumeUp();
void volumeDn();
void setVolume(byte volumeFrom0To30);
void setEqualizer(byte equalizerMode); // EQ_NORMAL to EQ_BASS
void setLoopMode(byte loopMode);
void setSource(byte source); // SRC_BUILTIN or SRC_SDCARD
void sleep();
void reset();
// Status querying commands
byte getStatus();
byte getVolume();
byte getEqualizer();
byte getLoopMode();
unsigned int countFiles(byte source);
unsigned int countFolders(byte source);
unsigned int currentFileIndexNumber(byte source);
unsigned int currentFilePositionInSeconds();
unsigned int currentFileLengthInSeconds();
void currentFileName(char *buffer, unsigned int bufferLength);
protected:
void sendCommand(byte command, byte arg1, byte arg2, char *responseBuffer, unsigned int bufferLength);
// Just some different versions of that for ease of use
void sendCommand(byte command);
void sendCommand(byte command, byte arg1);
void sendCommand(byte command, byte arg1, byte arg2);
unsigned int sendCommandWithUnsignedIntResponse(byte command);
// This seems not that useful since there only seems to be a version 1 anway :/
unsigned int getVersion();
size_t readBytesUntilAndIncluding(char terminator, char *buffer, size_t length, byte maxOneLineOnly = 0);
int waitUntilAvailable(unsigned long maxWaitTime = 1000);
};
#endif
JQ6500_Serial::nextFolder
void nextFolder()
Play the next folder.
Definition: JQ6500_Serial.cpp:69
JQ6500_Serial::sendCommandWithUnsignedIntResponse
unsigned int sendCommandWithUnsignedIntResponse(byte command)
Send a command to the JQ6500 module, and get a response.
Definition: JQ6500_Serial.cpp:198
JQ6500_Serial::JQ6500_Serial
JQ6500_Serial(short rxPin, short txPin)
Create JQ6500 object.
Definition: JQ6500_Serial.h:112
JQ6500_Serial::playFileNumberInFolderNumber
void playFileNumberInFolderNumber(unsigned int folderNumber, unsigned int fileNumber)
Play a specific file in a specific folder based on the name of those folder and file.
Definition: JQ6500_Serial.cpp:79
JQ6500_Serial::sendCommand
void sendCommand(byte command, byte arg1, byte arg2, char *responseBuffer, unsigned int bufferLength)
Send a command to the JQ6500 module,.
Definition: JQ6500_Serial.cpp:220
JQ6500_Serial::setVolume
void setVolume(byte volumeFrom0To30)
Set the volume to a specific level (0 to 30).
Definition: JQ6500_Serial.cpp:94
JQ6500_Serial::pause
void pause()
Pause the current file.
Definition: JQ6500_Serial.cpp:49
JQ6500_Serial::reset
void reset()
Reset the device (softly).
Definition: JQ6500_Serial.cpp:119
JQ6500_Serial::volumeDn
void volumeDn()
Decrease the volume by 1 (volume ranges 0 to 30).
Definition: JQ6500_Serial.cpp:89
JQ6500_Serial::currentFileLengthInSeconds
unsigned int currentFileLengthInSeconds()
For the currently playing or paused file, return the total length of the file in seconds.
Definition: JQ6500_Serial.cpp:189
JQ6500_Serial::countFolders
unsigned int countFolders(byte source)
Count the number of folders on the specified media.
Definition: JQ6500_Serial.cpp:164
JQ6500_Serial::play
void play()
Start playing the current file.
Definition: JQ6500_Serial.cpp:34
JQ6500_Serial::getLoopMode
byte getLoopMode()
Get loop mode.
Definition: JQ6500_Serial.cpp:147
JQ6500_Serial::setEqualizer
void setEqualizer(byte equalizerMode)
Set the equalizer to one of 6 preset modes.
Definition: JQ6500_Serial.cpp:99
JQ6500_Serial::restart
void restart()
Restart the current (possibly paused) track from the beginning.
Definition: JQ6500_Serial.cpp:39
JQ6500_Serial::getEqualizer
byte getEqualizer()
Get the equalizer mode.
Definition: JQ6500_Serial.cpp:146
JQ6500_Serial::next
void next()
Play the next file.
Definition: JQ6500_Serial.cpp:54
JQ6500_Serial::currentFileName
void currentFileName(char *buffer, unsigned int bufferLength)
Get the name of the "current" file on the SD Card.
Definition: JQ6500_Serial.cpp:191
JQ6500_Serial::getVolume
byte getVolume()
Get the current volume level.
Definition: JQ6500_Serial.cpp:145
JQ6500_Serial::volumeUp
void volumeUp()
Increase the volume by 1 (volume ranges 0 to 30).
Definition: JQ6500_Serial.cpp:84
JQ6500_Serial::currentFileIndexNumber
unsigned int currentFileIndexNumber(byte source)
For the currently playing (or paused, or file that would be played next if stopped) file...
Definition: JQ6500_Serial.cpp:174
JQ6500_Serial::currentFilePositionInSeconds
unsigned int currentFilePositionInSeconds()
For the currently playing or paused file, return the current position in seconds. ...
Definition: JQ6500_Serial.cpp:188
JQ6500_Serial::countFiles
unsigned int countFiles(byte source)
Count the number of files on the specified media.
Definition: JQ6500_Serial.cpp:150
JQ6500_Serial
Definition: JQ6500_Serial.h:80
JQ6500_Serial::setLoopMode
void setLoopMode(byte loopMode)
Set the looping mode.
Definition: JQ6500_Serial.cpp:104
JQ6500_Serial::prev
void prev()
Play the previous file.
Definition: JQ6500_Serial.cpp:59
JQ6500_Serial::getStatus
byte getStatus()
Get the status from the device.
Definition: JQ6500_Serial.cpp:126
JQ6500_Serial::prevFolder
void prevFolder()
Play the previous folder.
Definition: JQ6500_Serial.cpp:74
JQ6500_Serial::setSource
void setSource(byte source)
Set the source to read mp3 data from.
Definition: JQ6500_Serial.cpp:109
JQ6500_Serial::playFileByIndexNumber
void playFileByIndexNumber(unsigned int fileNumber)
Play a specific file based on it's (FAT table) index number.
Definition: JQ6500_Serial.cpp:64
JQ6500_Serial::sleep
void sleep()
Put the device to sleep.
Definition: JQ6500_Serial.cpp:114