mirror of
https://github.com/femtofox/femtofox.git
synced 2026-12-04 22:00:21 -05:00
commit
e167144222
3 changed files with 38 additions and 13 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
@ -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
|
||||
Loading…
Add table
Add a link
Reference in a new issue