Brak opisu

WT5001Sample.java 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. import java.io.IOException;
  2. /*
  3. * Author: Stefan Andritoiu <stefan.andritoiu@intel.com>
  4. * Copyright (c) 2015 Intel Corporation.
  5. *
  6. * Permission is hereby granted, free of charge, to any person obtaining
  7. * a copy of this software and associated documentation files (the
  8. * "Software"), to deal in the Software without restriction, including
  9. * without limitation the rights to use, copy, modify, merge, publish,
  10. * distribute, sublicense, and/or sell copies of the Software, and to
  11. * permit persons to whom the Software is furnished to do so, subject to
  12. * the following conditions:
  13. *
  14. * The above copyright notice and this permission notice shall be
  15. * included in all copies or substantial portions of the Software.
  16. *
  17. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  18. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  19. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  20. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  21. * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  22. * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  23. * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  24. */
  25. //NOT TESTED!!!
  26. public class WT5001Sample {
  27. static private void printUsage() {
  28. System.out.println("Usage: java WT5001Sample <command>");
  29. System.out.println("Commands:");
  30. System.out.println("0 - stop playing");
  31. System.out.println("1 - start playing track 1");
  32. System.out.println("2 - pause/un-pause playback");
  33. System.out.println("3 - next track");
  34. System.out.println("4 - previous track");
  35. }
  36. public static void main(String[] args) {
  37. // ! [Interesting]
  38. // Instantiate a WT5001 serial MP3 player on uart 0
  39. upm_wt5001.WT5001 mp3 = new upm_wt5001.WT5001(0);
  40. int cmd = -1;
  41. if (args.length > 0)
  42. cmd = Integer.parseInt(args[0]);
  43. // make sure port is initialized properly. 9600 baud is the default
  44. if (!mp3.setupTty()) {
  45. System.err.println("error in loading native library");
  46. System.exit(-1);
  47. }
  48. switch (cmd) {
  49. case 0 :
  50. mp3.stop();
  51. break;
  52. case 1 :
  53. mp3.play(upm_wt5001.WT5001.WT5001_PLAYSOURCE_T.SD, 1);
  54. break;
  55. case 2 :
  56. mp3.pause();
  57. break;
  58. case 3 :
  59. mp3.next();
  60. break;
  61. case 4 :
  62. mp3.previous();
  63. break;
  64. default :
  65. // nothing, just output usage, and info below
  66. printUsage();
  67. break;
  68. }
  69. // print out some information
  70. try {
  71. short vol;
  72. vol = mp3.getVolume();
  73. System.out.println("The current volume is: " + vol);
  74. } catch (IOException e) {
  75. e.printStackTrace();
  76. }
  77. try {
  78. short ps;
  79. ps = mp3.getPlayState();
  80. System.out.println("The current play state is: " + ps);
  81. } catch (IOException e) {
  82. e.printStackTrace();
  83. }
  84. try {
  85. int numf;
  86. numf = mp3.getNumFiles(upm_wt5001.WT5001.WT5001_PLAYSOURCE_T.SD);
  87. System.out.println("The number of files on the SD card is: " + numf);
  88. } catch (IOException e) {
  89. e.printStackTrace();
  90. }
  91. try {
  92. int curf;
  93. curf = mp3.getCurrentFile();
  94. System.out.println("The current file is: " + curf);
  95. } catch (IOException e) {
  96. e.printStackTrace();
  97. }
  98. int year[] = new int[1];
  99. short month[] = new short[1];
  100. short day[] = new short[1];
  101. if (mp3.getDate(year, month, day))
  102. System.out.println("The device date is: " + year[0] + "/" + month[0] + "/" + day[0]);
  103. short hour[] = new short[1];
  104. short minute[] = new short[1];
  105. short second[] = new short[1];
  106. if (mp3.getTime(hour, minute, second))
  107. System.out
  108. .println("The device time is: " + hour[0] + ":" + minute[0] + ":" + second[0]);
  109. // ! [Interesting]
  110. }
  111. }