diff options
4 files changed, 197 insertions, 0 deletions
diff --git a/recipes-core/multitech/reset-handler-test/reset-handler.default b/recipes-core/multitech/reset-handler-test/reset-handler.default new file mode 100644 index 0000000..71b3e24 --- /dev/null +++ b/recipes-core/multitech/reset-handler-test/reset-handler.default @@ -0,0 +1,2 @@ +# set to "no" to disable reset-handler starting on boot +ENABLED="yes" diff --git a/recipes-core/multitech/reset-handler-test/reset-handler.init b/recipes-core/multitech/reset-handler-test/reset-handler.init new file mode 100644 index 0000000..b50e7b8 --- /dev/null +++ b/recipes-core/multitech/reset-handler-test/reset-handler.init @@ -0,0 +1,30 @@ +#!/bin/sh + +DAEMON=/usr/sbin/reset-handler +PIDFILE=/var/run/reset-handler.pid +ENABLED="yes" + +[ -r /etc/default/reset-handler ] && . /etc/default/reset-handler +[ -x $DAEMON ] || exit 0 +[ "$ENABLED" = "yes" ] || exit 0 + +case "$1" in + start) + if [ -f $PIDFILE ]; then + echo "reset-handler pid file exists, not starting" + exit 1 + else + echo "Starting reset-handler" + start-stop-daemon --start --background --make-pidfile --pidfile $PIDFILE --exec $DAEMON + fi + ;; + stop) + echo "Stopping reset-handler" + start-stop-daemon --stop --oknodo --pidfile $PIDFILE + rm -f $PIDFILE + ;; + *) + echo "Usage: $0 {start|stop}" + exit 2 + ;; +esac diff --git a/recipes-core/multitech/reset-handler-test/reset-handler.sh b/recipes-core/multitech/reset-handler-test/reset-handler.sh new file mode 100755 index 0000000..08e4e51 --- /dev/null +++ b/recipes-core/multitech/reset-handler-test/reset-handler.sh @@ -0,0 +1,134 @@ +#!/bin/bash + +# Copyright (C) 2014 Multi-Tech Systems + +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: + +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. + +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +# THE SOFTWARE. + +PERSISTENT_DIR="/var/persistent/" +ERASE_PERSISTENT="${PERSISTENT_DIR}/mts_do_erase_persistent" + +name="reset-handler" +log="logger -t $name -s" +pid="$$" + +off_leds_test() { + logger 'Turning LEDs to off' + leds=$(ls $led_dir/ | grep -v status) + nleds=$(echo "$leds" | wc -w) + # turn LEDs off + for led in $leds; do + echo none > $led_dir/$led/trigger + echo 0 > $led_dir/$led/brightness + done + logger 'Done LEDs off' +} +blink_leds_test() { + logger 'Turning LEDs to test' + led_dir=/sys/class/leds + # blink all programmable LEDs except status + # in reverse order + leds=$(ls $led_dir/ | grep -v status | awk '{a[i++]=$0} END {for (j=i-1; j>=0;) print a[j--] }') + nleds=$(echo "$leds" | wc -w) + + # turn LEDs off + for led in $leds; do + echo "timer" > $led_dir/$led/trigger + echo 0 > $led_dir/$led/delay_off + done + + + # make a pattern + int=1200 + total=$(( int * (nleds+1) )) + on=$(( total - int )) + off=$(( total - on )) + for led in $leds; do + echo "$on" > $led_dir/$led/delay_on + echo "$off" > $led_dir/$led/delay_off + on=$(( total - int )) + off=$(( total - on )) + done + sleep 4 + off_leds_test + logger 'Done Turning LEDs to test' +} + +short_signal=10 # SIGUSR1 +long_signal=12 # SIGUSR2 +extralong_signal=1 # SIGHUP + +do_reboot() { + $log "Rebooting on button press" + sleep 1 + reboot +} + +do_shutdown() { + $log "Shutting down" + shutdown -h now +} + +do_restore_defaults() { + $log "Removing /var/config contents" + rm -rf /var/config/* + $log "Setting restore defaults on reboot" + touch /var/config/force_defaults + if [[ -x /usr/bin/rmpasswd ]] + then + $log "Resetting passwords" + source rmpasswd + fi + if [[ -d ${PERSISTENT_DIR} ]] ; then + touch ${ERASE_PERSISTENT} + fi + $log "Blink LEDs" + sleep 1 + reboot +} + +log_exit() { + $log "Exiting on SIGTERM" + exit 0 +} + +idle_wait() { + pipe=/var/tmp/$name.fifo + rm -f $pipe + mkfifo -m 400 $pipe + + # sneaky way to do nothing forever + while true; do + read < $pipe + done +} + +trap blink_leds_test $short_signal +trap blink_leds_test $long_signal +trap blink_leds_test $extralong_signal +trap log_exit TERM + +$log "Enabling reset-monitor for pid $pid" +mts-io-sysfs store reset-monitor "$pid $short_signal $long_signal $extralong_signal" +# set long press to 5 seconds for reset to defaults +mts-io-sysfs store reset-monitor-intervals "5 30" +# set up SIGPWR shutdown + +# wait for signals +idle_wait + diff --git a/recipes-core/multitech/reset-handler-test_1.0.bb b/recipes-core/multitech/reset-handler-test_1.0.bb new file mode 100644 index 0000000..38cd0ae --- /dev/null +++ b/recipes-core/multitech/reset-handler-test_1.0.bb @@ -0,0 +1,31 @@ +DESCRIPTION = "Test reset button" +SECTION = "base" +LICENSE = "MIT" +LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302" +PR = "r3" +RDEPENDS_${PN} += "bash" + +inherit update-rc.d +inherit allarch + +INITSCRIPT_NAME = "reset-handler" +INITSCRIPT_PARAMS = "start 95 2 3 4 5 ." +CONFFILES_${PN} = "${sysconfdir}/default/reset-handler" + +SRC_URI = "\ + file://reset-handler.sh \ + file://reset-handler.init \ + file://reset-handler.default \ +" + +do_install () { + install -d ${D}${sbindir} + install -m 0755 ${WORKDIR}/reset-handler.sh ${D}${sbindir}/reset-handler + + # init script + install -d ${D}${sysconfdir}/init.d + install -m 0755 ${WORKDIR}/reset-handler.init ${D}${sysconfdir}/init.d/reset-handler + + install -d ${D}${sysconfdir}/default + install -m 0644 ${WORKDIR}/reset-handler.default ${D}${sysconfdir}/default/reset-handler +} |