blob: b4a6988235e95a72ab7aa0e692c964637e724382 [file] [log] [blame]
#!/bin/bash -e
#
# Control step motor rotate of sled
# shellcheck source=meta-facebook/meta-bletchley/recipes-bletchley/plat-tools/files/bletchley-common-functions
source /usr/libexec/bletchley-common-functions
#######################################
# Setting step motor control pins to start/stop motor
# Arguments:
# 1. SLED NUMBER
# 2. Value of STBY RESET PIN
# 3. Value of ENABLE PIN
# 4. Value of DIRECTION PIN
# 5. Value of Motor Driver VREF PIN
#######################################
function set_motor() {
STBY_PIN="SLED${1}_MD_STBY_RESET"
EN_PIN="SLED${1}_MD_IOEXP_EN_FAULT"
DIR_PIN="SLED${1}_MD_DIR"
VREF_PIN="SLED${1}_MD_REF_PWM"
set_gpio "$STBY_PIN" "$2"
set_gpio "$EN_PIN" "$3"
set_gpio "$DIR_PIN" "$4"
set_gpio "$VREF_PIN" "$5"
}
function show_usage(){
echo "Usage: motor-ctrl [sled1 | sled2 | sled3 | sled4 | sled5 | sled6] [f r s]"
echo " f : Step Motor go forward"
echo " r : Step Motor go reverse"
echo " s : Step Motor stop "
}
if [ $# -ne 2 ]; then
show_usage
exit 1;
fi
if [[ "$1" =~ ^(sled[1-6]{1})$ ]]; then
SLED=$1
SLED_NUM=${SLED:4}
ACTION=$2
else
echo "invalid sled name: $1"
exit 1;
fi
#Check if sled is present
if ! is_sled_present "${SLED_NUM}"; then
echo "${SLED} is not present!"
exit 1
fi
if [[ "$ACTION" == "s" ]]; then
echo "stop motor"
set_motor "$SLED_NUM" 1 0 0 1
elif [[ "$ACTION" == "f" ]];then
echo "start motor, direction:forward"
set_motor "$SLED_NUM" 1 1 0 0
elif [[ "$ACTION" == "r" ]];then
echo "start motor, direction:reverse"
set_motor "$SLED_NUM" 1 1 1 0
else
echo "Error: Unknown action!"
exit 1
fi
exit 0