Example USBPIR Python program for playing an MP3
Source Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
#!/usr/bin/env python from tkinter import * from ctypes import * import os import subprocess import binascii import vlc root = Tk() text1="Finding U4xx:" text2="Number Found:" text3="Vendor ID:" text4="Product ID:" text5="Firmware:" text6="USBPIR signal:" data1="" data2="" data3="" data4="" data5="" data6="" # ---------------------------------------------------- USBbuff = create_string_buffer(200) USBpy = windll.USBm32 data1 = USBpy.USBm_FindDevices() if data1 == -1: data1 = 'Found' else: data1 = '' data2 = USBpy.USBm_NumberOfDevices() data3 = hex(USBpy.USBm_DeviceVID(0)) data4 = USBpy.USBm_DevicePID(0) data5 = hex(USBpy.USBm_DeviceDID(0)) ret = USBpy.USBm_Copyright(USBbuff) print("Copyright: " + str(USBbuff.value, 'utf-8')) ret = USBpy.USBm_About(USBbuff) print("About: " + str(USBbuff.value, 'utf-8')) ret = USBpy.USBm_Version(USBbuff) print("Version: " + str(USBbuff.value, 'utf-8')) USBpy.USBm_InitPorts(0) USBpy.USBm_DirectionAInPullup(0) USBpy.USBm_ReadA(0,USBbuff) temp = ord(USBbuff[0]) & ~128 print(temp) line1a = Label(root, text=text1, fg='black', font=('OpenSymbol',16)) line2a = Label(root, text=text2, fg='black', font=('OpenSymbol',16)) line3a = Label(root, text=text3, fg='black', font=('OpenSymbol',16)) line4a = Label(root, text=text4, fg='black', font=('OpenSymbol',16)) line5a = Label(root, text=text5, fg='black', font=('OpenSymbol',16)) line6a = Label(root, text=text6, fg='black', font=('OpenSymbol',16)) line1a.grid(row=1,column=0,sticky='W') line2a.grid(row=2,column=0,sticky='W') line3a.grid(row=3,column=0,sticky='W') line4a.grid(row=4,column=0,sticky='W') line5a.grid(row=5,column=0,sticky='W') line6a.grid(row=6,column=0,sticky='W') line1b = Label(root, text=data1, fg='black', font=('OpenSymbol',16)) line2b = Label(root, text=data2, fg='black', font=('OpenSymbol',16)) line3b = Label(root, text=data3, fg='black', font=('OpenSymbol',16)) line4b = Label(root, text=data4, fg='black', font=('OpenSymbol',16)) line5b = Label(root, text=data5, fg='black', font=('OpenSymbol',16)) line6b = Label(root, text=data6, fg='black', font=('OpenSymbol',16)) line1b.grid(row=1,column=1,sticky='E') line2b.grid(row=2,column=1,sticky='E') line3b.grid(row=3,column=1,sticky='E') line4b.grid(row=4,column=1,sticky='E') line5b.grid(row=5,column=1,sticky='E') line6b.grid(row=6,column=1,sticky='E') def readPIR(): USBpy.USBm_ReadA(0,USBbuff) data6 = ord(USBbuff[0]) & 32 if data6 == 0: line6b['text'] = '' line6b['fg'] = 'black' if data6 == 32: line6b['text'] = 'Play!' line6b['fg'] = 'red' p.stop() p.play() root.after(500,readPIR) p = vlc.MediaPlayer("file:///pirmp3.mp3") mainloop() |