summaryrefslogtreecommitdiffstats
path: root/examples/bedtime
diff options
context:
space:
mode:
authorMattias Andrée <maandree@operamail.com>2014-03-25 08:29:49 +0100
committerMattias Andrée <maandree@operamail.com>2014-03-25 08:29:49 +0100
commit8b34e6ea7b0afdec8f58d5b9d6cf03bf94232587 (patch)
tree25cca4d367827cfb3d92f30c0a648bece2c2c4c2 /examples/bedtime
parentimplemention of linearly_interpolate_ramp (diff)
downloadblueshift-8b34e6ea7b0afdec8f58d5b9d6cf03bf94232587.tar.gz
blueshift-8b34e6ea7b0afdec8f58d5b9d6cf03bf94232587.tar.bz2
blueshift-8b34e6ea7b0afdec8f58d5b9d6cf03bf94232587.tar.xz
m bug + beginning of bedtime example
Signed-off-by: Mattias Andrée <maandree@operamail.com>
Diffstat (limited to '')
-rw-r--r--examples/bedtime126
1 files changed, 126 insertions, 0 deletions
diff --git a/examples/bedtime b/examples/bedtime
new file mode 100644
index 0000000..28d1dd6
--- /dev/null
+++ b/examples/bedtime
@@ -0,0 +1,126 @@
+# -*- python -*-
+
+# This example adjusts the the colours to make it easier to go to bed
+# around a scheduled time, for each weekday.
+
+
+# Copyright © 2014 Mattias Andrée (maandree@member.fsf.org)
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+
+# The time for each weekday you go to bed. The first value is the
+# time to start preparing the for sleep and the second value is the
+# time the monitors should be fully adjusted for sleep.
+time_sleep_monday = ('22:00', '24:00')
+time_sleep_tuesday = ('22:00', '24:00')
+time_sleep_wednesday = ('22:00', '24:00')
+time_sleep_thursday = ('22:00', '24:00')
+time_sleep_friday = ('22:00', '24:00')
+time_sleep_saturday = ('24:00', '26:00')
+time_sleep_sunday = ('24:00', '26:00')
+# It is allowed to have values above and including 24:00, these
+# values are interprets as that time (minus 24 hours) the next day.
+
+# The time for each weekday you wake up. The first value is the time
+# to start adjusting the colours back to normal node, and the second
+# value is the time the adjustment should be back to fully normal.
+time_wakeup_monday = ('06:00', '07:00')
+time_wakeup_tuesday = ('06:00', '07:00')
+time_wakeup_wednesday = ('06:00', '07:00')
+time_wakeup_thursday = ('06:00', '07:00')
+time_wakeup_friday = ('06:00', '07:00')
+time_wakeup_saturday = ('13:00', '14:00')
+time_wakeup_sunday = ('13:00', '14:00')
+
+
+
+# Combine the time points into a matrix.
+times = (time_sleep_monday + time_wakeup_tuesday,
+ = time_sleep_tuesday + time_wakeup_wednesday,
+ = time_sleep_wednesday + time_wakeup_thursday,
+ = time_sleep_thursday + time_wakeup_friday,
+ = time_sleep_friday + time_wakeup_saturday,
+ = time_sleep_saturday + time_wakeup_sunday,
+ = time_sleep_sunday + time_wakeup_monday)
+
+def interpret_time(t):
+ '''
+ Convert a text representation of a time point to a float
+ point value of the number of seconds
+
+ @param t:str The time as text
+ @return :float The time as floating point
+ '''
+ t = [float(t_) for t_ in t.split(':')]
+ while len(t) > 3:
+ t.append(0)
+ return sum([v * 60 ** (2 - i) for i, v in enumerate(t)])
+
+def monotonic_time(ts):
+ '''
+ Ensure that each time points in a sequence is at least
+ as late as the previous time
+
+ @param ts:list<float> The time point sequence
+ @return :list<float> The time point sequence as an increasing sequence
+ '''
+ ONE_DAY = 24 * 60 * 60
+ rc = [ts[0]]
+ for t in ts[1:]:
+ if t < rc[-1]:
+ t += rc[-1] - (rc[-1] % ONE_DAY) + ONE_DAY
+ rc.append(t)
+ return rc
+
+times = [monotonic_time([interpret_time(t) for t in ts]) in ts for times]
+
+
+
+def periodically(year, month, day, hour, minute, second, weekday, fade):
+ '''
+ :(int, int, int, int, int, int, int, float?)?→void Place holder for periodically invoked function
+
+ Invoked periodically
+
+ If you want to control at what to invoke this function next time
+ you can set the value of the global variable `wait_period` to the
+ number of seconds to wait before invoking this function again.
+ The value does not need to be an integer.
+
+ @param year:int The year
+ @param month:int The month, 1 = January, 12 = December
+ @param day:int The day, minimum value is 1, probable maximum value is 31 (*)
+ @param hour:int The hour, minimum value is 0, maximum value is 23
+ @param minute:int The minute, minimum value is 0, maximum value is 59
+ @param second:int The second, minimum value is 0, probable maximum value is 60 (**)
+ @param weekday:int The weekday, 1 = Monday, 7 = Sunday
+ @param fade:float? Blueshift can use this function to fade into a state when it start
+ or exits. `fade` can either be negative, zero or positive or `None`,
+ but the magnitude of value cannot exceed 1. When Blueshift starts,
+ this function will be invoked multiple with the time parameters
+ of the time it is invoked and each time `fade` will increase towards
+ 1, starting at 0, when the value is 1, the settings should be applied
+ to 100 %. After this this function will be invoked once again with
+ `fade` being `None`. When Blueshift exits the same behaviour is used
+ except, `fade` decrease towards -1 but start slightly below 0, when
+ -1 is reached all settings should be normal. Then Blueshift will NOT
+ invoke this function with `fade` being `None`, instead it will by
+ itself revert all settings and quit.
+
+ (*) Can be exceeded if the calendar system is changed, like in 1712-(02)Feb-30
+ (**) See https://en.wikipedia.org/wiki/Leap_second
+ '''
+ pass
+