ps4eye_init.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 import usb.core
00003 import usb.util
00004 import os
00005 import sys
00006 
00007 # check if initialized device already exists
00008 dev = usb.core.find(idVendor=0x05a9, idProduct=0x058a)
00009 if dev is not None:
00010     print('PS4 camera already initialized')
00011     sys.exit()
00012 
00013 # find uninitialized device
00014 dev = usb.core.find(idVendor=0x05a9, idProduct=0x0580)
00015 if dev is None:
00016     print('PS4 camera not found')
00017     sys.exit()
00018 
00019 # set the active configuration. With no arguments, the first
00020 # configuration will be the active one
00021 dev.set_configuration()
00022 
00023 # helper function for chunking a file
00024 def read_chunks(infile, chunk_size):
00025     while True:
00026         chunk = infile.read(chunk_size)
00027         if chunk:
00028             yield chunk
00029         else:
00030             return
00031 
00032 chunk_size=512
00033 index=0x14
00034 value=0
00035 script_dir=os.path.abspath(os.path.dirname(__file__))
00036 firmware=open(script_dir + "/firmware.bin","rb")
00037 
00038 # transfer 512b chunks of the firmware
00039 for chunk in read_chunks(firmware, chunk_size):
00040     ret = dev.ctrl_transfer(0x40, 0x0, value, index, chunk)
00041     value+=chunk_size
00042     if value>=65536:
00043         value=0
00044         index+=1
00045     if len(chunk)!=ret:
00046         print("sent %d/%d bytes" % (ret,len(chunk)))
00047 
00048 # command reboots device with new firmware and product id
00049 try:
00050     ret = dev.ctrl_transfer(0x40, 0x0, 0x2200, 0x8018, [0x5b])
00051 except:
00052     print('PS4 camera firmware uploaded and device reset')


ps4eye
Author(s): Ron Tajima
autogenerated on Thu Aug 27 2015 14:35:08