blob: 81b90b1f4d68cbf32115ceefac6ef69203b8ff02 [file] [log] [blame]
Yang Chen5e5fe362023-12-15 16:41:42 +08001#!/bin/bash
2
3set_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
23get_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}