gpio: Fix GPIO handling for modern openwrt, handle sharkjack-cable

detection, temporarily don't halt on battery conditions
master
Mike Kershaw / Dragorn 2023-08-02 16:36:25 -04:00
parent 9a6e5984a8
commit c2f279a8d6
3 changed files with 22 additions and 6 deletions

View File

@ -1,5 +1,10 @@
#!/bin/sh #!/bin/sh
OFFSET=416
GPIO40=$((40 + $OFFSET))
GPIO41=$((41 + $OFFSET))
setup() { setup() {
echo "${1}" > /sys/class/gpio/export 2>/dev/null echo "${1}" > /sys/class/gpio/export 2>/dev/null
echo in > "/sys/class/gpio/gpio${1}/direction" 2>/dev/null echo in > "/sys/class/gpio/gpio${1}/direction" 2>/dev/null
@ -13,11 +18,13 @@ check_gpio() {
echo "${state}" echo "${state}"
} }
gpio40=$(check_gpio 40) gpio40=$(check_gpio $GPIO40)
gpio41=$(check_gpio 41) gpio41=$(check_gpio $GPIO41)
if [ "${gpio40}" -eq "0" ] && [ "${gpio41}" -eq "0" ]; then if [ "${gpio40}" -eq "0" ] && [ "${gpio41}" -eq "0" ]; then
echo "discharging" echo "discharging"
elif [ "${gpio40}" -eq "1" ] && [ "${gpio41}" -eq "1" ]; then
echo "cable"
elif [ "${gpio40}" -eq "0" ]; then elif [ "${gpio40}" -eq "0" ]; then
echo "full" echo "full"
elif [ "${gpio41}" -eq "0" ]; then elif [ "${gpio41}" -eq "0" ]; then

View File

@ -1,5 +1,10 @@
#!/bin/sh #!/bin/sh
OFFSET=416
GPIO0=$(($OFFSET))
GPIO2=$((2 + $OFFSET))
setup() { setup() {
echo "${1}" > /sys/class/gpio/export echo "${1}" > /sys/class/gpio/export
echo in > "/sys/class/gpio/gpio${1}/direction" echo in > "/sys/class/gpio/gpio${1}/direction"
@ -13,8 +18,8 @@ check_gpio() {
echo "${state}" echo "${state}"
} }
gpio0=$(check_gpio 0) gpio0=$(check_gpio $GPIO0)
gpio2=$(check_gpio 2) gpio2=$(check_gpio $GPIO2)
if [ "${gpio0}" -eq "0" ] && [ "${gpio2}" -eq "0" ]; then if [ "${gpio0}" -eq "0" ] && [ "${gpio2}" -eq "0" ]; then
echo "switch1" echo "switch1"

View File

@ -192,11 +192,15 @@ enter_idle_mode() {
"full") "full")
pgrep LED > /dev/null || /usr/bin/LED B pgrep LED > /dev/null || /usr/bin/LED B
;; ;;
"cable")
# Do nothing with battery if we're a sharkjack cable platform
;;
*) *)
pgrep LED > /dev/null || /usr/bin/LED Y SLOW pgrep LED > /dev/null || /usr/bin/LED Y SLOW
if [ "${MODE}" = "OFF" ]; then if [ "${MODE}" = "OFF" ]; then
sleep 2 #sleep 2
halt #halt
$LOG "battery state other ($BATTERY_STATE) would halt"
fi fi
;; ;;
esac esac