diff --git a/examples/javascript/wt5001.js b/examples/javascript/wt5001.js index 736ec662..ca58b046 100644 --- a/examples/javascript/wt5001.js +++ b/examples/javascript/wt5001.js @@ -29,7 +29,7 @@ var MP3Player = require('jsupm_wt5001'); function printUsage(progname) { - console.log("Usage:" + progname + " "); + console.log("Usage: node " + progname + " "); 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); diff --git a/examples/python/wt5001.py b/examples/python/wt5001.py new file mode 100644 index 00000000..315799cc --- /dev/null +++ b/examples/python/wt5001.py @@ -0,0 +1,107 @@ +#!/usr/bin/python +# Author: Zion Orent +# 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 + " \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 diff --git a/src/wt5001/pyupm_wt5001.i b/src/wt5001/pyupm_wt5001.i index caa684f3..7e9dde55 100644 --- a/src/wt5001/pyupm_wt5001.i +++ b/src/wt5001/pyupm_wt5001.i @@ -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;