aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--README.md15
-rw-r--r--conf8
-rwxr-xr-xrun6
3 files changed, 12 insertions, 17 deletions
diff --git a/README.md b/README.md
index d6a49e1..6acba52 100644
--- a/README.md
+++ b/README.md
@@ -2,9 +2,9 @@
A simple battery daemon written for use with a daemontools-style supervisor.
-`run` polls the status of a `check` function with a regular interval. On the
-transition from a successful `check` exit status to an unsuccessful `check` exit
-status the `failed` function is called.
+`run` polls the status of a `check` function with an interleaved call to
+`interval`. On the transition from a successful `check` exit status to an
+unsuccessful `check` exit status the `failed` function is called.
## Installation
@@ -20,7 +20,7 @@ Adjust the above as needed.
Configure `conf` appropriately. This should contain three functions:
`interval`
-: Called to determine the polling interval (see below).
+: Called between consecutive calls to `check`.
`check`
: Called to determine the battery status.
@@ -29,10 +29,3 @@ Configure `conf` appropriately. This should contain three functions:
: Called when the battery status has transitioned from a successful to a
failing return.
-Optionally two variables can be set:
-
-`long_interval`
-: The polling interval when `interval` returns success (default: 300).
-
-`short_interval`
-: The polling interval when `interval` returns failure (default: 30).
diff --git a/conf b/conf
index cff836d..e538b60 100644
--- a/conf
+++ b/conf
@@ -1,4 +1,10 @@
battery=/sys/class/power_supply/BAT0/uevent
-interval() { ./battcheck min_time=1200 min_pct=16 "$battery"; }
+interval() {
+ if ./battcheck min_time=1200 min_pct=16 "$battery"; then
+ sleep 300
+ else
+ sleep 30
+ fi
+}
check() { ./battcheck min_time=600 min_pct=8 "$battery"; }
failed() { zzz -H; }
diff --git a/run b/run
index 784c89c..03f7d08 100755
--- a/run
+++ b/run
@@ -9,11 +9,7 @@ check
laststatus=$?
while :; do
- if interval; then
- sleep "${long_interval-300}"
- else
- sleep "${short_interval-30}"
- fi
+ interval
check
status=$?
if [ "$laststatus" -eq 0 ] && [ "$status" -ne 0 ]; then