/ 铃儿响叮当 / usb鼠标唤醒系统

usb鼠标唤醒系统

2014-02-11 posted in [day-to-day]

背景

想要支持这个功能,发现当鼠标插入后你会发现下面的wakeup文件为’disabled’。

/sys/bus/usb/devices/*/power/wakeup

所以,如果想要启用usb鼠标唤醒,就得把它设置为’enabled’。

所需解决的问题一是怎么判断插入的是usb鼠标设备,二是如何更改wakeup值, 尝试了一通,单纯的通过udev规则文件来解决这两个问题,检测到usb鼠标的节点的父节点含有wakeup。

udev rules

$ cat 65-persistent-usb-mouse-wakeup.rules
ACTION=="add", SUBSYSTEM=="usb", DRIVERS=="usbhid", ATTR{bInterfaceProtocol}=="02", PROGRAM="udev-usb-mouse-wakeup %S%p"

scripts

$ cat udev-usb-mouse-wakeup
# udev-usb-mouse-wakeup used to enable the usb mouse to wake-up from suspend.

USB_MOUSE_DEV_PATH=$1

if [ -n $USB_MOUSE_DEV_PATH ] ; then
        PARENT_DEV_PATH_POWER=${USB_MOUSE_DEV_PATH%/*}/power/wakeup
        if [ -e $PARENT_DEV_PATH_POWER ] ; then
                # ignore it when it's already enabled
                [ "$(cat $PARENT_DEV_PATH_POWER)" = "disabled" ] && echo "enabled" > $PARENT_DEV_PATH_POWER
        fi
fi

Links

USB设备标准的定义,可以判断usb mouse

http://www.usb.org/developers/devclass_docs/HID1_11.pdf