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/>.
23 #include <avr/pgmspace.h>
27 #include "static_programs.h"
32 /* global variables */
33 struct global_script_t global_script
;
35 void script_init(void)
37 /* initialize global structures */
39 for (uint8_t i
= 0; i
< CONFIG_SCRIPT_TASKS
; i
++) {
40 global_script
.tasks
[i
].enable
= 0;
41 PT_INIT(&global_script
.tasks
[i
].pt
);
45 /* initialize timer, delay before start is 200ms */
46 timer_set(&global_script
.timer
, 20);
49 void script_start_default(void)
51 #ifdef CONFIG_SCRIPT_DEFAULT
52 #if CONFIG_SCRIPT_DEFAULT == 0
53 /* enable colorwheel program */
54 union program_params_t params
;
55 params
.colorwheel
.hue_start
= 0;
56 params
.colorwheel
.hue_step
= 60;
57 params
.colorwheel
.add_addr
= 0;
58 params
.colorwheel
.saturation
= 255;
59 params
.colorwheel
.value
= 255;
61 params
.colorwheel
.fade_step
= 1;
62 params
.colorwheel
.fade_delay
= 2;
63 params
.colorwheel
.fade_sleep
= 0;
65 script_start(0, 0, ¶ms
);
66 #elif CONFIG_SCRIPT_DEFAULT == 1
67 /* enable random program */
68 union program_params_t params
;
69 params
.random
.seed
= 23;
70 params
.random
.use_address
= 0;
71 params
.random
.wait_for_fade
= 1;
72 params
.random
.min_distance
= 60;
74 params
.random
.saturation
= 255;
75 params
.random
.value
= 255;
77 params
.random
.fade_step
= 1;
78 params
.random
.fade_delay
= 3;
79 params
.random
.fade_sleep
= 100;
81 script_start(0, 1, ¶ms
);
83 #warning "CONFIG_SCRIPT_DEFAULT has unknown value! No default program is started."
88 void script_poll(void)
90 if (global_script
.disable
)
93 if (timer_expired(&global_script
.timer
)) {
94 for (uint8_t i
= 0; i
< CONFIG_SCRIPT_TASKS
; i
++) {
95 struct process_t
*task
= &global_script
.tasks
[i
];
97 /* run task, disable if exited */
98 if (PT_SCHEDULE(task
->execute(task
)) == 0)
103 /* recall after 100ms */
104 timer_set(&global_script
.timer
, 10);
108 void script_stop(void)
111 for (uint8_t i
= 0; i
< CONFIG_SCRIPT_TASKS
; i
++) {
112 global_script
.tasks
[i
].enable
= false;
113 PT_INIT(&global_script
.tasks
[i
].pt
);
117 global_script
.disable
= true;
120 void script_start(uint8_t task
, uint8_t index
, union program_params_t
*params
)
122 /* check for valid index */
123 if (index
>= STATIC_PROGRAMS_LEN
)
127 global_script
.disable
= false;
129 /* copy params from pointer to task structure */
130 memcpy(&global_script
.tasks
[task
].params
, params
, sizeof(union program_params_t
));
132 /* load program handler */
133 global_script
.tasks
[task
].execute
= (program_handler
)pgm_read_word(&static_programs
[index
]);
136 global_script
.tasks
[task
].enable
= true;
139 timer_set(&global_script
.timer
, 10);