|
@@ -0,0 +1,107 @@
|
|
1
|
+#!/usr/bin/python
|
|
2
|
+# Author: Zion Orent <zorent@ics.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
|
+import time, signal, sys
|
|
25
|
+import pyupm_wt5001 as upmWt5001
|
|
26
|
+
|
|
27
|
+# Instantiate a WT5001 serial MP3 player on uart 0.
|
|
28
|
+# This example was tested on the Grove Serial MP3 module.
|
|
29
|
+myMP3Player = upmWt5001.WT5001(0)
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+def printUsage(progname):
|
|
33
|
+ print ("Usage: python " + progname + " <command>\n"
|
|
34
|
+ "Commands:\n"
|
|
35
|
+ "0 - stop playing\n"
|
|
36
|
+ "1 - start playing track 1\n"
|
|
37
|
+ "2 - pause/un-pause playback\n"
|
|
38
|
+ "3 - next track\n"
|
|
39
|
+ "4 - previous track")
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+cmd = -1;
|
|
43
|
+if (len(sys.argv) > 1):
|
|
44
|
+ cmd = int(sys.argv[1])
|
|
45
|
+
|
|
46
|
+if (not myMP3Player.setupTty(upmWt5001.cvar.int_B9600)):
|
|
47
|
+ print "Failed to setup tty port parameters"
|
|
48
|
+ sys.exit(0)
|
|
49
|
+
|
|
50
|
+if cmd == 0:
|
|
51
|
+ myMP3Player.stop()
|
|
52
|
+elif cmd == 1:
|
|
53
|
+ myMP3Player.play(upmWt5001.WT5001.SD, 1)
|
|
54
|
+elif cmd == 2:
|
|
55
|
+ myMP3Player.pause()
|
|
56
|
+elif cmd == 3:
|
|
57
|
+ myMP3Player.next()
|
|
58
|
+elif cmd == 4:
|
|
59
|
+ myMP3Player.previous()
|
|
60
|
+else:
|
|
61
|
+ # nothing, just output usage, and info below
|
|
62
|
+ printUsage(sys.argv[0])
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+# print out some information
|
|
66
|
+vol = upmWt5001.uint8Array(0)
|
|
67
|
+myMP3Player.getVolume(vol)
|
|
68
|
+print "The current volume is: " + str(vol.__getitem__(0))
|
|
69
|
+
|
|
70
|
+ps = upmWt5001.uint8Array(0)
|
|
71
|
+myMP3Player.getPlayState(ps)
|
|
72
|
+print "The current play state is: " + str(ps.__getitem__(0))
|
|
73
|
+
|
|
74
|
+numf = upmWt5001.uint16Array(0)
|
|
75
|
+myMP3Player.getNumFiles(upmWt5001.WT5001.SD, numf)
|
|
76
|
+print "The number of files on the SD card is: " + str(numf.__getitem__(0))
|
|
77
|
+
|
|
78
|
+curf = upmWt5001.uint16Array(0)
|
|
79
|
+myMP3Player.getCurrentFile(curf)
|
|
80
|
+print "The current file is: " + str(curf.__getitem__(0))
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+# set the date
|
|
84
|
+myMP3Player.setDate(2015, 3, 14)
|
|
85
|
+
|
|
86
|
+# set the time
|
|
87
|
+myMP3Player.setTime(9, 26, 53)
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+year = upmWt5001.uint16Array(0)
|
|
91
|
+month = upmWt5001.uint8Array(0)
|
|
92
|
+day = upmWt5001.uint8Array(0)
|
|
93
|
+
|
|
94
|
+myMP3Player.getDate(year, month, day)
|
|
95
|
+mp3date = str(month.__getitem__(0)) + "/"
|
|
96
|
+mp3date += (str(day.__getitem__(0)) + "/")
|
|
97
|
+mp3date += str(year.__getitem__(0))
|
|
98
|
+print "The device date is: " + mp3date
|
|
99
|
+
|
|
100
|
+hour = upmWt5001.uint8Array(0)
|
|
101
|
+minute = upmWt5001.uint8Array(0)
|
|
102
|
+second = upmWt5001.uint8Array(0)
|
|
103
|
+myMP3Player.getTime(hour, minute, second)
|
|
104
|
+mp3time = str(hour.__getitem__(0)) + ":"
|
|
105
|
+mp3time += (str(minute.__getitem__(0)) + ":")
|
|
106
|
+mp3time += str(second.__getitem__(0))
|
|
107
|
+print "The device time is: " + mp3time
|