mirror of
https://github.com/eclipse/upm.git
synced 2025-07-02 09:51:14 +03:00
python_examples: Reformatted, self-checking, executable
* Moved body of each python example to main. This allows for basic load module testing for CI * General cleanup of python modules (crlf/tabs/prints/etc) * Chmod'ed to 755 to allow running examples without specifying the python interpreter * Added ctest for loading python2/3 modules * Added jniclasscode pragma for java swig interface files. * Updated check_examplenames.py module to check all languages vs. a cxx example name * Added tests for checking python module and test loading * Added 'make test' to travis-ci run (run ctests) * Print a more meaningful message when not building cxx docs into python modules * Updated check_clean.py to only check java wrapper files * ENABLED ctests for UPM * Deleted using_carrays.py python example - this is covered by other examples Signed-off-by: Noel Eck <noel.eck@intel.com>
This commit is contained in:
133
examples/python/wt5001.py
Normal file → Executable file
133
examples/python/wt5001.py
Normal file → Executable file
@ -24,84 +24,83 @@
|
||||
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 main():
|
||||
# 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")
|
||||
|
||||
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)
|
||||
|
||||
cmd = -1;
|
||||
if (len(sys.argv) > 1):
|
||||
cmd = int(sys.argv[1])
|
||||
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])
|
||||
|
||||
if (not myMP3Player.setupTty(upmWt5001.cvar.int_B9600)):
|
||||
print "Failed to setup tty port parameters"
|
||||
sys.exit(0)
|
||||
# print out some information
|
||||
vol = upmWt5001.uint8Array(0)
|
||||
myMP3Player.getVolume(vol)
|
||||
print "The current volume is: " + str(vol.__getitem__(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])
|
||||
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))
|
||||
|
||||
# print out some information
|
||||
vol = upmWt5001.uint8Array(0)
|
||||
myMP3Player.getVolume(vol)
|
||||
print "The current volume is: " + str(vol.__getitem__(0))
|
||||
curf = upmWt5001.uint16Array(0)
|
||||
myMP3Player.getCurrentFile(curf)
|
||||
print "The current file is: " + str(curf.__getitem__(0))
|
||||
|
||||
ps = upmWt5001.uint8Array(0)
|
||||
myMP3Player.getPlayState(ps)
|
||||
print "The current play state is: " + str(ps.__getitem__(0))
|
||||
# set the date
|
||||
myMP3Player.setDate(2015, 3, 14)
|
||||
|
||||
numf = upmWt5001.uint16Array(0)
|
||||
myMP3Player.getNumFiles(upmWt5001.WT5001.SD, numf)
|
||||
print "The number of files on the SD card is: " + str(numf.__getitem__(0))
|
||||
# set the time
|
||||
myMP3Player.setTime(9, 26, 53)
|
||||
|
||||
curf = upmWt5001.uint16Array(0)
|
||||
myMP3Player.getCurrentFile(curf)
|
||||
print "The current file is: " + str(curf.__getitem__(0))
|
||||
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
|
||||
|
||||
# set the date
|
||||
myMP3Player.setDate(2015, 3, 14)
|
||||
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
|
||||
|
||||
# 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
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
Reference in New Issue
Block a user