-
Notifications
You must be signed in to change notification settings - Fork 153
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
I added events handling for shutdown + reboot and a status LED. #20
base: master
Are you sure you want to change the base?
Conversation
…le timeouts and false positive
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@fabiosoft I love this idea. A status LED definitely belongs in this repo, but there are a few considerations.
First, the status LED should be optional (and default to disabled). Also, the user should be able to specify the pin for the LED. Many people who use this power button use it alongside other projects they're working on. If a user doesn't want the status LED it shouldn't have unintended side effects. I'll leave specific comments and ideas in the code.
@@ -2,6 +2,8 @@ | |||
|
|||
Scripts used in our official [Raspberry Pi power button guide](https://howchoo.com/g/mwnlytk3zmm/how-to-add-a-power-button-to-your-raspberry-pi). | |||
|
|||
I added events handling for shutdown + reboot and a status LED. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's remove this. If this gets merged, I can update the original power button guide to include instructions for adding the status LED.
# DEBUG | ||
# if __name__ == '__main__': | ||
# GPIO.setmode(GPIO.BCM) | ||
# GPIO.setup(PWR_BUTTON_GPIO, GPIO.IN) | ||
# pressed = False | ||
# while True: | ||
# # button is pressed when pin is LOW | ||
# if not GPIO.input(PWR_BUTTON_GPIO): | ||
# print("Button pressed!") | ||
# else: | ||
# print("Button not pressed!") | ||
# time.sleep(0.5) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These comments will need to be removed.
RST_BUTTON_GPIO = 4 # 9(GND) 7-GPIO4(+) | ||
LED_STATUS_GPIO = 18 # 6(GND) 12-GPIO18(+) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These two should be configurable. I'm thinking:
RST_BUTTON_GPIO = 4 # 9(GND) 7-GPIO4(+) | |
LED_STATUS_GPIO = 18 # 6(GND) 12-GPIO18(+) | |
RESET_BUTTON_GPIO = int(os.environ.get('RESET_BUTTON_GPIO', 4)) # 9(GND) 7-GPIO4(+) | |
LED_STATUS_GPIO = int(os.environ.get('LED_STATUS_GPIO', 18)) # 6(GND) 12-GPIO18(+) |
Not sure if casting to int is actually required, and we'd need to import os
above.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't thought through yet, what is the recommended way for the user to set these since this script runs at startup. Let me know if you have any alternative ideas here.
GPIO.setup(LED_STATUS_GPIO, GPIO.OUT) | ||
GPIO.setup(PWR_BUTTON_GPIO, GPIO.IN, pull_up_down=GPIO.PUD_UP) | ||
GPIO.setup(RST_BUTTON_GPIO, GPIO.IN, pull_up_down=GPIO.PUD_UP) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We'd need to figure out how to make LED
and RESET
conditional. POWER
can stay because I believe it HAS to use pin 3.
no loop needed.