Ignore:
Timestamp:
Aug 14, 2025, 4:59:15 AM (4 months ago)
Author:
Waldemar Brodkorb <wbx@…>
Branches:
freewrt_2_0
Children:
28ae594
Parents:
d860f20
Message:

fix failsafe mode, use modern buttons and leds support

File:
1 edited

Legend:

Unmodified
Added
Removed
  • package/base-files/files/sbin/failsafe

    rd860f20 r03abecc  
    11#!/bin/sh
    22
     3# CONFIGURE
     4EVENT_DEV="/dev/input/event0"    # change if your reset button is on a different event device
     5KEY_CODE="KEY_RESTART"           # as reported by evtest
     6LED_PATH="/sys/class/leds/bcm47xx:green:dmz"  # adjust to your LED name from ls /sys/class/leds
     7FAILSAFE_IP="192.168.1.1"
     8FAILSAFE_BCAST="192.168.1.255"
     9
     10# Bring up LAN
    311ip link set up dev eth0
    4 ip addr add 192.168.1.1/24 broadcast 192.168.1.255 dev eth0
    5 netmsg 192.168.1.255 "Press reset now, to enter Failsafe!"
     12ip addr add ${FAILSAFE_IP}/24 broadcast ${FAILSAFE_BCAST} dev eth0
     13
     14# Warn the user
     15netmsg ${FAILSAFE_BCAST} "Press reset now, to enter Failsafe!"
    616echo "Press reset now to enter Failsafe!"
    7 sleep 2
     17sleep 2 &
    818
    9 if [ $(cat /proc/sys/reset) = 1 ]; then
    10         while :; do
    11                 echo $(((X=(X+1)%8)%2)) >/proc/sys/diag
    12                 sleep $((X==0))
    13         done &
    14         netmsg 192.168.1.255 "Entering Failsafe!"
    15         telnetd
    16         exit 1
     19# Check for reset press during the 2s window
     20# We'll read the event stream for KEY_RESTART with value 1 (press)
     21pressed=0
     22timeout 2 sh -c "
     23    evtest ${EVENT_DEV} 2>/dev/null | \
     24    grep -m1 '${KEY_CODE}.*value 1' && exit 0 || exit 1
     25"
     26if [ $? -eq 0 ]; then
     27    pressed=1
     28fi
     29
     30if [ "$pressed" -eq 1 ]; then
     31    # Blink LED in background
     32    (
     33        while :; do
     34            echo 1 > ${LED_PATH}/brightness
     35            sleep 0.5
     36            echo 0 > ${LED_PATH}/brightness
     37            sleep 0.5
     38        done
     39    ) &
     40
     41    netmsg ${FAILSAFE_BCAST} "Entering Failsafe!"
     42    telnetd
     43    exit 1
    1744else
    18         ip addr flush dev eth0
     45    ip addr flush dev eth0
    1946fi
     47
Note: See TracChangeset for help on using the changeset viewer.