Yang Chen | 5e5fe36 | 2023-12-15 16:41:42 +0800 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
| 3 | set_gpio() |
| 4 | { |
| 5 | local NET_NAME=$1 |
| 6 | local OUT_VAL=$2 |
| 7 | mapfile -t -d " " GPIO_INFO < <(gpiofind "$NET_NAME") |
| 8 | if [ "${#GPIO_INFO[@]}" -ne 2 ]; then |
| 9 | echo "set_gpio: can not find gpio, $NET_NAME" |
| 10 | return 1 |
| 11 | fi |
| 12 | |
| 13 | echo -n "set_gpio: set $NET_NAME = $OUT_VAL" |
| 14 | if ! gpioset "${GPIO_INFO[0]}" "${GPIO_INFO[1]%$'\n'}"="$OUT_VAL"; then |
| 15 | echo " failed" |
| 16 | return 1 |
| 17 | fi |
| 18 | |
| 19 | echo " success" |
| 20 | return 0 |
| 21 | } |
| 22 | |
| 23 | get_gpio() |
| 24 | { |
| 25 | local NET_NAME=$1 |
| 26 | local RET_VAL |
| 27 | |
| 28 | mapfile -t -d " " GPIO_INFO < <(gpiofind "${NET_NAME}") |
| 29 | if [ "${#GPIO_INFO[@]}" -ne 2 ]; then |
| 30 | logger -p user.info "get_gpio: can not find gpio, ${NET_NAME}" |
| 31 | return 1 |
| 32 | fi |
| 33 | if ! RET_VAL=$(gpioget "${GPIO_INFO[0]}" "${GPIO_INFO[1]%$'\n'}") ; then |
| 34 | logger -p user.info "get_gpio: get ${NET_NAME} failed" |
| 35 | return 1 |
| 36 | fi |
| 37 | logger -p user.info "get_gpio: get ${NET_NAME} = ${RET_VAL}" |
| 38 | echo "${RET_VAL}" |
| 39 | return 0 |
| 40 | } |