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
[] = {
43 #define DEBUG_COLORLEVEL 32u
45 PT_THREAD(program_showcfg(struct process_t
*process
))
47 static uint16_t sleep
;
48 static struct rgb_color_t c
, d
;
51 PT_BEGIN(&process
->pt
);
53 c
.red
= (remote_address() & 0x01u
) ? DEBUG_COLORLEVEL
: 0;
54 c
.green
= (remote_address() & 0x02u
) ? DEBUG_COLORLEVEL
: 0;
55 c
.blue
= (remote_address() & 0x04u
) ? DEBUG_COLORLEVEL
: 0;
57 d
.red
= d
.green
= d
.blue
= DEBUG_COLORLEVEL
;
59 global_pwm
.target
.rgb
= c
;
61 for (i
= 0; i
< 3u; i
++)
63 /* sleep 1s (remember: we are called every 100ms) */
66 PT_YIELD(&process
->pt
);
68 global_pwm
.target
.rgb
= d
;
72 PT_YIELD(&process
->pt
);
74 global_pwm
.target
.rgb
= c
;
77 /* now start default script */
78 if (storage_valid_config() && (startup_config
.params
.mode
== STARTUP_PROGRAM
)) {
79 script_start(0, startup_config
.params
.program
, (union program_params_t
*)startup_config
.params
.program_parameters
);
81 script_start_default();
87 PT_THREAD(program_colorwheel(struct process_t
*process
))
89 static uint16_t sleep
;
90 static struct hsv_color_t c
;
92 PT_BEGIN(&process
->pt
);
94 c
.hue
= process
->params
.colorwheel
.hue_start
;
95 c
.value
= process
->params
.colorwheel
.value
;
96 c
.saturation
= process
->params
.colorwheel
.saturation
;
98 int8_t add
= process
->params
.colorwheel
.add_addr
;
99 c
.hue
+= remote_address() * add
* process
->params
.colorwheel
.hue_step
;
103 pwm_fade_hsv(&c
, process
->params
.colorwheel
.fade_step
, process
->params
.colorwheel
.fade_delay
);
105 c
.hue
+= process
->params
.colorwheel
.hue_step
;
107 /* wait until target reached */
108 PT_WAIT_UNTIL(&process
->pt
, pwm_target_reached());
110 /* sleep (in seconds, remember: we are called every 100ms) */
111 sleep
= 10 * process
->params
.colorwheel
.fade_sleep
;
113 PT_YIELD(&process
->pt
);
116 PT_END(&process
->pt
);
119 PT_THREAD(program_random(struct process_t
*process
))
121 static uint16_t sleep
;
122 static struct hsv_color_t c
;
124 PT_BEGIN(&process
->pt
);
126 /* initialize random generator */
127 uint16_t seed
= process
->params
.random
.seed
;
128 if (process
->params
.random
.use_address
)
129 seed
^= remote_address();
132 c
.value
= process
->params
.random
.value
;
133 c
.saturation
= process
->params
.random
.saturation
;
136 /* generate new color */
137 union uint32_t_access rnd
;
140 /* use lower word for hue */
143 /* check for minimal color distance, regenerate random if not */
144 int16_t min_distance
= process
->params
.random
.min_distance
;
146 int16_t distance
= c
.hue
- rnd
.words
[0];
148 distance
= -distance
;
151 distance
= 360-distance
;
153 if (distance
< min_distance
)
157 /* copy color to structure */
158 c
.hue
= rnd
.words
[0];
160 /* fade to new color */
161 pwm_fade_hsv(&c
, process
->params
.random
.fade_step
, process
->params
.random
.fade_delay
);
163 /* wait until target reached */
164 if (process
->params
.random
.wait_for_fade
)
165 PT_WAIT_UNTIL(&process
->pt
, pwm_target_reached());
167 /* sleep (remember: we are called every 100ms) */
168 if (process
->params
.random
.fade_sleep
> 0) {
169 sleep
= process
->params
.random
.fade_sleep
;
172 PT_YIELD(&process
->pt
);
176 PT_END(&process
->pt
);
179 PT_THREAD(program_replay(struct process_t
*process
))
186 static struct storage_color_t c
;
188 PT_BEGIN(&process
->pt
);
190 /* reset variables */
191 pos
= process
->params
.replay
.start
;
195 /* load next color value */
196 storage_load_color(pos
, &c
);
198 if (c
.color
.rgb_marker
== 0xff) {
199 struct rgb_color_t color
;
200 color
.red
= c
.color
.red
;
201 color
.green
= c
.color
.green
;
202 color
.blue
= c
.color
.blue
;
204 pwm_fade_rgb(&color
, c
.step
, c
.delay
);
206 struct hsv_color_t color
;
207 color
.hue
= c
.color
.hue
;
208 color
.saturation
= c
.color
.saturation
;
209 color
.value
= c
.color
.value
;
211 pwm_fade_hsv(&color
, c
.step
, c
.delay
);
215 if (direction
== UP
) {
216 /* check for upper end */
217 if (pos
== process
->params
.replay
.end
) {
218 switch (process
->params
.replay
.repeat
) {
219 case REPEAT_NONE
: PT_EXIT(&process
->pt
);
221 case REPEAT_START
: pos
= process
->params
.replay
.start
;
223 case REPEAT_REVERSE
: direction
= DOWN
;
230 if (pos
== process
->params
.replay
.start
) {
239 PT_YIELD(&process
->pt
);
242 PT_END(&process
->pt
);