diff --git a/examples/wt5001.cxx b/examples/wt5001.cxx index 1b40553b..317e877f 100644 --- a/examples/wt5001.cxx +++ b/examples/wt5001.cxx @@ -43,24 +43,10 @@ void printUsage(char *progname) 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' - + // Instantiate a WT5001 serial MP3 player on uart 0. // 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); + upm::WT5001* mp3 = new upm::WT5001(0); int cmd = -1; if (argc > 1) diff --git a/src/wt5001/wt5001.cxx b/src/wt5001/wt5001.cxx index d595b721..14eb7a32 100644 --- a/src/wt5001/wt5001.cxx +++ b/src/wt5001/wt5001.cxx @@ -31,10 +31,9 @@ using namespace std; static const int defaultDelay = 100; // max wait time for read -WT5001::WT5001(int uart, const char *tty) : - m_ttyFd(-1) +WT5001::WT5001(int uart) { - mraa_init(); + m_ttyFd = -1; if ( !(m_uart = mraa_uart_init(uart)) ) { @@ -42,10 +41,19 @@ WT5001::WT5001(int uart, const char *tty) : return; } - // now open the tty - if ( (m_ttyFd = open(tty, O_RDWR)) == -1) + // This requires a recent MRAA (1/2015) + char *devPath = mraa_uart_get_dev_path(m_uart); + + if (!devPath) { - cerr << __FUNCTION__ << ": open of " << tty << " failed: " + cerr << __FUNCTION__ << ": mraa_uart_get_dev_path() failed" << endl; + return; + } + + // now open the tty + if ( (m_ttyFd = open(devPath, O_RDWR)) == -1) + { + cerr << __FUNCTION__ << ": open of " << devPath << " failed: " << strerror(errno) << endl; return; } diff --git a/src/wt5001/wt5001.h b/src/wt5001/wt5001.h index bc69bbac..ccf32096 100644 --- a/src/wt5001/wt5001.h +++ b/src/wt5001/wt5001.h @@ -110,9 +110,8 @@ namespace upm { * WT5001 Serial MP3 module constructor * * @param uart default uart to use (0 or 1) - * @param tty tty device to use */ - WT5001(int uart, const char *tty); + WT5001(int uart); /** * WT5001 Serial MP3 module Destructor