Browse Source

wt5001: new python example and update to JS example for wt5001 mp3 player

Signed-off-by: Zion Orent <zorent@ics.com>
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
Zion Orent 10 years ago
parent
commit
ff897e84eb
3 changed files with 129 additions and 20 deletions
  1. 5
    19
      examples/javascript/wt5001.js
  2. 107
    0
      examples/python/wt5001.py
  3. 17
    1
      src/wt5001/pyupm_wt5001.i

+ 5
- 19
examples/javascript/wt5001.js View File

@@ -29,7 +29,7 @@ var MP3Player = require('jsupm_wt5001');
29 29
 
30 30
 function printUsage(progname)
31 31
 {
32
-	console.log("Usage:" + progname + " <command>");
32
+	console.log("Usage: node " + progname + " <command>");
33 33
 	console.log("Commands:");
34 34
 	console.log("0  - stop playing");
35 35
 	console.log("1  - start playing track 1");
@@ -98,25 +98,11 @@ var curf = new MP3Player.uint16Array(0);
98 98
 myMP3Player.getCurrentFile(curf);
99 99
 console.log("The current file is: " + curf.getitem(0));
100 100
 
101
-/*
102
-// Example: set the date
103
-var year = new MP3Player.uint16Array(0);
104
-year.setitem(2015);
105
-var month = new MP3Player.uint8Array(0);
106
-month.setitem(1);
107
-var day = new MP3Player.uint8Array(0);
108
-day.setitem(1);
109
-myMP3Player.setDate(year, month, day);
101
+// set the date
102
+myMP3Player.setDate(2015, 3, 14);
110 103
 
111
-// Example: set the date
112
-var hour = new MP3Player.uint8Array(0);
113
-hour.setitem(12);
114
-var minute = new MP3Player.uint8Array(0);
115
-minute.setitem(30);
116
-var second = new MP3Player.uint8Array(0);
117
-second.setitem(30);
118
-myMP3Player.setTime(hour, minute, second);
119
-*/
104
+// set the time
105
+myMP3Player.setTime(9, 26, 53);
120 106
 
121 107
 var year = new MP3Player.uint16Array(0);
122 108
 var month = new MP3Player.uint8Array(0);

+ 107
- 0
examples/python/wt5001.py View File

@@ -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

+ 17
- 1
src/wt5001/pyupm_wt5001.i View File

@@ -1,9 +1,25 @@
1 1
 %module pyupm_wt5001
2 2
 %include "../upm.i"
3
+%include "../carrays_uint8_t.i"
4
+%include "../carrays_uint16_t.i"
5
+
6
+%typemap(in) uint8_t * {
7
+  void *argp = 0 ;
8
+  int res = SWIG_ConvertPtr($input, &argp,SWIGTYPE_p_uint8Array, 0 |  0 );
9
+  $1 = reinterpret_cast< uint8_t * >(argp);
10
+}
11
+
12
+%typemap(in) uint16_t * {
13
+  void *argp = 0 ;
14
+  int res = SWIG_ConvertPtr($input, &argp,SWIGTYPE_p_uint16Array, 0 |  0 );
15
+  $1 = reinterpret_cast< uint16_t * >(argp);
16
+}
3 17
 
4 18
 %feature("autodoc", "3");
5 19
 
6
-%include "wt5001.h"
7 20
 %{
8 21
     #include "wt5001.h"
22
+    speed_t int_B9600 = B9600;
9 23
 %}
24
+%include "wt5001.h"
25
+speed_t int_B9600 = B9600;