No Description

wt5001.js 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /*jslint node:true, vars:true, bitwise:true, unparam:true */
  2. /*jshint unused:true */
  3. /*global */
  4. /*
  5. * Author: Zion Orent <zorent@ics.com>
  6. * Copyright (c) 2015 Intel Corporation.
  7. *
  8. * Permission is hereby granted, free of charge, to any person obtaining
  9. * a copy of this software and associated documentation files (the
  10. * "Software"), to deal in the Software without restriction, including
  11. * without limitation the rights to use, copy, modify, merge, publish,
  12. * distribute, sublicense, and/or sell copies of the Software, and to
  13. * permit persons to whom the Software is furnished to do so, subject to
  14. * the following conditions:
  15. *
  16. * The above copyright notice and this permission notice shall be
  17. * included in all copies or substantial portions of the Software.
  18. *
  19. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  20. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  21. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  22. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  23. * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  24. * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  25. * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  26. */
  27. var MP3Player = require('jsupm_wt5001');
  28. function printUsage(progname)
  29. {
  30. console.log("Usage: node " + progname + " <command>");
  31. console.log("Commands:");
  32. console.log("0 - stop playing");
  33. console.log("1 - start playing track 1");
  34. console.log("2 - pause/un-pause playback");
  35. console.log("3 - next track");
  36. console.log("4 - previous track");
  37. }
  38. // Instantiate a WT5001 serial MP3 player on uart 0.
  39. // This example was tested on the Grove Serial MP3 module.
  40. var myMP3Player = new MP3Player.WT5001(0);
  41. var cmd = -1;
  42. if (process.argv.length > 2)
  43. cmd = parseInt(process.argv[2]);
  44. if (!myMP3Player.setupTty(MP3Player.int_B9600))
  45. {
  46. console.log("Failed to setup tty port parameters");
  47. process.exit(0);
  48. }
  49. switch (cmd)
  50. {
  51. case 0:
  52. myMP3Player.stop();
  53. break;
  54. case 1:
  55. myMP3Player.play(MP3Player.WT5001.SD, 1);
  56. break;
  57. case 2:
  58. myMP3Player.pause();
  59. break;
  60. case 3:
  61. myMP3Player.next();
  62. break;
  63. case 4:
  64. myMP3Player.previous();
  65. break;
  66. default:
  67. // nothing, just output usage, and info below
  68. printUsage(process.argv[1]);
  69. break;
  70. }
  71. // print out some information
  72. var vol = new MP3Player.uint8Array(0);
  73. myMP3Player.getVolume(vol);
  74. console.log("The current volume is: " + vol.getitem(0));
  75. var ps = new MP3Player.uint8Array(0);
  76. myMP3Player.getPlayState(ps);
  77. console.log("The current play state is: " + ps.getitem(0));
  78. var numf = new MP3Player.uint16Array(0);
  79. myMP3Player.getNumFiles(MP3Player.WT5001.SD, numf);
  80. console.log("The number of files on the SD card is: " + numf.getitem(0));
  81. var curf = new MP3Player.uint16Array(0);
  82. myMP3Player.getCurrentFile(curf);
  83. console.log("The current file is: " + curf.getitem(0));
  84. // set the date
  85. myMP3Player.setDate(2015, 3, 14);
  86. // set the time
  87. myMP3Player.setTime(9, 26, 53);
  88. var year = new MP3Player.uint16Array(0);
  89. var month = new MP3Player.uint8Array(0);
  90. var day = new MP3Player.uint8Array(0);
  91. myMP3Player.getDate(year, month, day);
  92. var mp3date = month.getitem(0) + "/";
  93. mp3date += (day.getitem(0) + "/");
  94. mp3date += year.getitem(0);
  95. console.log("The device date is: " + mp3date);
  96. var hour = new MP3Player.uint8Array(0);
  97. var minute = new MP3Player.uint8Array(0);
  98. var second = new MP3Player.uint8Array(0);
  99. myMP3Player.getTime(hour, minute, second);
  100. var mp3time = hour.getitem(0) + ":";
  101. mp3time += (minute.getitem(0) + ":");
  102. mp3time += second.getitem(0);
  103. console.log("The device time is: " + mp3time);
  104. // Print message when exiting
  105. process.on('SIGINT', function()
  106. {
  107. console.log("Exiting...");
  108. process.exit(0);
  109. });