Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implementing button press time to trigger manual shutdown #7

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions Software/wittypi/daemon.sh
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,34 @@ while true; do
clear_alarm_flags
else
# not shutdown by alarm
# wait for button to be pressed for SHUTDOWN_HOLD_TIME to prevent single accidental button shutdown
# by default this is set to 2 seconds, can be changed in utilities.sh
counter=0
while [ $counter -lt $SHUTDOWN_HOLD_TIME ]; do # increase this value if it needs more time
if [ $(gpio -g read $HALT_PIN) == '1' ] ; then
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, that the 1 will be correct?
After my Debug-Session of the correct value: while true; do gpio -g read 4; sleep 1; done I will get a 0 back, if I press the button. The default value of the $HALT_PIN is 1

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I test my changes on Raspbian OS (Buster, Bullseye) and now it works.
Please replace the 1 with a 0.

For a quick check, you can ask the GPIO-PIN 4:
while true; do gpio -g read 4; sleep 1; done

counter=$(($counter+1))
else
counter=0
continue 2
fi
sleep 1
done
break;
fi
else
# power switch can still work without RTC
# wait for button to be pressed for SHUTDOWN_HOLD_TIME to prevent single accidental button shutdown
# by default this is set to 2 seconds, can be changed in utilities.sh
counter=0
while [ $counter -lt $SHUTDOWN_HOLD_TIME ]; do # increase this value if it needs more time
if [ $(gpio -g read $HALT_PIN) == '1' ] ; then
counter=$(($counter+1))
else
counter=0
continue 2
fi
sleep 1
done
break;
fi
done
Expand Down
2 changes: 1 addition & 1 deletion Software/wittypi/utilities.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ if [ -z ${I2C_RTC_ADDRESS+x} ]; then

readonly HALT_PIN=4 # halt by GPIO-4 (BCM naming)
readonly SYSUP_PIN=17 # output SYS_UP signal on GPIO-17 (BCM naming)

readonly SHUTDOWN_HOLD_TIME=2 # hold power button for N seconds to trigger manual shutdown
readonly INTERNET_SERVER='http://google.com' # check network accessibility and get network time
fi

Expand Down