From b375f6b8cd36e45b8a6c29b04cd3c54db9f3b70d Mon Sep 17 00:00:00 2001 From: jayfan0 <> Date: Sat, 8 Apr 2023 22:13:11 +0100 Subject: [PATCH] Add reset daemon for cameras with gpio buttons --- general/overlay/etc/init.d/S10resetd | 8 +++++++ general/overlay/usr/sbin/resetd | 32 ++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100755 general/overlay/etc/init.d/S10resetd create mode 100644 general/overlay/usr/sbin/resetd diff --git a/general/overlay/etc/init.d/S10resetd b/general/overlay/etc/init.d/S10resetd new file mode 100755 index 00000000..f6ac30e9 --- /dev/null +++ b/general/overlay/etc/init.d/S10resetd @@ -0,0 +1,8 @@ +#!/bin/sh + +case "$1" in + start) + echo -e '\nLoading resetd...' + /usr/sbin/resetd & + ;; +esac diff --git a/general/overlay/usr/sbin/resetd b/general/overlay/usr/sbin/resetd new file mode 100644 index 00000000..14740665 --- /dev/null +++ b/general/overlay/usr/sbin/resetd @@ -0,0 +1,32 @@ +#!/bin/sh + +# Set Reset switch GPIO +GPIO= + +[ -z $GPIO ] && echo "GPIO not set. Exiting" && echo "[resetd] GPIO undefined in /usr/sbin/resetd" > /dev/kmsg && exit + +# Counter for button press until reset +count=0 + +# prepare the pin +if [ ! -d /sys/class/gpio/gpio${GPIO} ]; then + echo "${GPIO}" > /sys/class/gpio/export + echo "in" > /sys/class/gpio/gpio"${GPIO}"/direction +fi + +# continuously monitor current value of reset switch +while [ true ] +do + if [ "$(cat /sys/class/gpio/gpio"${GPIO}"/value)" -eq 1 ]; then + count=0 + else + count=$((count+1)) + + # 20 counts =~ 5 seconds @ 0.25 sleep intervals + if [ $count -eq 20 ]; then + echo RESETTING FIRMWARE + firstboot + fi + fi + sleep 0.25 # This interval uses 1% CPU. Less sleep = more CPU +done