I added events handling for shutdown + reboot and a status LED.#20
I added events handling for shutdown + reboot and a status LED.#20fabiosoft wants to merge 2 commits intoHowchoo:masterfrom
Conversation
…le timeouts and false positive
josephtyler
left a comment
There was a problem hiding this comment.
@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.
|
|
||
| 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.
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.
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.
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.
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.
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.