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 24import time, signal, sys 25import 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. 29myMP3Player = upmWt5001.WT5001(0) 30 31 32def 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 42cmd = -1; 43if (len(sys.argv) > 1): 44 cmd = int(sys.argv[1]) 45 46if (not myMP3Player.setupTty(upmWt5001.cvar.int_B9600)): 47 print "Failed to setup tty port parameters" 48 sys.exit(0) 49 50if cmd == 0: 51 myMP3Player.stop() 52elif cmd == 1: 53 myMP3Player.play(upmWt5001.WT5001.SD, 1) 54elif cmd == 2: 55 myMP3Player.pause() 56elif cmd == 3: 57 myMP3Player.next() 58elif cmd == 4: 59 myMP3Player.previous() 60else: 61 # nothing, just output usage, and info below 62 printUsage(sys.argv[0]) 63 64 65# print out some information 66vol = upmWt5001.uint8Array(0) 67myMP3Player.getVolume(vol) 68print "The current volume is: " + str(vol.__getitem__(0)) 69 70ps = upmWt5001.uint8Array(0) 71myMP3Player.getPlayState(ps) 72print "The current play state is: " + str(ps.__getitem__(0)) 73 74numf = upmWt5001.uint16Array(0) 75myMP3Player.getNumFiles(upmWt5001.WT5001.SD, numf) 76print "The number of files on the SD card is: " + str(numf.__getitem__(0)) 77 78curf = upmWt5001.uint16Array(0) 79myMP3Player.getCurrentFile(curf) 80print "The current file is: " + str(curf.__getitem__(0)) 81 82 83# set the date 84myMP3Player.setDate(2015, 3, 14) 85 86# set the time 87myMP3Player.setTime(9, 26, 53) 88 89 90year = upmWt5001.uint16Array(0) 91month = upmWt5001.uint8Array(0) 92day = upmWt5001.uint8Array(0) 93 94myMP3Player.getDate(year, month, day) 95mp3date = str(month.__getitem__(0)) + "/" 96mp3date += (str(day.__getitem__(0)) + "/") 97mp3date += str(year.__getitem__(0)) 98print "The device date is: " + mp3date 99 100hour = upmWt5001.uint8Array(0) 101minute = upmWt5001.uint8Array(0) 102second = upmWt5001.uint8Array(0) 103myMP3Player.getTime(hour, minute, second) 104mp3time = str(hour.__getitem__(0)) + ":" 105mp3time += (str(minute.__getitem__(0)) + ":") 106mp3time += str(second.__getitem__(0)) 107print "The device time is: " + mp3time 108