Нема описа

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. /*
  2. * Author: Jon Trulson <jtrulson@ics.com>
  3. * Copyright (c) 2014 Intel Corporation.
  4. *
  5. * Permission is hereby granted, free of charge, to any person obtaining
  6. * a copy of this software and associated documentation files (the
  7. * "Software"), to deal in the Software without restriction, including
  8. * without limitation the rights to use, copy, modify, merge, publish,
  9. * distribute, sublicense, and/or sell copies of the Software, and to
  10. * permit persons to whom the Software is furnished to do so, subject to
  11. * the following conditions:
  12. *
  13. * The above copyright notice and this permission notice shall be
  14. * included in all copies or substantial portions of the Software.
  15. *
  16. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  17. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  18. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  19. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  20. * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  21. * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  22. * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  23. */
  24. #include <unistd.h>
  25. #include <iostream>
  26. #include <signal.h>
  27. #include "wt5001.h"
  28. using namespace std;
  29. void printUsage(char *progname)
  30. {
  31. cout << "Usage:" << progname << " <command>" << endl;
  32. cout << "Commands:" << endl;
  33. cout << "0 - stop playing" << endl;
  34. cout << "1 - start playing track 1" << endl;
  35. cout << "2 - pause/un-pause playback" << endl;
  36. cout << "3 - next track" << endl;
  37. cout << "4 - previous track" << endl;
  38. }
  39. int main (int argc, char **argv)
  40. {
  41. //! [Interesting]
  42. // Instantiate a WT5001 serial MP3 player on uart 0 (/dev/ttyS0). This
  43. // works for the galileo G2.
  44. // The Edison uses a different serial port, /dev/ttyMFD1, so if you
  45. // are using this example on an Edison board, set the environment
  46. // variable WT5001_SERIAL_PORT to specify the proper port before
  47. // running this example,
  48. // eg: 'WT5001_SERIAL_PORT=/dev/ttyMFD1 ./wt5001-example'
  49. // This example was tested on the Grove Serial MP3 module.
  50. const char *defaultPort = "/dev/ttyS0";
  51. char *port = getenv("WT5001_SERIAL_PORT");
  52. if (port)
  53. defaultPort = port;
  54. upm::WT5001* mp3 = new upm::WT5001(0, defaultPort);
  55. int cmd = -1;
  56. if (argc > 1)
  57. cmd = atoi(argv[1]);
  58. // make sure port is initialized properly. 9600 baud is the default.
  59. if (!mp3->setupTty(B9600))
  60. {
  61. cerr << "Failed to setup tty port parameters" << endl;
  62. return 1;
  63. }
  64. switch (cmd)
  65. {
  66. case 0:
  67. mp3->stop();
  68. break;
  69. case 1:
  70. mp3->play(upm::WT5001::SD, 1);
  71. break;
  72. case 2:
  73. mp3->pause();
  74. break;
  75. case 3:
  76. mp3->next();
  77. break;
  78. case 4:
  79. mp3->previous();
  80. break;
  81. default:
  82. // nothing, just output usage, and info below
  83. printUsage(argv[0]);
  84. break;
  85. }
  86. // Example: set the date
  87. // mp3->setDate(2015, 1, 1);
  88. // Example: set the time
  89. // mp3->setTime(12, 30, 30);
  90. // print out some information
  91. uint8_t vol = 0;
  92. if (mp3->getVolume(&vol))
  93. cout << "The current volume is: " << int(vol) << endl;
  94. uint8_t ps = 0;
  95. if (mp3->getPlayState(&ps))
  96. cout << "The current play state is: " << int(ps) << endl;
  97. uint16_t numf = 0;
  98. if (mp3->getNumFiles(upm::WT5001::SD, &numf))
  99. cout << "The number of files on the SD card is: " << int(numf) << endl;
  100. uint16_t curf = 0;
  101. if (mp3->getCurrentFile(&curf))
  102. cout << "The current file is: " << int(curf) << endl;
  103. uint16_t year = 0;
  104. uint8_t month = 0, day = 0;
  105. if (mp3->getDate(&year, &month, &day))
  106. cout << "The device date is: " << int(month) << "/" << int(day)
  107. << "/" << int(year) << endl;
  108. uint8_t hour = 0, minute = 0, second = 0;
  109. if (mp3->getTime(&hour, &minute, &second))
  110. cout << "The device time is: " << int(hour) << ":" << int(minute)
  111. << ":" << int(second) << endl;
  112. //! [Interesting]
  113. cout << "Exiting..." << endl;
  114. delete mp3;
  115. return 0;
  116. }