为了给树莓派添加像PC机一样的开机关机按键,找了很多资料,但都不是很理想。我就在想堂堂的树莓派,这么成熟的产品怎么会来这么基本的东西也没有呢,其实是我自己太孤陋寡闻了。我在想开机关机是和boot有关的,然后就是/boot下readme,在/boot/overlays/文件夹下的README中,终于找到了相关的设置,不说废话了,相关说明如下:
Name: gpio-shutdown
Info: Initiates a shutdown when GPIO pin changes. The given GPIO pin
is configured as an input key that generates KEY_POWER events.
This event is handled by systemd-logind by initiating a
shutdown. Systemd versions older than 225 need an udev rule
enable listening to the input device:
ACTION!="REMOVE", SUBSYSTEM=="input", KERNEL=="event*", \
SUBSYSTEMS=="platform", DRIVERS=="gpio-keys", \
ATTRS{keys}=="116", TAG+="power-switch"
This overlay only handles shutdown. After shutdown, the system
can be powered up again by driving GPIO3 low. The default
configuration uses GPIO3 with a pullup, so if you connect a
button between GPIO3 and GND (pin 5 and 6 on the 40-pin header),
you get a shutdown and power-up button.
Load: dtoverlay=gpio-shutdown,<param>=<val>
Params: gpio_pin GPIO pin to trigger on (default 3)
active_low When this is 1 (active low), a falling
edge generates a key down event and a
rising edge generates a key up event.
When this is 0 (active high), this is
reversed. The default is 1 (active low).
gpio_pull Desired pull-up/down state (off, down, up)
Default is "up".
Note that the default pin (GPIO3) has an
external pullup.
说的很明确了:
默认的开关机按钮是gpio3,默认是低电平关机,同时关机完,再使gpio3低电平就会开机。
这些在/boot/config.txt文件添加即可,如使用默认的,添加内容即为:
dtoverlay=gpio-shutdown