No Description

wt5001.cxx 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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.
  43. // This example was tested on the Grove Serial MP3 module.
  44. upm::WT5001* mp3 = new upm::WT5001(0);
  45. int cmd = -1;
  46. if (argc > 1)
  47. cmd = atoi(argv[1]);
  48. // make sure port is initialized properly. 9600 baud is the default.
  49. if (!mp3->setupTty(B9600))
  50. {
  51. cerr << "Failed to setup tty port parameters" << endl;
  52. return 1;
  53. }
  54. switch (cmd)
  55. {
  56. case 0:
  57. mp3->stop();
  58. break;
  59. case 1:
  60. mp3->play(upm::WT5001::SD, 1);
  61. break;
  62. case 2:
  63. mp3->pause();
  64. break;
  65. case 3:
  66. mp3->next();
  67. break;
  68. case 4:
  69. mp3->previous();
  70. break;
  71. default:
  72. // nothing, just output usage, and info below
  73. printUsage(argv[0]);
  74. break;
  75. }
  76. // Example: set the date
  77. // mp3->setDate(2015, 1, 1);
  78. // Example: set the time
  79. // mp3->setTime(12, 30, 30);
  80. // print out some information
  81. uint8_t vol = 0;
  82. if (mp3->getVolume(&vol))
  83. cout << "The current volume is: " << int(vol) << endl;
  84. uint8_t ps = 0;
  85. if (mp3->getPlayState(&ps))
  86. cout << "The current play state is: " << int(ps) << endl;
  87. uint16_t numf = 0;
  88. if (mp3->getNumFiles(upm::WT5001::SD, &numf))
  89. cout << "The number of files on the SD card is: " << int(numf) << endl;
  90. uint16_t curf = 0;
  91. if (mp3->getCurrentFile(&curf))
  92. cout << "The current file is: " << int(curf) << endl;
  93. uint16_t year = 0;
  94. uint8_t month = 0, day = 0;
  95. if (mp3->getDate(&year, &month, &day))
  96. cout << "The device date is: " << int(month) << "/" << int(day)
  97. << "/" << int(year) << endl;
  98. uint8_t hour = 0, minute = 0, second = 0;
  99. if (mp3->getTime(&hour, &minute, &second))
  100. cout << "The device time is: " << int(hour) << ":" << int(minute)
  101. << ":" << int(second) << endl;
  102. //! [Interesting]
  103. cout << "Exiting..." << endl;
  104. delete mp3;
  105. return 0;
  106. }