X728 Shutdown Options | Geekworm

X728 Shutdown Options


  • Hi,  I have recently brought the X728 board for my raspberry Pi, and first of all I have to say it is brilliant!

    It's the only UPS I've tested that actually works correctly.

    I would however like some help with the shut down options.

    How can I change the script so that when you press the external button it shutsdown and powers off the pi and disconnects the battery with one press (and turns back on with one press)?

    I.e:

     

    It must be something to do with this script?

    #x728 Powering on /reboot /full shutdown through hardware
    #!/bin/bash

        sudo sed -e '/shutdown/ s/^#*/#/' -i /etc/rc.local

        echo '#!/bin/bash
    SHUTDOWN=5
    REBOOTPULSEMINIMUM=200
    REBOOTPULSEMAXIMUM=600
    echo "$SHUTDOWN" > /sys/class/gpio/export
    echo "in" > /sys/class/gpio/gpio$SHUTDOWN/direction
    BOOT=12
    echo "$BOOT" > /sys/class/gpio/export
    echo "out" > /sys/class/gpio/gpio$BOOT/direction
    echo "1" > /sys/class/gpio/gpio$BOOT/value
    echo "X728 Shutting down..."
    while [ 1 ]; do
      shutdownSignal=$(cat /sys/class/gpio/gpio$SHUTDOWN/value)
      if [ $shutdownSignal = 0 ]; then
        /bin/sleep 0.2
      else  
        pulseStart=$(date +%s%N | cut -b1-13)
        while [ $shutdownSignal = 1 ]; do
          /bin/sleep 0.02
          if [ $(($(date +%s%N | cut -b1-13)-$pulseStart)) -gt $REBOOTPULSEMAXIMUM ]; then
            echo "X728 Shutting down", SHUTDOWN, ", halting Rpi ..."
            sudo poweroff
            exit
          fi
          shutdownSignal=$(cat /sys/class/gpio/gpio$SHUTDOWN/value)
        done
        if [ $(($(date +%s%N | cut -b1-13)-$pulseStart)) -gt $REBOOTPULSEMINIMUM ]; then 
          echo "X728 Rebooting", SHUTDOWN, ", recycling Rpi ..."
          sudo reboot
          exit
        fi
      fi
    done' > /etc/x728pwr.sh
    sudo chmod +x /etc/x728pwr.sh
    sudo sed -i '$ i /etc/x728pwr.sh &' /etc/rc.local 


    #X728 full shutdown through Software
    #!/bin/bash

        sudo sed -e '/button/ s/^#*/#/' -i /etc/rc.local

        echo '#!/bin/bash
    BUTTON=13
    echo "$BUTTON" > /sys/class/gpio/export;
    echo "out" > /sys/class/gpio/gpio$BUTTON/direction
    echo "1" > /sys/class/gpio/gpio$BUTTON/value
    SLEEP=${1:-4}
    re='^[0-9\.]+$'
    if ! [[ $SLEEP =~ $re ]] ; then
       echo "error: sleep time not a number" >&2; exit 1
    fi
    echo "X728 Shutting down..."
    /bin/sleep $SLEEP
    #restore GPIO 13
    echo "0" > /sys/class/gpio/gpio$BUTTON/value
    ' > /usr/local/bin/x728softsd.sh
    sudo chmod +x /usr/local/bin/x728softsd.sh

     



  • @Aiden Ralph 

    Hi, Thanks

     

    The press time is related to the firmware of the MCU,  The purpose of pressing 3 seconds is to prevent accidental shutdown


  • Detaching the battery after shutdown requires a tweak that is specific to the hardware configuration and battery geometry dash lite attachment method of the X728 board.  The three-second button has an anti-shutdown safety feature.


  • lease be cautious when modifying scripts related to power management, as improper changes can potentially lead to data corruption or other issues. Make sure to back up your data and configurations before proceeding.

    1. Identify the Button's GPIO Pin: Determine which GPIO pin the external button is connected to on the X728 board. This information should be available in the product documentation or on the board itself.

    2. Create or Modify a Shutdown Script:

      • You can create a custom script to handle the shutdown and power-off sequence. Here's a basic example using Python:
        python
         
        #!/usr/bin/env python import RPi.GPIO as GPIO import os import time # Set the GPIO pin for the external button button_pin = 18 # Replace with the actual GPIO pin GPIO.setmode(GPIO.BCM) GPIO.setup(button_pin, GPIO.IN, pull_up_down=GPIO.PUD_UP) try: while True: input_state = GPIO.input(button_pin) if input_state == False: # Button is pressed os.system("sudo poweroff") time.sleep(5) # Wait for the shutdown to complete os.system("sudo systemctl poweroff -i") time.sleep(0.2) except KeyboardInterrupt: pass finally: GPIO.cleanup()
        Save this script to a file (e.g., shutdown_button.py) and make it executable using chmod +x shutdown_button.py.

    You can also check mac show hidden folders option for mac os users, the best option.


Please login to reply this topic!
BACK TO TOP