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
25#include <unistd.h>
26#include <iostream>
27#include <signal.h>
28#include "wt5001.h"
29
30using namespace std;
31
32void printUsage(char *progname)
33{
34  cout << "Usage:" << progname << " <command>" << endl;
35  cout << "Commands:" << endl;
36  cout << "0  - stop playing" << endl;
37  cout << "1  - start playing track 1" << endl;
38  cout << "2  - pause/un-pause playback" << endl;
39  cout << "3  - next track" << endl;
40  cout << "4  - previous track" << endl;
41}
42
43int main (int argc, char **argv)
44{
45//! [Interesting]
46  // Instantiate a WT5001 serial MP3 player on uart 0.
47  // This example was tested on the Grove Serial MP3 module.
48
49  upm::WT5001* mp3 = new upm::WT5001(0);
50
51  int cmd = -1;
52  if (argc > 1)
53    cmd = atoi(argv[1]);
54
55  // make sure port is initialized properly.  9600 baud is the default.
56  if (!mp3->setupTty(B9600))
57    {
58      cerr << "Failed to setup tty port parameters" << endl;
59      return 1;
60    }
61
62  switch (cmd)
63    {
64    case 0:
65      mp3->stop();
66      break;
67
68    case 1:
69      mp3->play(upm::WT5001::SD, 1);
70      break;
71
72    case 2:
73      mp3->pause();
74      break;
75
76    case 3:
77      mp3->next();
78      break;
79
80    case 4:
81      mp3->previous();
82      break;
83
84    default:
85      // nothing, just output usage, and info below
86      printUsage(argv[0]);
87      break;
88    }
89
90  // Example: set the date
91  // mp3->setDate(2015, 1, 1);
92
93  // Example: set the time
94  // mp3->setTime(12, 30, 30);
95
96  // print out some information
97  uint8_t vol = 0;
98  if (mp3->getVolume(&vol))
99    cout << "The current volume is: " << int(vol) << endl;
100
101  uint8_t ps = 0;
102  if (mp3->getPlayState(&ps))
103    cout << "The current play state is: " << int(ps) << endl;
104
105  uint16_t numf = 0;
106  if (mp3->getNumFiles(upm::WT5001::SD, &numf))
107    cout << "The number of files on the SD card is: " << int(numf) << endl;
108
109  uint16_t curf = 0;
110  if (mp3->getCurrentFile(&curf))
111    cout << "The current file is: " << int(curf) << endl;
112
113  uint16_t year = 0;
114  uint8_t month = 0, day = 0;
115  if (mp3->getDate(&year, &month, &day))
116    cout << "The device date is: " << int(month) << "/" << int(day)
117         << "/" << int(year) << endl;
118
119  uint8_t hour = 0, minute = 0, second = 0;
120  if (mp3->getTime(&hour, &minute, &second))
121    cout << "The device time is: " << int(hour) << ":" << int(minute)
122         << ":" << int(second) << endl;
123
124//! [Interesting]
125
126  cout << "Exiting..." << endl;
127
128  delete mp3;
129  return 0;
130}
131