upm  0.4.1
Sensor/Actuator repository for libmraa (v0.8.0)
Classes | Public Member Functions | List of all members

API for the WT5001 Serial MP3 Module. More...

Detailed Description

UPM support for the WT5001 Serial MP3 module. This was tested specifically with the Grove Serial MP3 module.

wt5001.jpg
// Instantiate a WT5001 serial MP3 player on uart 0
int cmd = -1;
if (args.length > 0)
cmd = Integer.parseInt(args[0]);
// make sure port is initialized properly. 9600 baud is the default
if (!mp3.setupTty()) {
System.err.println("error in loading native library");
System.exit(-1);
}
switch (cmd) {
case 0 :
mp3.stop();
break;
case 1 :
break;
case 2 :
mp3.pause();
break;
case 3 :
mp3.next();
break;
case 4 :
mp3.previous();
break;
default :
// nothing, just output usage, and info below
printUsage();
break;
}
// print out some information
try {
short vol;
vol = mp3.getVolume();
System.out.println("The current volume is: " + vol);
} catch (IOException e) {
e.printStackTrace();
}
try {
short ps;
ps = mp3.getPlayState();
System.out.println("The current play state is: " + ps);
} catch (IOException e) {
e.printStackTrace();
}
try {
int numf;
numf = mp3.getNumFiles(upm_wt5001.WT5001.WT5001_PLAYSOURCE_T.SD);
System.out.println("The number of files on the SD card is: " + numf);
} catch (IOException e) {
e.printStackTrace();
}
try {
int curf;
curf = mp3.getCurrentFile();
System.out.println("The current file is: " + curf);
} catch (IOException e) {
e.printStackTrace();
}
int year[] = new int[1];
short month[] = new short[1];
short day[] = new short[1];
if (mp3.getDate(year, month, day))
System.out.println("The device date is: " + year[0] + "/" + month[0] + "/" + day[0]);
short hour[] = new short[1];
short minute[] = new short[1];
short second[] = new short[1];
if (mp3.getTime(hour, minute, second))
System.out
.println("The device time is: " + hour[0] + ":" + minute[0] + ":" + second[0]);

Classes

class  WT5001_OPCODE_T
 
class  WT5001_PLAYMODE_T
 
class  WT5001_PLAYSOURCE_T
 

Public Member Functions

synchronized void delete ()
 
 WT5001 (int uart)
 
boolean dataAvailable (long millis)
 
int readData (byte[] buffer)
 
int writeData (byte[] buffer)
 
boolean setupTty (int baud)
 
boolean setupTty ()
 
boolean checkResponse (WT5001.WT5001_OPCODE_T opcode)
 
boolean play (WT5001.WT5001_PLAYSOURCE_T psrc, int index)
 
boolean stop ()
 
boolean pause ()
 
boolean next ()
 
boolean previous ()
 
boolean setVolume (short vol)
 
boolean queue (int index)
 
boolean setPlayMode (WT5001.WT5001_PLAYMODE_T pm)
 
boolean insert (int index)
 
boolean setDate (int year, short month, short day)
 
boolean setTime (short hour, short minute, short second)
 
boolean setAlarm (short hour, short minute, short second)
 
boolean clearAlarm ()
 
short getVolume () throws java.io.IOException
 
short getPlayState () throws java.io.IOException
 
int getNumFiles (WT5001.WT5001_PLAYSOURCE_T psrc) throws java.io.IOException
 
int getCurrentFile () throws java.io.IOException
 
boolean getDate (int[] year, short[] month, short[] day)
 
boolean getTime (short[] hour, short[] minute, short[] second)
 

Constructor & Destructor Documentation

WT5001 ( int  uart)

WT5001 constructor

Parameters
uartDefault UART to use (0 or 1)

Member Function Documentation

boolean checkResponse ( WT5001.WT5001_OPCODE_T  opcode)

Gets a command response and returns its validity

Parameters
indexOpcode to verify
Returns
True if successful
boolean clearAlarm ( )

Clears any alarm that has been set

Returns
True if successful
boolean dataAvailable ( long  millis)

Checks to see if there is data available for reading

Parameters
millisNumber of milliseconds to wait; 0 means no waiting
Returns
True if there is data available for reading
int getCurrentFile ( ) throws java.io.IOException

Gets the index of the current file

Returns
Index of the curretn file
Exceptions
std::runtime_errorif reading from the sensor failed
boolean getDate ( int[]  year,
short[]  month,
short[]  day 
)

Gets the device date

Parameters
year4-digit year
monthMonth
dayDay
Returns
True if successful
int getNumFiles ( WT5001.WT5001_PLAYSOURCE_T  psrc) throws java.io.IOException

Gets the number of files present on the source device

Parameters
psrcStorage source
Returns
Number of files
Exceptions
std::runtime_errorif reading from the sensor failed
short getPlayState ( ) throws java.io.IOException

Gets the current play state: 1 = playing, 2 = stopped, 3 = paused

Returns
Play state
Exceptions
std::runtime_errorif reading from the sensor failed
boolean getTime ( short[]  hour,
short[]  minute,
short[]  second 
)

Gets the device time

Parameters
hourHour
minuteMinute
secondSecond
Returns
True if successful
short getVolume ( ) throws java.io.IOException

Gets the current volume

Returns
Volume
Exceptions
std::runtime_errorif reading from the sensor failed
boolean insert ( int  index)

Inserts a track to play immediately, interrupting the current track. When the inserted track is finished, the interrupted track resumes where it was interrupted.

Parameters
indexFile number to insert
Returns
True if successful
boolean next ( )

Moves to the next track

Returns
True if successful
boolean pause ( )

Pauses the playback or resumes it if already paused

Returns
True if successful
boolean play ( WT5001.WT5001_PLAYSOURCE_T  psrc,
int  index 
)

Plays a file from a source

Parameters
psrcPlay source (SD, UDISK, SPI)
indexFile number to play
Returns
True if successful
boolean previous ( )

Moves to the previous track

Returns
True if successful
boolean queue ( int  index)

Queues a track to play next, when the current song is finished

Parameters
indexFile number to queue
Returns
True if successful
boolean setAlarm ( short  hour,
short  minute,
short  second 
)

Sets the alarm

Parameters
hourHour
minuteMinute
secondSecond
Returns
True if successful
boolean setDate ( int  year,
short  month,
short  day 
)

Sets the date of the internal clock

Parameters
year4-digit year
monthMonth
dayDay
Returns
True if successful
boolean setPlayMode ( WT5001.WT5001_PLAYMODE_T  pm)

Sets the playback mode

Parameters
pmPlay mode to enable
Returns
True if successful
boolean setTime ( short  hour,
short  minute,
short  second 
)

Sets the time of the internal clock

Parameters
hourHour
minuteMinute
secondSecond
Returns
True if successful
boolean setupTty ( int  baud)

Sets up proper tty I/O modes and the baud rate. The default baud rate is 9,600 (B9600).

Parameters
baudDesired baud rate.
Returns
True if successful
boolean setVolume ( short  vol)

Sets the volume. Valid range is 0-31. 0 means mute.

Returns
True if successful
boolean stop ( )

Stops playing

Returns
True if successful

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