usb keyboard disconnect fix ubuntu

I have a G15 gaming keyboard and a mouse plugged into the USB hub that is built in.

Every so often the G15 LCD starts flickering very fast and the only remedy is to unplug the USB lead from the PC and reconnect it.

I have permanently fixed it using the following method:

Create the file /bin/monitorusb
[code]#!/bin/bash
function strstr() {
echo $1 | grep --quiet "$2"
}

monfile="/var/log/syslog"

tail -f $monfile | while read line; do
if strstr "${line}" "can't reset device,*input0, status -32"; then
sudo /bin/usb_reset
fi
done[/code]
and set it to executable (chmod +x /bin/monitorusb)

Create the file /bin/usb_reset
[code]#!/bin/bash
# This script must be run as root to work. For desktop launcher, use command "gksudo /bin/usb_reset".

# Stop USB
modprobe -r usbhid
wait

# Start USB
modprobe usbhid

exit 0[/code]
and set it to executable (chmod +x /bin/usb_reset)

Add the following to root’s cron (sudo crontab -e)
[code]
@reboot /bin/monitorusb
[/code]

Run the program (press alt-f2, type in monitorusb). It is non-interactive and will happily sit in the background until it is needed, at which point it will silently disable the USB HID (human interface device) subsystem and immediately re-enable it, fixing the problem before you even notice it has happened.

As always, comments are always welcomed :)

This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

CommentLuv badge