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 PT_THREAD(program_showcfg(struct process_t
*process
))
45 static uint16_t sleep
;
46 struct rgb_color_t c
, d
;
48 PT_BEGIN(&process
->pt
);
50 c
.red
= (remote_address() & 0x01u
) * 128u;
51 c
.green
= (remote_address() & 0x02u
) * 128u;
52 c
.blue
= (remote_address() & 0x04u
) * 128u;
54 d
.red
= d
.green
= d
.blue
= 128u;
56 pwm_fade_rgb(&d
, 0xffu
, 0);
58 PT_WAIT_UNTIL(&process
->pt
, pwm_target_reached());
60 /* sleep .5s (remember: we are called every 100ms) */
63 PT_YIELD(&process
->pt
);
65 pwm_fade_rgb(&c
, 0xffu
, 0);
67 PT_WAIT_UNTIL(&process
->pt
, pwm_target_reached());
69 /* sleep 1s (remember: we are called every 100ms) */
72 PT_YIELD(&process
->pt
);
73 pwm_fade_rgb(&d
, 0xffu
, 0);
75 PT_WAIT_UNTIL(&process
->pt
, pwm_target_reached());
77 /* sleep .5s (remember: we are called every 100ms) */
80 PT_YIELD(&process
->pt
);
82 pwm_fade_rgb(&c
, 0xffu
, 0);
84 PT_WAIT_UNTIL(&process
->pt
, pwm_target_reached());
86 /* sleep 1s (remember: we are called every 100ms) */
89 PT_YIELD(&process
->pt
);
91 /* now start default script */
92 if (storage_valid_config() && (startup_config
.params
.mode
== STARTUP_PROGRAM
)) {
93 script_start(0, startup_config
.params
.program
, (union program_params_t
*)startup_config
.params
.program_parameters
);
95 script_start_default();
101 PT_THREAD(program_colorwheel(struct process_t
*process
))
103 static uint16_t sleep
;
104 static struct hsv_color_t c
;
106 PT_BEGIN(&process
->pt
);
108 c
.hue
= process
->params
.colorwheel
.hue_start
;
109 c
.value
= process
->params
.colorwheel
.value
;
110 c
.saturation
= process
->params
.colorwheel
.saturation
;
112 int8_t add
= process
->params
.colorwheel
.add_addr
;
113 c
.hue
+= remote_address() * add
* process
->params
.colorwheel
.hue_step
;
117 pwm_fade_hsv(&c
, process
->params
.colorwheel
.fade_step
, process
->params
.colorwheel
.fade_delay
);
119 c
.hue
+= process
->params
.colorwheel
.hue_step
;
121 /* wait until target reached */
122 PT_WAIT_UNTIL(&process
->pt
, pwm_target_reached());
124 /* sleep (in seconds, remember: we are called every 100ms) */
125 sleep
= 10 * process
->params
.colorwheel
.fade_sleep
;
127 PT_YIELD(&process
->pt
);
130 PT_END(&process
->pt
);
133 PT_THREAD(program_random(struct process_t
*process
))
135 static uint16_t sleep
;
136 static struct hsv_color_t c
;
138 PT_BEGIN(&process
->pt
);
140 /* initialize random generator */
141 uint16_t seed
= process
->params
.random
.seed
;
142 if (process
->params
.random
.use_address
)
143 seed
^= remote_address();
146 c
.value
= process
->params
.random
.value
;
147 c
.saturation
= process
->params
.random
.saturation
;
150 /* generate new color */
151 union uint32_t_access rnd
;
154 /* use lower word for hue */
157 /* check for minimal color distance, regenerate random if not */
158 int16_t min_distance
= process
->params
.random
.min_distance
;
160 int16_t distance
= c
.hue
- rnd
.words
[0];
162 distance
= -distance
;
165 distance
= 360-distance
;
167 if (distance
< min_distance
)
171 /* copy color to structure */
172 c
.hue
= rnd
.words
[0];
174 /* fade to new color */
175 pwm_fade_hsv(&c
, process
->params
.random
.fade_step
, process
->params
.random
.fade_delay
);
177 /* wait until target reached */
178 if (process
->params
.random
.wait_for_fade
)
179 PT_WAIT_UNTIL(&process
->pt
, pwm_target_reached());
181 /* sleep (remember: we are called every 100ms) */
182 if (process
->params
.random
.fade_sleep
> 0) {
183 sleep
= process
->params
.random
.fade_sleep
;
186 PT_YIELD(&process
->pt
);
190 PT_END(&process
->pt
);
193 PT_THREAD(program_replay(struct process_t
*process
))
200 static struct storage_color_t c
;
202 PT_BEGIN(&process
->pt
);
204 /* reset variables */
205 pos
= process
->params
.replay
.start
;
209 /* load next color value */
210 storage_load_color(pos
, &c
);
212 if (c
.color
.rgb_marker
== 0xff) {
213 struct rgb_color_t color
;
214 color
.red
= c
.color
.red
;
215 color
.green
= c
.color
.green
;
216 color
.blue
= c
.color
.blue
;
218 pwm_fade_rgb(&color
, c
.step
, c
.delay
);
220 struct hsv_color_t color
;
221 color
.hue
= c
.color
.hue
;
222 color
.saturation
= c
.color
.saturation
;
223 color
.value
= c
.color
.value
;
225 pwm_fade_hsv(&color
, c
.step
, c
.delay
);
229 if (direction
== UP
) {
230 /* check for upper end */
231 if (pos
== process
->params
.replay
.end
) {
232 switch (process
->params
.replay
.repeat
) {
233 case REPEAT_NONE
: PT_EXIT(&process
->pt
);
235 case REPEAT_START
: pos
= process
->params
.replay
.start
;
237 case REPEAT_REVERSE
: direction
= DOWN
;
244 if (pos
== process
->params
.replay
.start
) {
253 PT_YIELD(&process
->pt
);
256 PT_END(&process
->pt
);