24

假设我有一个 USB 供电的 LED 灯,通过 USB OTG 适配器连接到运行 Android 4.0.3 的 Toshiba Excite 10 平板电脑,该平板电脑提供电源。

我想通过应用程序以编程方式打开和关闭 USB OTG 主机端口的电源引脚。(理想情况下没有root,但我会尽我所能)。有任何想法吗?

4

2 回答 2

4

您必须对 /sys 目录具有写权限。生根使该过程非常容易。只需root您的设备并发出正确的回显命令即可切换内核状态位,例如:

String[] command = { "/system/bin/sh", "-c", "echo xxx > /sys/bus/usb/devices/usb3/power/level", };
Runtime.getRuntime().exec(command);

另一种方法是使用libusb,为切断电源的功能挖掘库。您可以使用 android.hardware.usb.UsbManager 为 libusb 请求适当的权限。

于 2015-07-13T03:28:39.487 回答
1

As I know from here https://askubuntu.com/questions/342061/power-on-off-usb-ports "All of the previous answers talk about a USB suspend mechanism, i.e. a "logical power-off", they will never physically cut the VBUS +5V from the USB port.".

Maybe a hardware solution is bad idea, but I can advise you to use MOSFET transistor with programmed Atmega8U4 chip on PCB, that is programmed to cutoff power to led lamp.

于 2017-06-14T15:58:57.517 回答