1 /* 2 * Author: Stefan Andritoiu <stefan.andritoiu@intel.com> 3 * Copyright (c) 2015 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 25 //NOT TESTED!!! 26 public class WT5001Sample { 27 28 static { 29 try { 30 System.loadLibrary("javaupm_wt5001"); 31 } catch (UnsatisfiedLinkError e) { 32 System.err.println("error in loading native library"); 33 System.exit(-1); 34 } 35 } 36 printUsage()37 static private void printUsage() { 38 System.out.println("Usage: java WT5001Sample <command>"); 39 System.out.println("Commands:"); 40 System.out.println("0 - stop playing"); 41 System.out.println("1 - start playing track 1"); 42 System.out.println("2 - pause/un-pause playback"); 43 System.out.println("3 - next track"); 44 System.out.println("4 - previous track"); 45 } 46 main(String[] args)47 public static void main(String[] args) throws InterruptedException { 48 // ! [Interesting] 49 // Instantiate a WT5001 serial MP3 player on uart 0 50 upm_wt5001.WT5001 mp3 = new upm_wt5001.WT5001(0); 51 52 int cmd = -1; 53 if (args.length > 0) 54 cmd = Integer.parseInt(args[0]); 55 56 // make sure port is initialized properly. 9600 baud is the default 57 if (!mp3.setupTty()) { 58 System.err.println("error in loading native library"); 59 System.exit(-1); 60 } 61 62 switch (cmd) { 63 case 0 : 64 mp3.stop(); 65 break; 66 67 case 1 : 68 mp3.play(upm_wt5001.WT5001.WT5001_PLAYSOURCE_T.SD, 1); 69 break; 70 71 case 2 : 72 mp3.pause(); 73 break; 74 75 case 3 : 76 mp3.next(); 77 break; 78 79 case 4 : 80 mp3.previous(); 81 break; 82 83 default : 84 // nothing, just output usage, and info below 85 printUsage(); 86 break; 87 } 88 89 // print out some information 90 short vol[] = new short[1]; 91 if (mp3.getVolume(vol)) 92 System.out.println("The current volume is: " + vol[0]); 93 94 short ps[] = new short[1]; 95 if (mp3.getPlayState(ps)) 96 System.out.println("The current play state is: " + ps[0]); 97 98 int numf[] = new int[1]; 99 if (mp3.getNumFiles(upm_wt5001.WT5001.WT5001_PLAYSOURCE_T.SD, numf)) 100 System.out.println("The number of files on the SD card is: " + numf[0]); 101 102 int curf[] = new int[1]; 103 if (mp3.getCurrentFile(curf)) 104 System.out.println("The current file is: " + curf[0]); 105 106 int year[] = new int[1]; 107 short month[] = new short[1]; 108 short day[] = new short[1]; 109 if (mp3.getDate(year, month, day)) 110 System.out.println("The device date is: " + year[0] + "/" + month[0] + "/" + day[0]); 111 112 short hour[] = new short[1]; 113 short minute[] = new short[1]; 114 short second[] = new short[1]; 115 if (mp3.getTime(hour, minute, second)) 116 System.out 117 .println("The device time is: " + hour[0] + ":" + minute[0] + ":" + second[0]); 118 // ! [Interesting] 119 } 120 121 }