mirror of
https://github.com/eclipse/upm.git
synced 2025-07-01 17:31:13 +03:00
wt5001: Initial implementation
The module implements support for the WT5001 serial mp3 player. It was tested on the Grove Serial MP3 Player. Signed-off-by: Jon Trulson <jtrulson@ics.com> Signed-off-by: Zion Orent <zorent@ics.com> Signed-off-by: John Van Drasek <john.r.van.drasek@intel.com>
This commit is contained in:

committed by
John Van Drasek

parent
40e0595892
commit
df390358f2
@ -68,6 +68,7 @@ add_executable (groveloudness-example groveloudness.cxx)
|
||||
add_executable (mpr121-example mpr121.cxx)
|
||||
add_executable (ublox6-example ublox6.cxx)
|
||||
add_executable (yg1006-example yg1006.cxx)
|
||||
add_executable (wt5001-example wt5001.cxx)
|
||||
|
||||
include_directories (${PROJECT_SOURCE_DIR}/src/hmc5883l)
|
||||
include_directories (${PROJECT_SOURCE_DIR}/src/grove)
|
||||
@ -123,6 +124,7 @@ include_directories (${PROJECT_SOURCE_DIR}/src/groveloudness)
|
||||
include_directories (${PROJECT_SOURCE_DIR}/src/mpr121)
|
||||
include_directories (${PROJECT_SOURCE_DIR}/src/ublox6)
|
||||
include_directories (${PROJECT_SOURCE_DIR}/src/yg1006)
|
||||
include_directories (${PROJECT_SOURCE_DIR}/src/wt5001)
|
||||
|
||||
target_link_libraries (hmc5883l-example hmc5883l ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries (groveled-example grove ${CMAKE_THREAD_LIBS_INIT})
|
||||
@ -194,3 +196,4 @@ target_link_libraries (groveloudness-example groveloudness ${CMAKE_THREAD_LIBS_I
|
||||
target_link_libraries (mpr121-example mpr121 ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries (ublox6-example ublox6 ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries (yg1006-example yg1006 ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries (wt5001-example wt5001 ${CMAKE_THREAD_LIBS_INIT})
|
||||
|
137
examples/javascript/w5001.js
Normal file
137
examples/javascript/w5001.js
Normal file
@ -0,0 +1,137 @@
|
||||
/*jslint node:true, vars:true, bitwise:true, unparam:true */
|
||||
/*jshint unused:true */
|
||||
/*global */
|
||||
/*
|
||||
* Author: Zion Orent <zorent@ics.com>
|
||||
* Copyright (c) 2014 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
var MP3Player = require('jsupm_wt5001');
|
||||
|
||||
function printUsage(progname)
|
||||
{
|
||||
console.log("Usage:" + progname + " <command>");
|
||||
console.log("Commands:");
|
||||
console.log("0 - stop playing");
|
||||
console.log("1 - start playing track 1");
|
||||
console.log("2 - pause/un-pause playback");
|
||||
console.log("3 - next track");
|
||||
console.log("4 - previous track");
|
||||
}
|
||||
|
||||
// Instantiate a WT5001 serial MP3 player on uart 0 (/dev/ttyS0). This
|
||||
// works for the galileo G2.
|
||||
|
||||
// The Edison uses a different serial port, /dev/ttyMFD1, so if you
|
||||
// are using this example on an Edison board, set the environment
|
||||
// variable WT5001_SERIAL_PORT to specify the proper port before
|
||||
// running this example,
|
||||
// eg: 'WT5001_SERIAL_PORT=/dev/ttyMFD1 node w5001.js'
|
||||
|
||||
// This example was tested on the Grove Serial MP3 module.
|
||||
|
||||
var defaultPort = "/dev/ttyS0";
|
||||
var port = process.env.WT5001_SERIAL_PORT;
|
||||
if (port)
|
||||
defaultPort = port;
|
||||
|
||||
var myMP3Player = new MP3Player.WT5001(0, defaultPort);
|
||||
|
||||
var cmd = -1;
|
||||
if (process.argv.length > 2)
|
||||
cmd = parseInt(process.argv[2]);
|
||||
|
||||
if (!myMP3Player.setupTty(MP3Player.int_B9600))
|
||||
{
|
||||
console.log("Failed to setup tty port parameters");
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
switch (cmd)
|
||||
{
|
||||
case 0:
|
||||
myMP3Player.stop();
|
||||
break;
|
||||
|
||||
case 1:
|
||||
myMP3Player.play(MP3Player.WT5001.SD, 1);
|
||||
break;
|
||||
|
||||
case 2:
|
||||
myMP3Player.pause();
|
||||
break;
|
||||
|
||||
case 3:
|
||||
myMP3Player.next();
|
||||
break;
|
||||
|
||||
case 4:
|
||||
myMP3Player.previous();
|
||||
break;
|
||||
|
||||
default:
|
||||
// nothing, just output usage, and info below
|
||||
printUsage(process.argv[1]);
|
||||
break;
|
||||
}
|
||||
|
||||
// print out some information
|
||||
var vol = new MP3Player.uint8Array(0);
|
||||
myMP3Player.getVolume(vol);
|
||||
console.log("The current volume is: " + vol.getitem(0));
|
||||
|
||||
var ps = new MP3Player.uint8Array(0);
|
||||
myMP3Player.getPlayState(ps);
|
||||
console.log("The current play state is: " + ps.getitem(0));
|
||||
|
||||
var numf = new MP3Player.uint16Array(0);
|
||||
myMP3Player.getNumFiles(MP3Player.WT5001.SD, numf);
|
||||
console.log("The number of files on the SD card is: " + numf.getitem(0));
|
||||
|
||||
var curf = new MP3Player.uint16Array(0);
|
||||
myMP3Player.getCurrentFile(curf);
|
||||
console.log("The current file is: " + curf.getitem(0));
|
||||
|
||||
var year = new MP3Player.uint16Array(0);
|
||||
var month = new MP3Player.uint8Array(0);
|
||||
var day = new MP3Player.uint8Array(0);
|
||||
myMP3Player.getDate(year, month, day);
|
||||
var mp3date = month.getitem(0) + "/";
|
||||
mp3date += (day.getitem(0) + "/");
|
||||
mp3date += year.getitem(0);
|
||||
console.log("The device date is: " + mp3date);
|
||||
|
||||
var hour = new MP3Player.uint8Array(0);
|
||||
var minute = new MP3Player.uint8Array(0);
|
||||
var second = new MP3Player.uint8Array(0);
|
||||
myMP3Player.getTime(hour, minute, second);
|
||||
var mp3time = hour.getitem(0) + ":";
|
||||
mp3time += (minute.getitem(0) + ":");
|
||||
mp3time += second.getitem(0);
|
||||
console.log("The device time is: " + mp3time);
|
||||
|
||||
// Print message when exiting
|
||||
process.on('SIGINT', function()
|
||||
{
|
||||
console.log("Exiting...");
|
||||
process.exit(0);
|
||||
});
|
144
examples/wt5001.cxx
Normal file
144
examples/wt5001.cxx
Normal file
@ -0,0 +1,144 @@
|
||||
/*
|
||||
* Author: Jon Trulson <jtrulson@ics.com>
|
||||
* Copyright (c) 2014 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
#include <iostream>
|
||||
#include <signal.h>
|
||||
#include "wt5001.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
void printUsage(char *progname)
|
||||
{
|
||||
cout << "Usage:" << progname << " <command>" << endl;
|
||||
cout << "Commands:" << endl;
|
||||
cout << "0 - stop playing" << endl;
|
||||
cout << "1 - start playing track 1" << endl;
|
||||
cout << "2 - pause/un-pause playback" << endl;
|
||||
cout << "3 - next track" << endl;
|
||||
cout << "4 - previous track" << endl;
|
||||
}
|
||||
|
||||
int main (int argc, char **argv)
|
||||
{
|
||||
//! [Interesting]
|
||||
// Instantiate a WT5001 serial MP3 player on uart 0 (/dev/ttyS0). This
|
||||
// works for the galileo G2.
|
||||
|
||||
// The Edison uses a different serial port, /dev/ttyMFD1, so if you
|
||||
// are using this example on an Edison board, set the environment
|
||||
// variable WT5001_SERIAL_PORT to specify the proper port before
|
||||
// running this example,
|
||||
// eg: 'WT5001_SERIAL_PORT=/dev/ttyMFD1 ./wt5001-example'
|
||||
|
||||
// This example was tested on the Grove Serial MP3 module.
|
||||
|
||||
const char *defaultPort = "/dev/ttyS0";
|
||||
char *port = getenv("WT5001_SERIAL_PORT");
|
||||
|
||||
if (port)
|
||||
defaultPort = port;
|
||||
|
||||
upm::WT5001* mp3 = new upm::WT5001(0, defaultPort);
|
||||
|
||||
int cmd = -1;
|
||||
if (argc > 1)
|
||||
cmd = atoi(argv[1]);
|
||||
|
||||
// make sure port is initialized properly. 9600 baud is the default.
|
||||
if (!mp3->setupTty(B9600))
|
||||
{
|
||||
cerr << "Failed to setup tty port parameters" << endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
switch (cmd)
|
||||
{
|
||||
case 0:
|
||||
mp3->stop();
|
||||
break;
|
||||
|
||||
case 1:
|
||||
mp3->play(upm::WT5001::SD, 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(argv[0]);
|
||||
break;
|
||||
}
|
||||
|
||||
// Example: set the date
|
||||
// mp3->setDate(2015, 1, 1);
|
||||
|
||||
// Example: set the time
|
||||
// mp3->setTime(12, 30, 30);
|
||||
|
||||
// print out some information
|
||||
uint8_t vol = 0;
|
||||
if (mp3->getVolume(&vol))
|
||||
cout << "The current volume is: " << int(vol) << endl;
|
||||
|
||||
uint8_t ps = 0;
|
||||
if (mp3->getPlayState(&ps))
|
||||
cout << "The current play state is: " << int(ps) << endl;
|
||||
|
||||
uint16_t numf = 0;
|
||||
if (mp3->getNumFiles(upm::WT5001::SD, &numf))
|
||||
cout << "The number of files on the SD card is: " << int(numf) << endl;
|
||||
|
||||
uint16_t curf = 0;
|
||||
if (mp3->getCurrentFile(&curf))
|
||||
cout << "The current file is: " << int(curf) << endl;
|
||||
|
||||
uint16_t year = 0;
|
||||
uint8_t month = 0, day = 0;
|
||||
if (mp3->getDate(&year, &month, &day))
|
||||
cout << "The device date is: " << int(month) << "/" << int(day)
|
||||
<< "/" << int(year) << endl;
|
||||
|
||||
uint8_t hour = 0, minute = 0, second = 0;
|
||||
if (mp3->getTime(&hour, &minute, &second))
|
||||
cout << "The device time is: " << int(hour) << ":" << int(minute)
|
||||
<< ":" << int(second) << endl;
|
||||
|
||||
//! [Interesting]
|
||||
|
||||
cout << "Exiting..." << endl;
|
||||
|
||||
delete mp3;
|
||||
return 0;
|
||||
}
|
Reference in New Issue
Block a user