今天发现ipad在Ubuntu上会一直显示Not Charging,搜了一下,发现有人写了一个ipad_charge程序:https://github.com/mkorenkov/ipad_charge/
看了一下源码,是通过发一个控制指令实现开始和停止充电的。
于是用pyusb(apt-get install Python-usb)移植了一下:
#!/usr/bin/python
import usb.core
import usb.util
import usb.backend.libusb10
import sys, getopt
opts = getopt.getopt(sys.argv[1:],”,[‘off‘])
off = ‘off‘ in opts[1]
VENDOR_APPLE = 0x05ac
PRODUCT_IPAD1 = 0x129a
PRODUCT_IPAD2 = 0x129f
# find our device
dev = usb.core.find(idVendor=VENDOR_APPLE, idProduct=PRODUCT_IPAD1)
if not dev:
dev = usb.core.find(idVendor=VENDOR_APPLE, idProduct=PRODUCT_IPAD2)
if dev is None:
raise ValueError(‘Device not found‘)
usb.util.claim_interface(dev, 0)
dev.ctrl_transfer(usb.util.CTRL_TYPE_VENDOR|usb.util.CTRL_OUT, 0x40, 0x6400, 0x6400 if not off else 0, None, 2000)
usb.util.release_interface(dev, 0)
充电:
python ipad_charge.py
停止充电:
python ipad_charge.py off