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

Conversation

ubidefeo
Copy link

Manual shutdown currently happens at first button tap, which could be accidental.
This patch implements a configurable time for the button to be held down before the shutdown script is triggered.
Hope you'll want to merge it, it's very useful :)

It would also be great if you could add this parameter to the configuration utility and save it to the Microcontroller's EEPROM so users could choose to have 1, 2, 3, 4 seconds to shut down manually, since 5 is the circuit's force shutdown time.

Thank you for your attention
u.

@ubidefeo
Copy link
Author

ubidefeo commented May 7, 2021

@uugear
pinging your again about this PR :)

@lgremme
Copy link

lgremme commented Nov 21, 2021

Today I test your PR with our Debian Package it won't work.
I press 3 Seconds the Power-Button, but the Pi doesn't power off.

Currently we revert the changes.

@ubidefeo
Copy link
Author

hi @lgremme
It works on Raspberry Pi OS.
You could try and patch my changes to implement it, it's a really nice feature :)

Unfortunately @uugear doesn't seem to respond to PRs at all.
Too bad, because the products are nice

@lgremme
Copy link

lgremme commented Nov 21, 2021

@ubidefeo : I patch your changes into our Debian Package for Raspberry Pi OS (Rasbian), Ubuntu, Debian, ...

Without your changes, we can power off via the power button. With your changes, we can't power off in the default (pressing 2 Seconds the power button).

We used the current version of the WittyPi3 (v1.13).

I add some Debug code for your lines. We are using only the first loop (line 155-166). The second loop (l. 171-182) doesn't work. I add an echo for debugging and additionally a set -x and set +x

I get for a short press (< 2 Sec) and a long press (> 2 Sec) this loglines:

Nov 21 11:22:15 hostname wittypi-daemon[1560]: + echo 'not shutdown by alarm - hint'
Nov 21 11:22:15 hostname wittypi-daemon[1560]: not shutdown by alarm - hint
Nov 21 11:22:15 hostname wittypi-daemon[1560]: + counter=0
Nov 21 11:22:15 hostname wittypi-daemon[1560]: + '[' 0 -lt 2 ']'
Nov 21 11:22:15 hostname wittypi-daemon[2251]: ++ gpio -g read 4
Nov 21 11:22:15 hostname wittypi-daemon[1560]: + '[' 0 == 1 ']'
Nov 21 11:22:15 hostname wittypi-daemon[1560]: + counter=0
Nov 21 11:22:15 hostname wittypi-daemon[1560]: + set +x
Nov 21 11:26:41 hostname wittypi-daemon[1560]: + echo 'not shutdown by alarm - hint'
Nov 21 11:26:41 hostname wittypi-daemon[1560]: not shutdown by alarm - hint
Nov 21 11:26:41 hostname wittypi-daemon[1560]: + counter=0
Nov 21 11:26:41 hostname wittypi-daemon[1560]: + '[' 0 -lt 2 ']'
Nov 21 11:26:41 hostname wittypi-daemon[2313]: ++ gpio -g read 4
Nov 21 11:26:41 hostname wittypi-daemon[1560]: + '[' 0 == 1 ']'
Nov 21 11:26:41 hostname wittypi-daemon[1560]: + counter=0
Nov 21 11:26:41 hostname wittypi-daemon[1560]: + set +x

# 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants