From d01e49729419b1e76869417fdaf7e83f06d47ba9 Mon Sep 17 00:00:00 2001 From: nagumii Date: Mon, 23 Dec 2024 17:04:05 +0200 Subject: [PATCH 1/2] Expand button functionality Short press now toggles wifi. LED will flash 3 times to show the command was received. - wifi will toggle within 30 seconds. 2 second press reboots. LED will turn on to show the command was received. --- .../lib/systemd/system/button.service | 6 +++--- .../out/rootfs_uclibc_rv1106/usr/local/bin/button.sh | 8 ++++++++ .../usr/local/bin/buttonservice.sh | 10 ---------- 3 files changed, 11 insertions(+), 13 deletions(-) create mode 100644 foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/usr/local/bin/button.sh delete mode 100755 foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/usr/local/bin/buttonservice.sh 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..efb817b --- /dev/null +++ b/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/usr/local/bin/button.sh @@ -0,0 +1,8 @@ + 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 From b12f3f27bdade1065673122095b7b555512a6183 Mon Sep 17 00:00:00 2001 From: nagumii Date: Mon, 23 Dec 2024 17:04:40 +0200 Subject: [PATCH 2/2] Update button.sh --- .../usr/local/bin/button.sh | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) 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 index efb817b..bc24626 100644 --- a/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/usr/local/bin/button.sh +++ b/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/usr/local/bin/button.sh @@ -1,3 +1,30 @@ +#!/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."