Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

treehouses usb refactor (fixes #1580) #1581

Merged
merged 4 commits into from
Jul 3, 2020
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 55 additions & 45 deletions modules/usb.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,56 +14,66 @@ function usb {
command="$1"

if [[ $(detectrpi) =~ 'RPI3' ]]; then
if [ "$command" = "on" ]; then
/usr/local/bin/hub-ctrl -h 1 -P 2 -p 1
case $command in
"on")
/usr/local/bin/hub-ctrl -h 1 -P 2 -p 1

echo "usb ports turned on"
elif [ "$command" = "off" ]; then
/usr/local/bin/hub-ctrl -h 1 -P 2 -p
echo "usb ports turned on"
;;
"off")
/usr/local/bin/hub-ctrl -h 1 -P 2 -p

echo "usb ports turned off"
elif [ "$command" = "" ]; then
lsusb -t
else
echo "Error: unknown command"
usb_help
exit 1
fi
echo "usb ports turned off"
;;
"")
lsusb -t
;;
*)
echo "Error: unknown command"
usb_help
exit 1
;;
esac
elif [[ $(detectrpi) =~ 'RPI4' ]]; then
if [ "$command" = "on" ]; then
/usr/local/bin/hub-ctrl -h 2 -P 1 -p 1
/usr/local/bin/hub-ctrl -h 2 -P 2 -p 1
/usr/local/bin/hub-ctrl -h 2 -P 3 -p 1
/usr/local/bin/hub-ctrl -h 2 -P 4 -p 1
/usr/local/bin/hub-ctrl -h 1 -P 1 -p 1
case $command in
"on")
/usr/local/bin/hub-ctrl -h 2 -P 1 -p 1
/usr/local/bin/hub-ctrl -h 2 -P 2 -p 1
/usr/local/bin/hub-ctrl -h 2 -P 3 -p 1
/usr/local/bin/hub-ctrl -h 2 -P 4 -p 1
/usr/local/bin/hub-ctrl -h 1 -P 1 -p 1

echo "usb ports turned on"
elif [ "$command" = "off" ]; then
# check for connected ethernet
if [ "$(</sys/class/net/eth0/carrier)" = "1" ]; then
read -r -p "The ethernet port on your Raspberry Pi 4 is connected. Turning off usb power will interfere with your ethernet connection. Do you wish to continue? Y or N" yn
case $yn in
[Yy]*)
;;
[Nn]*)
exit
;;
esac
fi
/usr/local/bin/hub-ctrl -h 2 -P 1 -p
/usr/local/bin/hub-ctrl -h 2 -P 2 -p
/usr/local/bin/hub-ctrl -h 2 -P 3 -p
/usr/local/bin/hub-ctrl -h 2 -P 4 -p
/usr/local/bin/hub-ctrl -h 1 -P 1 -p
echo "usb ports turned on"
;;
"off")
# check for connected ethernet
if [ "$(</sys/class/net/eth0/carrier)" = "1" ]; then
read -r -p "The ethernet port on your Raspberry Pi 4 is connected. Turning off usb power will interfere with your ethernet connection. Do you wish to continue? Y or N" yn
case $yn in
[Yy]*)
;;
[Nn]*)
exit
;;
esac
fi
/usr/local/bin/hub-ctrl -h 2 -P 1 -p
/usr/local/bin/hub-ctrl -h 2 -P 2 -p
/usr/local/bin/hub-ctrl -h 2 -P 3 -p
/usr/local/bin/hub-ctrl -h 2 -P 4 -p
/usr/local/bin/hub-ctrl -h 1 -P 1 -p

echo "usb ports turned off"
elif [ "$command" = "" ]; then
lsusb -t
else
echo "Error: unknown command"
usb_help
exit 1
fi
echo "usb ports turned off"
;;
"")
lsusb -t
;;
*)
echo "Error: unknown command"
usb_help
exit 1
;;
esac
fi
}

Expand Down