No Description

wt5001.py 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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. import time, signal, sys
  24. import pyupm_wt5001 as upmWt5001
  25. # Instantiate a WT5001 serial MP3 player on uart 0.
  26. # This example was tested on the Grove Serial MP3 module.
  27. myMP3Player = upmWt5001.WT5001(0)
  28. def printUsage(progname):
  29. print ("Usage: python " + progname + " <command>\n"
  30. "Commands:\n"
  31. "0 - stop playing\n"
  32. "1 - start playing track 1\n"
  33. "2 - pause/un-pause playback\n"
  34. "3 - next track\n"
  35. "4 - previous track")
  36. cmd = -1;
  37. if (len(sys.argv) > 1):
  38. cmd = int(sys.argv[1])
  39. if (not myMP3Player.setupTty(upmWt5001.cvar.int_B9600)):
  40. print "Failed to setup tty port parameters"
  41. sys.exit(0)
  42. if cmd == 0:
  43. myMP3Player.stop()
  44. elif cmd == 1:
  45. myMP3Player.play(upmWt5001.WT5001.SD, 1)
  46. elif cmd == 2:
  47. myMP3Player.pause()
  48. elif cmd == 3:
  49. myMP3Player.next()
  50. elif cmd == 4:
  51. myMP3Player.previous()
  52. else:
  53. # nothing, just output usage, and info below
  54. printUsage(sys.argv[0])
  55. # print out some information
  56. vol = upmWt5001.uint8Array(0)
  57. myMP3Player.getVolume(vol)
  58. print "The current volume is: " + str(vol.__getitem__(0))
  59. ps = upmWt5001.uint8Array(0)
  60. myMP3Player.getPlayState(ps)
  61. print "The current play state is: " + str(ps.__getitem__(0))
  62. numf = upmWt5001.uint16Array(0)
  63. myMP3Player.getNumFiles(upmWt5001.WT5001.SD, numf)
  64. print "The number of files on the SD card is: " + str(numf.__getitem__(0))
  65. curf = upmWt5001.uint16Array(0)
  66. myMP3Player.getCurrentFile(curf)
  67. print "The current file is: " + str(curf.__getitem__(0))
  68. # set the date
  69. myMP3Player.setDate(2015, 3, 14)
  70. # set the time
  71. myMP3Player.setTime(9, 26, 53)
  72. year = upmWt5001.uint16Array(0)
  73. month = upmWt5001.uint8Array(0)
  74. day = upmWt5001.uint8Array(0)
  75. myMP3Player.getDate(year, month, day)
  76. mp3date = str(month.__getitem__(0)) + "/"
  77. mp3date += (str(day.__getitem__(0)) + "/")
  78. mp3date += str(year.__getitem__(0))
  79. print "The device date is: " + mp3date
  80. hour = upmWt5001.uint8Array(0)
  81. minute = upmWt5001.uint8Array(0)
  82. second = upmWt5001.uint8Array(0)
  83. myMP3Player.getTime(hour, minute, second)
  84. mp3time = str(hour.__getitem__(0)) + ":"
  85. mp3time += (str(minute.__getitem__(0)) + ":")
  86. mp3time += str(second.__getitem__(0))
  87. print "The device time is: " + mp3time