Initial revision
[wakeup.git] / doc / design.xml
1 <?xml version="1.0"?>
2
3 <doc style="style.css">
4
5   <book>
6   <titlepage>
7       <title>Bedroom light control</title>
8    </titlepage>
9
10     <chapter>
11     <heading>Requirements</heading>
12     <section>
13     <heading>Top level requirements</heading>
14
15 <description>
16   <item tag='REQ1.01'>
17     Wake up lights fade in to specified color or slightly open curtains.
18   </item>
19
20   <item tag='REQ1.02'>
21     wake up light starts at preset alarm time
22   </item>
23
24   <item tag='REQ1.03'>
25     if outside light open curtain else fade to light level
26   </item>
27
28   <item tag='REQ1.04'>
29     open curtain and fade out light at sunrise
30   </item>
31
32   <item tag='REQ1.05'>
33     input from sunrise calculation and outside light sensor
34   </item>
35
36   <item tag='REQ1.06'>
37     user interface for alarm times
38   </item>
39
40   <item tag='REQ1.07'>
41     user interface for wake up light level, sleep light level, walk-in light level and fade times
42   </item>
43
44   <item tag='REQ1.08'>
45     light on at walking in and no outside light
46   </item>
47
48   <item tag='REQ1.09'>
49     lights fade to dark at sleep time
50   </item>
51
52   <item tag='REQ1.10'>
53     lights fade on to specified color at movement in the night.
54   </item>
55
56   <item tag='REQ1.11'>
57     curtains fully open if outside light and after alarm
58   </item>
59
60   <item tag='REQ1.12'>
61     curtains close ar outside dark
62   </item>
63
64   <item tag='REQ1.13'>
65     wake up times can be specified with a recurrance pattern
66   </item>
67
68   <item tag='REQ1.14'>
69     recurrence patterns can be n days, weeks, months, years, weekday, weekendday
70   </item>
71
72   <item tag='REQ1.15'>
73     wake up times can be optained from a online calander
74   </item>
75 </description>
76
77     </section>
78     <section>
79     <heading>Manual controls</heading>
80
81 <description>
82   <item tag='REQ2.01'>
83     manual controls override automatic controls
84   </item>
85
86   <item tag='REQ2.02'>
87     manual control for light levels
88   </item>
89
90   <item tag='REQ2.03'>
91     manual control for light on and off
92   </item>
93
94   <item tag='REQ2.04'>
95     manual control for curtains open and close
96   </item>
97
98   <item tag='REQ2.05'>
99     manual control from switches
100   </item>
101
102   <item tag='REQ2.06'>
103     manual control from remote, online
104   </item>
105 </description>
106
107     </section>
108
109     <section>
110     <heading>Security requirements</heading>
111
112 <description>
113   <item tag='REQ3.01'>
114     Accessible by authorized persons and devices only
115   </item>
116
117   <item tag='REQ3.02'>
118     All remote inputs are logged.
119   </item>
120 </description>
121
122     </section>
123     <section>
124     <heading>Testability requirements</heading>
125
126 <description>
127   <item tag='REQ4.01'>
128     Time is obtained from actual time or simulated time
129   </item>
130
131   <item tag='REQ4.02'>
132     A simulated time base is used for testing
133   </item>
134 </description>
135
136     </section>
137     </chapter>
138
139     <chapter>
140     <heading>Test scenarios</heading>
141
142 <itemize>
143   <item>
144     Wake up sequence when dark outside followed by sunrise
145     <enumerate>
146     <item>Set the date to dec 21, 23:00.</item>
147     <item>Set a wakeup event at dec 22, 06:00</item>
148     </enumerate>
149   </item>
150   <item>
151     wake up sequence when light outside
152   </item>
153   <item>
154     wake up with a single alarm event
155   </item>
156   <item>
157     wake up with recurring alarm events
158   </item>
159   <item>
160     sleep time fade out
161   </item>
162   <item>
163     walk in when dark
164   </item>
165   <item>
166     walk in when light
167   </item>
168   <item>
169     curtains close at dusk
170   </item>
171 </itemize>
172
173     </chapter>
174
175     <chapter>
176     <heading>Interfaces</heading>
177
178 <para>
179     inputs:
180
181 <itemize>
182   <item>
183     alarm time for wake up
184   </item>
185   <item>
186     calculated sunrise and sunset time
187   </item>
188   <item>
189     outside light level
190   </item>
191   <item>
192     manual switches
193   </item>
194   <item>
195     remote control inputs
196   </item>
197   <item>
198     pir sensor
199   </item>
200 </itemize>
201 </para>
202
203 <para>
204     outputs:
205
206 <itemize>
207   <item>
208     light levels
209   </item>
210   <item>
211     curtain open and close
212   </item>
213 </itemize>
214 </para>
215
216     </chapter>
217
218     <chapter>
219     <heading>Modules</heading>
220 <para>
221 The dataflow diagram shows the high level design.
222 </para>
223 <svg src='dataflow.svg'/>
224     <section>
225     <heading>PWM generator</heading>
226 <para>
227 The PWM generator is controlled by a list of <emph>pwm</emph> structures:
228 <verbatim>
229
230     struct pwm
231     {
232        int interval;
233        int output;
234     };
235
236 </verbatim>
237 Each structure holds an interval in microseconds and an output that is to be switched off after
238 that interval of time has passed.
239 An interval defines the width of the pulse of the PWM output signal relative to the previous interval in the list.
240 The pulse width of a specifc output is the addition of all intervals up to and including the interval for that output.
241 The last entry in the list has an output of -1, which deniotes the end of the list.
242 After that final interval has passed, all outputs are switched ON and the PWM generator returns to the first entry in the list.
243 </para>
244 <svg src='pwm-algorithm.svg'/>
245 <para>
246 This allows the PWM genrator run run with a minimum of calculations.
247 The algorithm of the PWM generator is shown in the figure below:
248 </para>
249 <svg src='pwm-psd.svg'/>
250 <para>
251 The list of PWM signal intervals and associated outputs are store in shared memory.
252 The content of this shared memroy is written by <emph>lightcontrol</emph>.
253 The PWM generator reads the list continuously to generate the output signals.
254 </para>
255     </section>
256
257     <section>
258     <heading>lightcontrol</heading>
259 <para>
260 The program <emph>lightcontrol</emph> is used to control the levels of the red, green, blue and white LEDs.
261 The levels specified on the command line are converted into PWM signals and passed to the PWM generator.
262 The PWM generator uses a list of incremental intervals, as described in the previous section.
263 These intervals are calculated by <emph>lightcontrol</emph> and stored in the shared memory interface
264 for the PWM generator.
265 The algorithm is shown is the figure below:
266 </para>
267 <svg src='light_to_pwm.svg'/>
268 <para>
269 The following figure shows the algorithm to fade the lights:
270 </para>
271 <svg src='lightfade.svg'/>
272     <subsection>
273     <heading>Command line interface</heading>
274 <para>
275 Command line options specify the operation of the LEDs:
276 <verbatim>
277
278    lightcontrol [-l] [-V] [-r red] [-g green] [-b blue] [-w white] [-f fadetime]
279
280 </verbatim>
281 Not all levels need to be specified. If the desired level for a LED is not specified, it will not be changed.
282 For example if only the option "-r 50" is given,
283 the red LED will light at 50% but the green, blue and white levels will be unchanged.
284 <description>
285   <item tag="-r red">
286     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.
287   </item>
288   <item tag="-g green">
289     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.
290   </item>
291   <item tag="-b blue">
292     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.
293   </item>
294   <item tag="-w white">
295     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.
296   </item>
297   <item tag="-f fadetime">
298     Do not set the levels of the LEDs immediately but fade from the current levels to the desired levels
299     in <emph>fadetime</emph> seconds.
300     The default fade time is 0, which will immeditely change the light levels.
301   </item>
302   <item tag="-l">
303     List the current light levels.
304     The current levels are printed to standard output on a single line of 4 numbers.
305     The numbers are the current levels in the order red, green, blue and white.
306   </item>
307   <item tag="-V">
308     Print the version of the program and exit.
309   </item>
310 </description>
311
312 <remark>TODO:</remark> Option -p to set the PWM period, default 10000 microseconds.
313 </para>
314     </subsection>
315     <subsection>
316     <heading>Execution interface</heading>
317 <para>
318 Create a run file when fading lights to the desired level.
319 The run file holds the process id and the Tachyon name.
320 A fade can be interrupted by a signal. This allows another lightcontrol process to override a running fade.
321 The Tachyon name can be used to control the time base used by the fade process.
322 This is mainly used for test purpooses.
323 The run file is removed on exit.
324 </para>
325     </subsection>
326
327     </section>
328     <section>
329     <heading>Wakeup</heading>
330
331 <para>
332 The primary function of the wakeup process is to gradually increase the light at wakeup time in the morning.
333 Either by fading in the lights to a specified level or by (slightly) opening the curtains.
334 Controlling the curtains is the secondary function of wakeup.
335 This means fully opening the curtains in the morning and closing the curtains in the evening,
336 depending on the times of sunrise and sunset.
337 </para>
338
339 <para>
340 The wakeup times are specified like calendar events, possibly with a recurrence pattern and an end date.
341 Elements in a wakeup event are:
342 <itemize>
343    <item> Label</item>
344    <item> Light parameters</item>
345    <item> Start time</item>
346    <item> Recurrence pattern</item>
347    <item> Number of recurrences</item>
348    <item> End time</item>
349 </itemize>
350 A recurrence pattern can be specified with a number of days, weeks or months as well as a set of weekdays.
351 A set of weekdays implies the recurrence will be weekly.
352 </para>
353
354     </section>
355     </chapter>
356
357   </book>
358
359 </doc>