diff --git a/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/lib/systemd/system/button.service b/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/lib/systemd/system/button.service index 4f91a0c..c285e3d 100644 --- a/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/lib/systemd/system/button.service +++ b/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/lib/systemd/system/button.service @@ -1,11 +1,11 @@ [Unit] -Description=Button Reboot Service +Description=Button Service After=multi-user.target [Service] -ExecStart=/usr/local/bin/buttonservice.sh +ExecStart=/usr/local/bin/button.sh Restart=always -User=femto +User=root [Install] WantedBy=multi-user.target diff --git a/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/usr/local/bin/button.sh b/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/usr/local/bin/button.sh new file mode 100644 index 0000000..bc24626 --- /dev/null +++ b/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/usr/local/bin/button.sh @@ -0,0 +1,35 @@ +#!/bin/bash + +logger "Listening for button press on $DEVICE..." +evtest --grab /dev/input/event0 | while read line; do + # Check for key press event + if echo "$line" | grep -q "EV_KEY.*value 1"; then + start_time=$(date +%s) + fi + + # Check for key release event + if echo "$line" | grep -q "EV_KEY.*value 0"; then + duration=$(($(date +%s) - start_time)) + if [ $duration -lt 2 ]; then + ( for i in $(seq 1 3); do + echo 1 > /sys/class/gpio/gpio34/value; + sleep 0.25; + echo 0 > /sys/class/gpio/gpio34/value; + sleep 0.25; + done + ) & + wifi_status=$(cat /root/.portduino/default/prefs/config.proto | protoc --decode_raw | awk '/4 {/, /}/ {if ($1 == "1:") print $2}') + if [ "$wifi_status" -eq 1 ]; then + echo "$duration second button press detected. Toggling wifi off." + /usr/local/bin/updatemeshtastic.sh "--set network.wifi_enabled false" 10 "Button toggle wifi" + else + echo "$duration second button press detected. Toggling wifi on." + /usr/local/bin/updatemeshtastic.sh "--set network.wifi_enabled true" 10 "Button toggle wifi" + fi + else + echo "$duration second button press detected. Rebooting." + echo 1 > /sys/class/gpio/gpio34/value; + sudo reboot + fi + fi +done diff --git a/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/usr/local/bin/buttonservice.sh b/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/usr/local/bin/buttonservice.sh deleted file mode 100755 index d0d5d81..0000000 --- a/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/usr/local/bin/buttonservice.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/bash - -logger "$(date): Listening for button press on $DEVICE..." - -evtest --grab /dev/input/event0 | while read line; do - if echo $line | grep -q "EV_KEY.*value 1"; then - logger "Button pressed, triggering reboot..." - sudo reboot - fi -done