3 <doc style="style.css">
7 <title>Bedroom light control</title>
11 <heading>Requirements</heading>
13 <heading>Top level requirements</heading>
17 Wake up lights fade in to specified color or slightly open curtains.
21 wake up light starts at preset alarm time
25 if outside light open curtain else fade to light level
29 open curtain and fade out light at sunrise
33 input from sunrise calculation and outside light sensor
37 user interface for alarm times
41 user interface for wake up light level, sleep light level, walk-in light level and fade times
45 light on at walking in and no outside light
49 lights fade to dark at sleep time
53 lights fade on to specified color at movement in the night.
57 curtains fully open if outside light and after alarm
61 curtains close ar outside dark
65 wake up times can be specified with a recurrance pattern
69 recurrence patterns can be n days, weeks, months, years, weekday, weekendday
73 wake up times can be optained from a online calander
79 <heading>Manual controls</heading>
83 manual controls override automatic controls
87 manual control for light levels
91 manual control for light on and off
95 manual control for curtains open and close
99 manual control from switches
103 manual control from remote, online
110 <heading>Security requirements</heading>
114 Accessible by authorized persons and devices only
118 All remote inputs are logged.
124 <heading>Testability requirements</heading>
128 Time is obtained from actual time or simulated time
132 A simulated time base is used for testing
140 <heading>Test scenarios</heading>
144 Wake up sequence when dark outside followed by sunrise
146 <item>Set the date to dec 21, 23:00.</item>
147 <item>Set a wakeup event at dec 22, 06:00</item>
148 <item>Start wakeup daemon</item>
149 <item>Verify lights on at 06:00</item>
150 <item>Verify lights off at sunrise</item>
154 wake up sequence when light outside
157 wake up with a single alarm event
160 wake up with recurring alarm events
172 curtains close at dusk
179 <heading>Interfaces</heading>
186 alarm time for wake up
189 calculated sunrise and sunset time
198 remote control inputs
214 curtain open and close
222 <heading>Modules</heading>
224 The dataflow diagram shows the high level design.
226 <svg src='dataflow.svg'/>
228 <heading>PWM generator</heading>
230 The PWM generator is controlled by a list of <emph>pwm</emph> structures:
240 Each structure holds an interval in microseconds and an output that is to be switched off after
241 that interval of time has passed.
242 An interval defines the width of the pulse of the PWM output signal relative to the previous interval in the list.
243 The pulse width of a specifc output is the addition of all intervals up to and including the interval for that output.
244 The last entry in the list has an output of -1, which deniotes the end of the list.
245 After that final interval has passed, all outputs are switched ON and the PWM generator returns to the first entry in the list.
247 <svg src='pwm-algorithm.svg'/>
249 This allows the PWM genrator run run with a minimum of calculations.
250 The algorithm of the PWM generator is shown in the figure below:
252 <svg src='pwm-psd.svg'/>
254 The list of PWM signal intervals and associated outputs are store in shared memory.
255 The content of this shared memroy is written by <emph>lightcontrol</emph>.
256 The PWM generator reads the list continuously to generate the output signals.
261 <heading>lightcontrol</heading>
263 The program <emph>lightcontrol</emph> is used to control the levels of the red, green, blue and white LEDs.
264 The levels specified on the command line are converted into PWM signals and passed to the PWM generator.
265 The PWM generator uses a list of incremental intervals, as described in the previous section.
266 These intervals are calculated by <emph>lightcontrol</emph> and stored in the shared memory interface
267 for the PWM generator.
268 The algorithm is shown is the figure below:
270 <svg src='light_to_pwm.svg'/>
272 The following figure shows the algorithm to fade the lights:
274 <svg src='lightfade.svg'/>
276 <heading>Command line interface</heading>
278 Command line options specify the operation of the LEDs:
281 lightcontrol [-l] [-V] [-r red] [-g green] [-b blue] [-w white] [-f fadetime]
284 Not all levels need to be specified. If the desired level for a LED is not specified, it will not be changed.
285 For example if only the option "-r 50" is given,
286 the red LED will light at 50% but the green, blue and white levels will be unchanged.
289 Set the level of the red LED. The level is an integer number between 0 and 100, 0 meaning fully off and 100 meaning fully on.
291 <item tag="-g green">
292 Set the level of the green LED. The level is an integer number between 0 and 100, 0 meaning fully off and 100 meaning fully on.
295 Set the level of the blue LED. The level is an integer number between 0 and 100, 0 meaning fully off and 100 meaning fully on.
297 <item tag="-w white">
298 Set the level of the white LED. The level is an integer number between 0 and 100, 0 meaning fully off and 100 meaning fully on.
300 <item tag="-f fadetime">
301 Do not set the levels of the LEDs immediately but fade from the current levels to the desired levels
302 in <emph>fadetime</emph> seconds.
303 The default fade time is 0, which will immeditely change the light levels.
306 List the current light levels.
307 The current levels are printed to standard output on a single line of 4 numbers.
308 The numbers are the current levels in the order red, green, blue and white.
311 Print the version of the program and exit.
315 <remark>TODO:</remark> Option -p to set the PWM period, default 10000 microseconds.
319 <heading>Execution interface</heading>
321 Create a run file when fading lights to the desired level.
322 The run file holds the process id and the Tachyon name.
323 A fade can be interrupted by a signal. This allows another lightcontrol process to override a running fade.
324 The Tachyon name can be used to control the time base used by the fade process.
325 This is mainly used for test purpooses.
326 The run file is removed on exit.
332 <heading>Wakeup</heading>
335 The primary function of the wakeup process is to gradually increase the light at wakeup time in the morning.
336 Either by fading in the lights to a specified level or by (slightly) opening the curtains.
337 Controlling the curtains is the secondary function of wakeup.
338 This means fully opening the curtains in the morning and closing the curtains in the evening,
339 depending on the times of sunrise and sunset.
343 The wakeup times are specified like calendar events, possibly with a recurrence pattern and an end date.
344 Elements in an event are:
348 <item> Start time</item>
349 <item> Recurrence pattern</item>
350 <item> Number of recurrences</item>
351 <item> End time</item>
353 A recurrence pattern can be specified with a number of days, weeks or months as well as a set of weekdays.
354 A set of weekdays implies the recurrence will be weekly.
355 The action for an event can be a light sequence or a curtain control.
359 An event is read from an XML element or created dynamically, for example calculated from the time of sunrise.
360 From any event, the next occurance is calculated, which is an event that happens after a certain time.
361 When the next event does happen, meaning the time of the occurance is the current time, the sequence of actions is executed.
362 Each action can for example be a change in lights or the opening or closing of curtains.