2016年6月25日 星期六

reset USB device when resume/wakeup my desktop with linux mint 17 (ubuntu 14.04)

Cause I've replace my desktop before, from Homebuilt computer that old than 8-year
To brix mini computer, and I've solve the monitor VH226H HDMI source could not sleep issue by replace it to VGA source...

Now I have a computer that can sleep/hibernation and wakeup/resume
but following issue is, I've plug a DVB-T usb dongle on my Desktop, and I'm using Me-TV 1.4 as my TV player,
Me-TV 1.4 turn into server and client architecture, so server application will stay in background, keep open device

If computer sleep or hibernation, it wake up or resume quickly, but DVB-T dongle might be work abnormal, maybe the driver does not implement relative power management function? I don't know:~

I need replug my DVB-T dongle , kill Me-TV server manually to make it work
Hm.... Try to make it easier:)

put following code to /usr/lib/pm-utils/sleep.d, save as 99ZZ_my_script, and make it executable
it could kill me-tv both server and client when sleep,
and when you wake up, find the usb port number, force it reset

#!/bin/sh
# resume me-tv-client if exist

case "$1" in
hibernate|suspend)
#echo "7 blink" >/proc/acpi/ibm/led
killall me-tv-server
killall me-tv-client
;;
thaw|resume)
for X in /sys/bus/usb/devices/*; do
#if [ "$VID" == "$(cat $X/idVendor 2>/dev/null)" -a "$PID" == "$(cat $X/idProduct 2>/dev/null)" ]
if [ "MDTV Receiver" = "$(cat $X/product 2>/dev/null)" ]
then
Port_Number=`echo $X | awk -F / '{print $NF}'`
#echo "Found $Port_Number"
echo $Port_Number > /sys/bus/usb/drivers/usb/unbind
sleep 1
echo $Port_Number > /sys/bus/usb/drivers/usb/bind
break
fi
done
;;
*) exit $NA
;;
esac

exit 0



refer:
  1.  Run Script on Wakeup?
  2.  POWER OFF AND ON USB DEVICE IN LINUX (UBUNTU)

沒有留言:

張貼留言

來推薦一下VPS Racknerd

網路上有蠻多這間VPS的推薦,不過大多是賺傭金的 推薦的點不外乎是便宜,然後中國那邊很多拿來當VPN跳板主機 我當初也是無聊租了一台來玩 後來實際上用起來覺得還可以 但是有幾個小地方當初租的時候沒注意到 就來分享一下,順便分享我的推薦連結 XDDD Racknerd有很多優惠方案...