From 9c1a5511c68e95557e29eaa2e1136863d9ee5c47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrgen=20Weigert?= Date: Sat, 25 May 2019 08:54:07 +0200 Subject: [PATCH] idea how to switch off usb power. does not work for me. The plan was to make the badge display its text by switching off power. --- usb-power.sh | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 usb-power.sh diff --git a/usb-power.sh b/usb-power.sh new file mode 100644 index 0000000..1a9000f --- /dev/null +++ b/usb-power.sh @@ -0,0 +1,31 @@ +#!/bin/bash +############################################################### +# It will power on/off a usb device based on a string found in dmesg output. +# +# Example for the led-badge: +# +# usb-power.sh off "Product: LS32 Custm HID" +# - This code does not work with a Lenovo-T440s running Mint. Not sure why. +############################################################### +if [[ $2 == "" ]]; then + echo "Usage: $0 [on|off] DMESG_STRING" + exit; +fi +USB_DEV=$(dmesg | grep -o "usb .*: $2" | tail -n 1 | awk '{print $2}' | sed 's/://') +if [[ $USB_DEV == "" ]]; then + echo "Device not found"; + exit; +fi + +echo using USB_DEV=$USB_DEV + +if [[ $1 == "on" ]]; then + echo "2000" > /sys/bus/usb/devices/$USB_DEV/power/autosuspend_delay_ms + echo "on" > /sys/bus/usb/devices/$USB_DEV/power/control +elif [[ $1 == "off" ]]; then + echo "0" > /sys/bus/usb/devices/$USB_DEV/power/autosuspend_delay_ms + echo "auto" > /sys/bus/usb/devices/$USB_DEV/power/control +else + echo "Unknown action: $1" + exit; +fi