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 28var MP3Player = require('jsupm_wt5001'); 29 30function printUsage(progname) 31{ 32 console.log("Usage: node " + progname + " <command>"); 33 console.log("Commands:"); 34 console.log("0 - stop playing"); 35 console.log("1 - start playing track 1"); 36 console.log("2 - pause/un-pause playback"); 37 console.log("3 - next track"); 38 console.log("4 - previous track"); 39} 40 41// Instantiate a WT5001 serial MP3 player on uart 0. 42// This example was tested on the Grove Serial MP3 module. 43 44var myMP3Player = new MP3Player.WT5001(0); 45 46var cmd = -1; 47if (process.argv.length > 2) 48 cmd = parseInt(process.argv[2]); 49 50if (!myMP3Player.setupTty(MP3Player.int_B9600)) 51{ 52 console.log("Failed to setup tty port parameters"); 53 process.exit(0); 54} 55 56switch (cmd) 57{ 58 case 0: 59 myMP3Player.stop(); 60 break; 61 62 case 1: 63 myMP3Player.play(MP3Player.WT5001.SD, 1); 64 break; 65 66 case 2: 67 myMP3Player.pause(); 68 break; 69 70 case 3: 71 myMP3Player.next(); 72 break; 73 74 case 4: 75 myMP3Player.previous(); 76 break; 77 78 default: 79 // nothing, just output usage, and info below 80 printUsage(process.argv[1]); 81 break; 82} 83 84// print out some information 85var vol = new MP3Player.uint8Array(0); 86myMP3Player.getVolume(vol); 87console.log("The current volume is: " + vol.getitem(0)); 88 89var ps = new MP3Player.uint8Array(0); 90myMP3Player.getPlayState(ps); 91console.log("The current play state is: " + ps.getitem(0)); 92 93var numf = new MP3Player.uint16Array(0); 94myMP3Player.getNumFiles(MP3Player.WT5001.SD, numf); 95console.log("The number of files on the SD card is: " + numf.getitem(0)); 96 97var curf = new MP3Player.uint16Array(0); 98myMP3Player.getCurrentFile(curf); 99console.log("The current file is: " + curf.getitem(0)); 100 101// set the date 102myMP3Player.setDate(2015, 3, 14); 103 104// set the time 105myMP3Player.setTime(9, 26, 53); 106 107var year = new MP3Player.uint16Array(0); 108var month = new MP3Player.uint8Array(0); 109var day = new MP3Player.uint8Array(0); 110myMP3Player.getDate(year, month, day); 111var mp3date = month.getitem(0) + "/"; 112mp3date += (day.getitem(0) + "/"); 113mp3date += year.getitem(0); 114console.log("The device date is: " + mp3date); 115 116var hour = new MP3Player.uint8Array(0); 117var minute = new MP3Player.uint8Array(0); 118var second = new MP3Player.uint8Array(0); 119myMP3Player.getTime(hour, minute, second); 120var mp3time = hour.getitem(0) + ":"; 121mp3time += (minute.getitem(0) + ":"); 122mp3time += second.getitem(0); 123console.log("The device time is: " + mp3time); 124 125// Print message when exiting 126process.on('SIGINT', function() 127{ 128 console.log("Exiting..."); 129 process.exit(0); 130}); 131