如何检测Linux中用于充电的USB端口? [英] How can I detect a USB port being used for charging in Linux?

查看:304
本文介绍了如何检测Linux中用于充电的USB端口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Raspberry Pi 3 Model B上的USB端口通过USB磁性充电电缆为配件充电.我想检测何时插入电缆并从Pi上拔出 .

I'm using a USB port on the Raspberry Pi 3 Model B to charge an accessory via a USB magnetic charging cable. I want to detect when the cable is plugged in and removed from the Pi.

我一直在插拔电缆,寻找在Linux上检测到的任何痕迹.到目前为止,我已经尝试过:

I've been plugging in and removing this cable and looking for any traces of this being detected on Linux. So far, I've tried:

  • 通过udevadm monitor监视udev事件.
  • /var/log等中设置系统登录的尾巴.
  • /dev目录上运行inotify监视以查找新设备
  • /sys/bus/usb/devices中四处寻找线索
  • monitoring udev events by udevadm monitor.
  • tailing the system logs in /var/log etc.
  • running an inotify watch on the /dev directory for new devices
  • looking around in /sys/bus/usb/devices for any clues

是否可以检测到我插入/拔出的简单充电电缆?凭直觉,我认为没有(因为电缆仅用于充电,并且没有驱动程序),但是我观察到插入电缆时RPI闪烁其内置的LED红色.

Is it possible to detect my simple charging cable being inserted/removed? By intuition I would think no (since the cable is purely for charging, and doesn't have drivers), however I observe that the RPI flashes its builtin LED red when I insert the cable.

推荐答案

无需花费大量精力(硬件或黑客),

Without significant effort (hardware or hacks), No.

您观察到的红色LED闪烁是Pi的功率监视器,指示当电流开始流向附件时电压突然下降.该LED指示灯指示电压(电能)已短暂下降到稳定水平以下,并且可能导致系统不稳定.

The red LED flash you observe is the power monitor for the Pi indicating a sudden voltage drop as current begins to flow to your accessory. This LED indicates voltage (electrical energy) has briefly dropped below stable levels, and system instability may result.

由于连接纯粹是在充电(没有与Pi交换USB数据),因此操作系统不知道该设备已连接.您可以构建一个外部电流测量电路来检测外围设备的汲取功率,但是在电子堆栈交换中最好解决这个问题.

As the connection is purely charging (no USB data exchanged with the Pi) the operating system has no idea the device is connected. You could build an external current-measuring circuit to detect the peripheral drawing power, but such a question is better off in the electronics stack exchange.

这篇关于如何检测Linux中用于充电的USB端口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆