Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- import usb.core
- import usb.util
- import sys
- import struct
- # source: http://androbuntu.googlecode.com/svn-history/r84/trunk/ubudroid-server/pycm19a/pycm19a.py
- def init_remotes(outEp):
- cr12init1 = [ 0x020, 0x034, 0x0cb, 0x058, 0x0a7 ]
- cr12init2 = [ 0x080, 0x001, 0x000, 0x020, 0x014 ]
- cr12init3 = [ 0x080, 0x001, 0x000, 0x000, 0x014, 0x024, 0x020, 0x020 ]
- writeRes = outEp.write(cr12init1)
- writeRes = outEp.write(cr12init2)
- writeRes = outEp.write(cr12init3)
- def sendData(lsdata,outEP):
- outEP.write(lsdata,10000)
- def getEndPointInfo(configs):
- for interface in configs:
- print "Configuration"
- for endpoint in interface:
- print "Endpoint"
- print "======================================"
- print "Direction = " + str(usb.util.endpoint_direction(endpoint.bEndpointAddress))
- print "Type = " + str(usb.util.endpoint_type(endpoint.bEndpointAddress))
- print endpoint.bLength
- print endpoint.bDescriptorType
- print endpoint.bmAttributes
- print endpoint.wMaxPacketSize
- print endpoint.bInterval
- print endpoint.bRefresh
- print endpoint.bSynchAddress
- dev = usb.core.find(idVendor=0x10c4, idProduct=0x8668)
- if dev is None:
- print "USBDevice not found"
- else:
- print "Found RF module"
- if dev.is_kernel_driver_active(0):
- print "detaching kernel driver"
- dev.detach_kernel_driver(0)
- dev.set_configuration()
- cfg = dev.get_active_configuration()#this thing only has one config
- for i in cfg:
- print i.bInterfaceNumber
- interface_number = i.bInterfaceNumber
- alternate_settting = usb.control.get_interface(dev, interface_number)
- intf = usb.util.find_descriptor(cfg, bInterfaceNumber = interface_number, bAlternateSetting = alternate_settting)
- ep_tx = usb.util.find_descriptor(intf,
- # match the first OUT endpoint
- custom_match = \
- lambda e: \
- usb.util.endpoint_direction(e.bEndpointAddress) == \
- usb.util.ENDPOINT_OUT
- )
- ep_rx = usb.util.find_descriptor(intf,
- # match the first OUT endpoint
- custom_match = \
- lambda e: \
- usb.util.endpoint_direction(e.bEndpointAddress) == \
- usb.util.ENDPOINT_IN
- )
- assert ep_tx is not None
- assert ep_rx is not None
- #getEndPointInfo(cfg)
- init_remotes(ep_tx)
- while True:
- ep_tx.write([0x02,0x02, 0x07, 0x20])
- init_remotes(ep_tx)
- # try:
- # data = ep_rx.read(1)
- # print data
- # time.sleep(0.1)
- # except usb.USBError:
- # print "."
- # pass
- # if len(line)>0:
- # sendData([ 0x080, 0x001, 0x000, 0x000, 0x014, 0x024, 0x020, 0x020 ],ep_rx)
- #
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement