Skip to content

Commit

Permalink
treehouses usb refactor (fixes #1580) (#1581)
Browse files Browse the repository at this point in the history
Co-authored-by: dogi <dogi@users.noreply.github.com>
  • Loading branch information
sarahrams and dogi authored Jul 3, 2020
1 parent c968584 commit 0890158
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 46 deletions.
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@treehouses/cli",
"version": "1.22.47",
"version": "1.22.48",
"remote": "2346",
"description": "Thin command-line interface for Raspberry Pi low level configuration.",
"main": "cli.sh",
Expand Down

0 comments on commit 0890158

Please sign in to comment.