button_manager.py monitors two momentary buttons connected to GPIO inputs. Each button supports a short press and a long press, allowing local recovery, WiFi reset or control actions without accessing the OliveYin Dashboard.
The reference configuration uses a five-second long-press threshold and starts commands asynchronously so GPIO event handling remains responsive.
The script currently defines the following actions:
| Button | Short press | Long press |
|---|---|---|
| P1 | Run /opt/custom-scripts/reset-esp32.sh |
Run /opt/custom-scripts/reset-wifi.sh |
| P2 | Run /opt/custom-scripts/custom-action.sh |
Run /opt/custom-scripts/shutdown.sh |
The reference script uses GPIO line offsets 18 and 19 from /dev/gpiochip0:
GPIO_CHIP = "/dev/gpiochip0"
BUTTON_P1 = 18
BUTTON_P2 = 19The inputs use the internal pull-up resistor. Connect each normally open momentary button between its assigned GPIO line and GND. Pressing a button produces a falling edge; releasing it produces a rising edge.
GPIO line offsets are not physical header pin numbers, but the GPIO reference: 18 = PA18 (pin 18), 19=PA19(pin16().
Install the Python GPIO bindings in the shared virtual environment.
The
gpiodpackage is already installed if the optional TFT display setup has been completed.
source /opt/custom-env/bin/activate
pip install gpiodInstall the button manager and its dependent scripts:
install -d -m 755 /opt/custom-scripts
install -m 755 custom-scripts/button_manager.py /opt/custom-scripts/button_manager.py
install -m 755 custom-scripts/reset_wifi.sh /opt/custom-scripts/reset-wifi.sh
install -m 755 custom-scripts/shutdown.sh /opt/custom-scripts/shutdown.sh
install -m 755 custom-scripts/shutdown.sh /opt/custom-scripts/custom-action.shReview the command definitions near the top of /opt/custom-scripts/button_manager.py before deployment. In particular, replace or provide the scripts used for the two short-press actions.
Install the supplied unit file:
install -m 644 systemd_scripts/system/button-manager.service \
/etc/systemd/system/button-manager.service
systemctl daemon-reload
systemctl enable --now button-manager.service
systemctl status button-manager.serviceInspect service logs while testing each press duration:
journalctl -u button-manager.service -fThe startup log reports the configured GPIO.
The P2 long-press action runs shutdown.sh. It atomically writes the SHUTDOWN_PROGRESS event ID to /run/sbc-serial-bridge/display-event, sends a Telegram notification when configured, waits three seconds, then invokes systemctl poweroff.
Ensure the telegram-send configuration is available to root, because button-manager.service runs as root.
The display manager shows SHUTDOWN_PROGRESS as a persistent shutdown screen, then clears the display and turns off the backlight when systemd stops the service.
