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>
This commit is contained in:
Zion Orent 2015-03-24 13:14:55 -04:00 committed by Mihai Tudor Panu
parent f0cd7843c7
commit ff897e84eb
3 changed files with 129 additions and 20 deletions

View File

@ -29,7 +29,7 @@ var MP3Player = require('jsupm_wt5001');
function printUsage(progname)
{
console.log("Usage:" + progname + " <command>");
console.log("Usage: node " + progname + " <command>");
console.log("Commands:");
console.log("0 - stop playing");
console.log("1 - start playing track 1");
@ -98,25 +98,11 @@ var curf = new MP3Player.uint16Array(0);
myMP3Player.getCurrentFile(curf);
console.log("The current file is: " + curf.getitem(0));
/*
// Example: set the date
var year = new MP3Player.uint16Array(0);
year.setitem(2015);
var month = new MP3Player.uint8Array(0);
month.setitem(1);
var day = new MP3Player.uint8Array(0);
day.setitem(1);
myMP3Player.setDate(year, month, day);
// set the date
myMP3Player.setDate(2015, 3, 14);
// Example: set the date
var hour = new MP3Player.uint8Array(0);
hour.setitem(12);
var minute = new MP3Player.uint8Array(0);
minute.setitem(30);
var second = new MP3Player.uint8Array(0);
second.setitem(30);
myMP3Player.setTime(hour, minute, second);
*/
// set the time
myMP3Player.setTime(9, 26, 53);
var year = new MP3Player.uint16Array(0);
var month = new MP3Player.uint8Array(0);

107
examples/python/wt5001.py Normal file
View File

@ -0,0 +1,107 @@
#!/usr/bin/python
# Author: Zion Orent <zorent@ics.com>
# Copyright (c) 2015 Intel Corporation.
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
import time, signal, sys
import pyupm_wt5001 as upmWt5001
# Instantiate a WT5001 serial MP3 player on uart 0.
# This example was tested on the Grove Serial MP3 module.
myMP3Player = upmWt5001.WT5001(0)
def printUsage(progname):
print ("Usage: python " + progname + " <command>\n"
"Commands:\n"
"0 - stop playing\n"
"1 - start playing track 1\n"
"2 - pause/un-pause playback\n"
"3 - next track\n"
"4 - previous track")
cmd = -1;
if (len(sys.argv) > 1):
cmd = int(sys.argv[1])
if (not myMP3Player.setupTty(upmWt5001.cvar.int_B9600)):
print "Failed to setup tty port parameters"
sys.exit(0)
if cmd == 0:
myMP3Player.stop()
elif cmd == 1:
myMP3Player.play(upmWt5001.WT5001.SD, 1)
elif cmd == 2:
myMP3Player.pause()
elif cmd == 3:
myMP3Player.next()
elif cmd == 4:
myMP3Player.previous()
else:
# nothing, just output usage, and info below
printUsage(sys.argv[0])
# print out some information
vol = upmWt5001.uint8Array(0)
myMP3Player.getVolume(vol)
print "The current volume is: " + str(vol.__getitem__(0))
ps = upmWt5001.uint8Array(0)
myMP3Player.getPlayState(ps)
print "The current play state is: " + str(ps.__getitem__(0))
numf = upmWt5001.uint16Array(0)
myMP3Player.getNumFiles(upmWt5001.WT5001.SD, numf)
print "The number of files on the SD card is: " + str(numf.__getitem__(0))
curf = upmWt5001.uint16Array(0)
myMP3Player.getCurrentFile(curf)
print "The current file is: " + str(curf.__getitem__(0))
# set the date
myMP3Player.setDate(2015, 3, 14)
# set the time
myMP3Player.setTime(9, 26, 53)
year = upmWt5001.uint16Array(0)
month = upmWt5001.uint8Array(0)
day = upmWt5001.uint8Array(0)
myMP3Player.getDate(year, month, day)
mp3date = str(month.__getitem__(0)) + "/"
mp3date += (str(day.__getitem__(0)) + "/")
mp3date += str(year.__getitem__(0))
print "The device date is: " + mp3date
hour = upmWt5001.uint8Array(0)
minute = upmWt5001.uint8Array(0)
second = upmWt5001.uint8Array(0)
myMP3Player.getTime(hour, minute, second)
mp3time = str(hour.__getitem__(0)) + ":"
mp3time += (str(minute.__getitem__(0)) + ":")
mp3time += str(second.__getitem__(0))
print "The device time is: " + mp3time

View File

@ -1,9 +1,25 @@
%module pyupm_wt5001
%include "../upm.i"
%include "../carrays_uint8_t.i"
%include "../carrays_uint16_t.i"
%typemap(in) uint8_t * {
void *argp = 0 ;
int res = SWIG_ConvertPtr($input, &argp,SWIGTYPE_p_uint8Array, 0 | 0 );
$1 = reinterpret_cast< uint8_t * >(argp);
}
%typemap(in) uint16_t * {
void *argp = 0 ;
int res = SWIG_ConvertPtr($input, &argp,SWIGTYPE_p_uint16Array, 0 | 0 );
$1 = reinterpret_cast< uint16_t * >(argp);
}
%feature("autodoc", "3");
%include "wt5001.h"
%{
#include "wt5001.h"
speed_t int_B9600 = B9600;
%}
%include "wt5001.h"
speed_t int_B9600 = B9600;