1 /* vim:ts=4 sts=4 et tw=80
5 * for additional information please
6 * see http://lochraster.org/fnordlichtmini
8 * (c) by Alexander Neumann <alexander@bumpern.de>
10 * This program is free software: you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License version 3 as published by
12 * the Free Software Foundation.
14 * This program is distributed in the hope that it will be useful, but WITHOUT
15 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
19 * You should have received a copy of the GNU General Public License along with
20 * this program. If not, see <http://www.gnu.org/licenses/>.
24 #include <avr/pgmspace.h>
25 #include "static_programs.h"
30 #include "../common/common.h"
35 /* global list of programs */
36 PROGMEM program_handler static_programs
[] = {
42 PT_THREAD(program_colorwheel(struct process_t
*process
))
44 static uint16_t sleep
;
45 static struct hsv_color_t c
;
47 PT_BEGIN(&process
->pt
);
49 c
.hue
= process
->params
.colorwheel
.hue_start
;
50 c
.value
= process
->params
.colorwheel
.value
;
51 c
.saturation
= process
->params
.colorwheel
.saturation
;
53 int8_t add
= process
->params
.colorwheel
.add_addr
;
54 c
.hue
+= remote_address() * add
* process
->params
.colorwheel
.hue_step
;
58 pwm_fade_hsv(&c
, process
->params
.colorwheel
.fade_step
, process
->params
.colorwheel
.fade_delay
);
60 c
.hue
+= process
->params
.colorwheel
.hue_step
;
62 /* wait until target reached */
63 PT_WAIT_UNTIL(&process
->pt
, pwm_target_reached());
65 /* sleep (in seconds, remember: we are called every 100ms) */
66 sleep
= 10 * process
->params
.colorwheel
.fade_sleep
;
68 PT_YIELD(&process
->pt
);
74 PT_THREAD(program_random(struct process_t
*process
))
76 static uint16_t sleep
;
77 static struct hsv_color_t c
;
79 PT_BEGIN(&process
->pt
);
81 /* initialize random generator */
82 uint16_t seed
= process
->params
.random
.seed
;
83 if (process
->params
.random
.use_address
)
84 seed
^= remote_address();
87 c
.value
= process
->params
.random
.value
;
88 c
.saturation
= process
->params
.random
.saturation
;
91 /* generate new color */
92 union uint32_t_access rnd
;
95 /* use lower word for hue */
98 /* check for minimal color distance, regenerate random if not */
99 int16_t min_distance
= process
->params
.random
.min_distance
;
101 int16_t distance
= c
.hue
- rnd
.words
[0];
103 distance
= -distance
;
106 distance
= 360-distance
;
108 if (distance
< min_distance
)
112 /* copy color to structure */
113 c
.hue
= rnd
.words
[0];
115 /* fade to new color */
116 pwm_fade_hsv(&c
, process
->params
.random
.fade_step
, process
->params
.random
.fade_delay
);
118 /* wait until target reached */
119 if (process
->params
.random
.wait_for_fade
)
120 PT_WAIT_UNTIL(&process
->pt
, pwm_target_reached());
122 /* sleep (remember: we are called every 100ms) */
123 if (process
->params
.random
.fade_sleep
> 0) {
124 sleep
= process
->params
.random
.fade_sleep
;
127 PT_YIELD(&process
->pt
);
131 PT_END(&process
->pt
);
134 PT_THREAD(program_replay(struct process_t
*process
))
141 static struct storage_color_t c
;
143 PT_BEGIN(&process
->pt
);
145 /* reset variables */
146 pos
= process
->params
.replay
.start
;
150 /* load next color value */
151 storage_load_color(pos
, &c
);
153 if (c
.color
.rgb_marker
== 0xff) {
154 struct rgb_color_t color
;
155 color
.red
= c
.color
.red
;
156 color
.green
= c
.color
.green
;
157 color
.blue
= c
.color
.blue
;
159 pwm_fade_rgb(&color
, c
.step
, c
.delay
);
161 struct hsv_color_t color
;
162 color
.hue
= c
.color
.hue
;
163 color
.saturation
= c
.color
.saturation
;
164 color
.value
= c
.color
.value
;
166 pwm_fade_hsv(&color
, c
.step
, c
.delay
);
170 if (direction
== UP
) {
171 /* check for upper end */
172 if (pos
== process
->params
.replay
.end
) {
173 switch (process
->params
.replay
.repeat
) {
174 case REPEAT_NONE
: PT_EXIT(&process
->pt
);
176 case REPEAT_START
: pos
= process
->params
.replay
.start
;
178 case REPEAT_REVERSE
: direction
= DOWN
;
185 if (pos
== process
->params
.replay
.start
) {
194 PT_YIELD(&process
->pt
);
197 PT_END(&process
->pt
);