summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKeine_Ahnung <dirk-vdr@gmx.de>2013-02-05 20:09:41 +0100
committerKeine_Ahnung <dirk-vdr@gmx.de>2013-02-05 20:09:41 +0100
commitb2316e705cf742ac9e811d3c3e200a8f21547bab (patch)
treede56ee3bee9508cb112119da36a3c439274419ab
parent2be7e65c7b15775993eeb3198b8c2404b5b489dd (diff)
downloadvdr-plugin-uactivity-b2316e705cf742ac9e811d3c3e200a8f21547bab.tar.gz
vdr-plugin-uactivity-b2316e705cf742ac9e811d3c3e200a8f21547bab.tar.bz2
Added switch_tv_light example, fixed filenames and attributes
-rwxr-xr-x[-rw-r--r--]script/uactivity/activity/#10-syslog_demo (renamed from script/uactivity/activity/-10-syslog_demo)0
-rwxr-xr-x[-rw-r--r--]script/uactivity/activity/#20-graphlcd_dbus2vdr (renamed from script/uactivity/activity/-20-graphlcd_dbus2vdr)0
-rwxr-xr-x[-rw-r--r--]script/uactivity/activity/#20-switch_tv (renamed from script/uactivity/activity/-20-switch_tv)0
-rwxr-xr-xscript/uactivity/activity/#20-switch_tv_light116
-rwxr-xr-x[-rw-r--r--]script/uactivity/key/#10-syslog_demo (renamed from script/uactivity/key/-10-syslog_demo)0
-rwxr-xr-x[-rw-r--r--]script/uactivity/key/#20-toggle_demo (renamed from script/uactivity/key/-20-toggle_demo)0
-rwxr-xr-x[-rw-r--r--]script/uactivity/watchdog/#10-syslog_demo (renamed from script/uactivity/watchdog/-10-syslog_demo)0
-rwxr-xr-x[-rw-r--r--]script/vdr-uactivity0
8 files changed, 116 insertions, 0 deletions
diff --git a/script/uactivity/activity/-10-syslog_demo b/script/uactivity/activity/#10-syslog_demo
index c1d98ec..c1d98ec 100644..100755
--- a/script/uactivity/activity/-10-syslog_demo
+++ b/script/uactivity/activity/#10-syslog_demo
diff --git a/script/uactivity/activity/-20-graphlcd_dbus2vdr b/script/uactivity/activity/#20-graphlcd_dbus2vdr
index 010dfbe..010dfbe 100644..100755
--- a/script/uactivity/activity/-20-graphlcd_dbus2vdr
+++ b/script/uactivity/activity/#20-graphlcd_dbus2vdr
diff --git a/script/uactivity/activity/-20-switch_tv b/script/uactivity/activity/#20-switch_tv
index c9bbf57..c9bbf57 100644..100755
--- a/script/uactivity/activity/-20-switch_tv
+++ b/script/uactivity/activity/#20-switch_tv
diff --git a/script/uactivity/activity/#20-switch_tv_light b/script/uactivity/activity/#20-switch_tv_light
new file mode 100755
index 0000000..baae21f
--- /dev/null
+++ b/script/uactivity/activity/#20-switch_tv_light
@@ -0,0 +1,116 @@
+#!/bin/sh
+
+set -u
+set -e
+
+# Your Settings
+#
+LATITUDE="52.000000"
+LONGITUDE="11.000000"
+# http://search.cpan.org/~rkhill/DateTime-Event-Sunrise-0.0501/lib/DateTime/Event/Sunrise.pm#METHODS
+ALTITUDE="-0.833"
+SWITCH_ON_CMD="touch /tmp/tv_light"
+SWITCH_OFF_CMD="rm -f /tmp/tv_light"
+#
+# End of user config
+# apt-get install libdatetime-event-sunrise-perl
+
+
+
+JOB_ID_FILE="${4}/activity/jobid.$(basename ${0})"
+
+
+
+daylight(){
+ export LATITUDE
+ export LONGITUDE
+ export ALTITUDE
+
+sunset="$(perl <<'EOF' 2> /dev/null
+ use DateTime;
+ use DateTime::Event::Sunrise;
+ use DateTime::Format::Strptime;
+
+ my $latitude = $ENV{'LATITUDE'};
+ my $longitude = $ENV{'LONGITUDE'};
+ my $altitude = $ENV{'ALTITUDE'};
+
+ my $sunrise = DateTime::Event::Sunrise ->sunrise (longitude => $longitude, latitude => $latitude, altitude => $altitude, iteration => '1');
+ my $sunset = DateTime::Event::Sunrise ->sunset (longitude => $longitude, latitude => $latitude, altitude => $altitude, iteration => '1');
+
+ my $strp = DateTime::Format::Strptime->new(pattern => '%H:%M %Y-%m-%d');
+ print $strp->format_datetime($sunset->next(DateTime->now(time_zone=>'local')));
+
+ my $day_set = DateTime::SpanSet->from_sets(start_set => $sunrise, end_set => $sunset);
+ $day_set->contains(DateTime->now()) ? exit 1 : exit 0;
+EOF
+)"
+
+ err=$?
+ if [ ${err} = 0 ]; then
+ echo ""
+ return 0
+ elif [ ${err} = 1 ]; then
+ echo "${sunset}"
+ return 1
+ else
+ echo ""
+ return 2
+ fi
+}
+
+
+
+delete_job(){
+ if [ -f "${JOB_ID_FILE}" ]; then
+ JOB_ID="$(cat ${JOB_ID_FILE})"
+ atrm ${JOB_ID} 2> /dev/null
+ rm -f "${JOB_ID_FILE}"
+ fi
+}
+
+
+
+switch_tv_light(){
+ delete_job
+ if [ "${1}" = "on" ]; then
+ sunset="$(daylight)"
+ light=$?
+ if [ "${light}" = "1" ]; then
+ # daylight now, shedule "light on" for later
+ JOB_ID_TMP="$(echo "rm -f "${JOB_ID_FILE}"; ${SWITCH_ON_CMD}" | at ${sunset} 2>&1)"
+ JOB_ID="$(echo "${JOB_ID_TMP}" | tr -d '\n' | sed 's/^.*job \([0-9]*\).*$/\1/')"
+ echo "${JOB_ID}" > ${JOB_ID_FILE}
+ elif [ "${light}" = "0" ]; then
+ eval ${SWITCH_ON_CMD}
+ else
+ # Some error
+ eval ${SWITCH_OFF_CMD}
+ fi
+ else
+ eval ${SWITCH_OFF_CMD}
+ fi
+}
+
+
+
+case "${1}" in
+ startup)
+ delete_job
+ ;;
+ started)
+ [ "${2}" = "true" ] && switch_tv_light on
+ ;;
+ shutdown)
+ switch_tv_light off
+ ;;
+ running)
+ if [ "${2}" = "true" ]; then
+ switch_tv_light on
+ else
+ switch_tv_light off
+ fi
+ ;;
+esac
+
+exit 0
diff --git a/script/uactivity/key/-10-syslog_demo b/script/uactivity/key/#10-syslog_demo
index ee794a7..ee794a7 100644..100755
--- a/script/uactivity/key/-10-syslog_demo
+++ b/script/uactivity/key/#10-syslog_demo
diff --git a/script/uactivity/key/-20-toggle_demo b/script/uactivity/key/#20-toggle_demo
index 3ec3cfb..3ec3cfb 100644..100755
--- a/script/uactivity/key/-20-toggle_demo
+++ b/script/uactivity/key/#20-toggle_demo
diff --git a/script/uactivity/watchdog/-10-syslog_demo b/script/uactivity/watchdog/#10-syslog_demo
index 8ff6ca3..8ff6ca3 100644..100755
--- a/script/uactivity/watchdog/-10-syslog_demo
+++ b/script/uactivity/watchdog/#10-syslog_demo
diff --git a/script/vdr-uactivity b/script/vdr-uactivity
index c758939..c758939 100644..100755
--- a/script/vdr-uactivity
+++ b/script/vdr-uactivity