用python解决ipad在ubuntu上无法充电的问题

今天发现ipad在ubuntu上会一直显示not charging,搜了一下,发现有人写了一个ipad_charge程序:https://github.com/mkorenkov/ipad_charge/

看了一下源码,是通过发一个控制指令实现开始和停止充电的。

于是用pyusb(apt-get install python-usb)移植了一下:

#!/usr/bin/pythonimport usb.coreimport usb.utilimport usb.backend.libusb10import sys, getoptopts = getopt.getopt(sys.argv[1:],”,[‘off’])off = ‘off’ in opts[1]vendor_apple = 0x05acproduct_ipad1 = 0x129aproduct_ipad2 = 0x129f# find our devicedev = 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

Posted in 未分类

发表评论