diff options
author | Mattias Andrée <maandree@operamail.com> | 2014-02-20 06:56:15 +0100 |
---|---|---|
committer | Mattias Andrée <maandree@operamail.com> | 2014-02-20 06:56:15 +0100 |
commit | 78790b90bc25c8ef0de460c52d72bcdd17df0e51 (patch) | |
tree | 26ad13f0fe607022b9a62951d9d15b74ba8f3bb0 /examples | |
parent | fix -c bug (diff) | |
download | blueshift-78790b90bc25c8ef0de460c52d72bcdd17df0e51.tar.gz blueshift-78790b90bc25c8ef0de460c52d72bcdd17df0e51.tar.bz2 blueshift-78790b90bc25c8ef0de460c52d72bcdd17df0e51.tar.xz |
m + add new example: sleepmode
Signed-off-by: Mattias Andrée <maandree@operamail.com>
Diffstat (limited to 'examples')
-rw-r--r-- | examples/comprehensive | 22 | ||||
-rw-r--r-- | examples/sleepmode | 128 |
2 files changed, 139 insertions, 11 deletions
diff --git a/examples/comprehensive b/examples/comprehensive index f033d27..5f6675c 100644 --- a/examples/comprehensive +++ b/examples/comprehensive @@ -10,7 +10,7 @@ # (KTH computer laboratories in this example.) latitude, longitude = 59.3472, 18.0728 -# Custom dayness by time settings +# Custom dayness by time settings. time_alpha = [['02:00', 0], ['08:00', 1], ['22:00', 1]] @@ -37,11 +37,11 @@ def by_time(): return 1 # Error in `time_alpha` (probably) -# Keep uncomment to use solar position +# Keep uncomment to use solar position. get_dayness = lambda : sun(latitude, longitude) -# Uncomment to use time of day +# Uncomment to use time of day. #get_dayness = by_time -# Uncomment if you do not want continuous mode, high night values are used +# Uncomment if you do not want continuous mode, high night values are used. #get_dayness = None @@ -158,13 +158,13 @@ def periodically(year, month, day, hour, minute, second, weekday, fade): global last_dayness, wait_period dayness = get_dayness() - # Do not do unnecessary work + # Do not do unnecessary work. if fade is None: if dayness == last_dayness: return last_dayness = dayness - # Help functions for colour interpolation + # Help functions for colour interpolation. interpol = lambda _day, _night : _day[m % len(_day)] * dayness + _night[m % len(_night)] * (1 - dayness) purify = lambda current, pure : current * alpha + pure * (1 - alpha) @@ -226,7 +226,7 @@ def periodically(year, month, day, hour, minute, second, weekday, fade): else: randr(m) - # Lets wait only 5 seconds, instead of a minute before running again + # Lets wait only 5 seconds, instead of a minute before running again. wait_period = 10 @@ -253,12 +253,12 @@ def reset(): if get_dayness is not None: - # Set transition time, 0 on high day and 5 seconds on high night + # Set transition time, 0 on high day and 5 seconds on high night. fadein_time = 5 * (1 - get_dayness()) - # Do 10 changes per second + # Do 10 changes per second. fadein_steps = fadein_time * 10 - # Transition on exit in the same way, calculated on exit + # Transition on exit in the same way, calculated on exit. old_signal_SIGTERM = signal_SIGTERM def signal_SIGTERM(signum, frame): global fadeout_time, fadeout_steps @@ -266,7 +266,7 @@ if get_dayness is not None: fadeout_steps = fadeout_time * 10 old_signal_SIGTERM(signum, frame) else: - # Do not use continuous mode + # Do not use continuous mode. get_dayness = lambda : 0 def apply(fade): t = datetime.datetime.now() diff --git a/examples/sleepmode b/examples/sleepmode new file mode 100644 index 0000000..22138e5 --- /dev/null +++ b/examples/sleepmode @@ -0,0 +1,128 @@ +# -*- python -*- + +# This example graciously fades out the screen on start and +# in on exit. It is a nice alternative to turning off the +# monitor, just press Control+C when you wake up. + + +# The (zero-based) index of the monitors (CRTC:s) to apply +# settings to. An empty list means that all monitors are used, +# but all monitors will have the same settings. +monitors = [] + + +# These settings are lists. This is to allow you to use different +# settings on different monitors. For example, `gamma_red = [1]`, +# this means that the red gamma is 1 on all monitors. But if we +# change this to `gamma_red = [1.0, 1.1]`, the first monitor will +# have the red gamma set to 1,0 and the second monitor will have +# the red gamma set to 1,1. If you have more monitors than used +# in the settings modulo division will be used. For instance, if +# you have four monitors, the third monitor will have the same +# settings as the first monitor, and the fourth monitor will have +# the same settings as the second monitor. + +# Gamma correction for the red, green and blue components, respectively. +gamma_red, gamma_green, gamma_blue = [1], [1], [1] + +# The red, green and blue brightness, respectively. +redness, greenness, blueness = [0.25], [0], [0] + + +# Set fade time at start to 15 seconds. +fadein_time = 15 +# Do 10 changes per second at start. +fadein_steps = fadein_time * 10 + +# Set fade time at exit to 30 seconds. +fadeout_time = 30 +# Do 10 changes per second at end. +fadeout_steps = fadeout_time * 10 + + +# During sleep mode the changes will occur so we update one every hour. +wait_period = 60 * 60 + + +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, + the 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 + ''' + purity = 0 if fade is None else 1 - abs(fade) + for m in [0] if len(monitors) == 0 else monitors: + # Remove settings from last run. + start_over() + + # Fade out the blue colours component, then the green + # colours component and lastly the blue colours component. + r = min(max(0, purity * 3 - 0), 1) + g = min(max(0, purity * 3 - 1), 1) + b = min(max(0, purity * 3 - 2), 1) + r = redness [m % len(redness)] * (1 - r) + purity + r = greenness[m % len(greenness)] * (1 - g) + purity + r = blueness [m % len(blueness)] * (1 - b) + purity + rgb_brightness(r, g, b) + + # Flush settings to monitor. + r = gamma_red [m % len(gamma_red)] + g = gamma_green[m % len(gamma_green)] + b = gamma_blue [m % len(gamma_blue)] + gamma(r, g, b) + + # Flush settings to monitor. + if len(monitors) == 0: + randr() + else: + randr(m) + + +def reset(): + ''' + Invoked to reset the displays + ''' + for m in [0] if len(monitors) == 0 else monitors: + # Remove settings from last run. + start_over() + + # Apply gamma correction to monitor. + r = gamma_red [m % len(gamma_red)] + g = gamma_green[m % len(gamma_green)] + b = gamma_blue [m % len(gamma_blue)] + gamma(r, g, b) + + # Flush settings to monitor. + if len(monitors) == 0: + randr() + else: + randr(m) + |