forked from schneider42/moodlamp-rf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstatic_scripts.h
146 lines (118 loc) · 4.02 KB
/
static_scripts.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
/* vim:fdm=marker ts=4 et ai
* {{{
* moodlamp-ng - fnordlicht firmware next generation
*
* for additional information please
* see http://blinkenlichts.net/
* and http://koeln.ccc.de/prozesse/running/fnordlicht
*
* This is a modified version of the fnordlicht
* (c) by Alexander Neumann <[email protected]>
* Lars Noschinski <[email protected]>
*
* Modifications done by Tobias Schneider([email protected])
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* For more information on the GPL, please go to:
* http://www.gnu.org/copyleft/gpl.html
}}} */
#ifndef fnordlicht_static_script_h
#define fnordlicht_static_script_h
#include "config.h"
#if STATIC_SCRIPTS
#include "common.h"
#include <avr/io.h>
#include <stdint.h>
#include <avr/eeprom.h>
#define MAX_THREAD_STACK_DEPTH 3
#define MAX_THREADS 1
/* opcodes */
/* {{{ */
#define OP_RND_CHANNEL 0x00
#define OP_FADE_CHANNEL 0x10
#define OP_FADE_CHANNELS 0x20
#define OP_JUMP 0x30
#define OP_SET_CHANNEL 0x40
#define OP_SLEEP 0x50
#define OP_WAIT 0x60
#define OP_CLEAR 0x70
#define OP_STOP 0x80
/* }}} */
/* opcode macros */
/* {{{ */
#define MACRO_RND_CHANNEL(channel, speed_l_min, speed_h_max) \
OP_RND_CHANNEL, channel, speed_l_min, speed_h_max
#define MACRO_FADE_CHANNEL(channel, target_brightness, speed) \
(OP_FADE_CHANNEL | channel), target_brightness, LOW(speed), HIGH(speed)
#define MACRO_FADE_CHANNELS(brightness1, brightness2, brightness3) \
OP_FADE_CHANNELS, brightness1, brightness2, brightness3
#define MACRO_JUMP(offset) \
OP_JUMP, offset, 0, 0
#define MACRO_SET_CHANNEL(channel, target_brightness) \
OP_SET_CHANNEL, channel, target_brightness, 0
#define MACRO_SLEEP(delay_cycles) \
OP_SLEEP, LOW(delay_cycles), HIGH(delay_cycles), 0
#define MACRO_WAIT(eventmask) \
OP_WAIT, eventmask, 0, 0
#define MACRO_CLEAR() \
OP_CLEAR, 0, 0, 0
#define MACRO_STOP() \
OP_STOP, 0, 0, 0
/* }}} */
/* opcode function return values */
/* {{{ */
#define OP_RETURN_OK 0 /* do nothing */
#define OP_RETURN_BREAK 1 /* execution has been completed for this cycle, jump to next thread */
#define OP_RETURN_STOP 2 /* disable this script */
/* }}} */
/* workaround prototype for handler 'execute' function definition */
struct thread_t;
/* structs */
struct script_handler_t
/* {{{ */ {
void (*execute)(struct thread_t *current_thread);
uint16_t position;
uint8_t opcode;
}; /* }}} */
struct thread_t
/* {{{ */ {
struct script_handler_t handler;
struct {
uint8_t channel_target_reached:PWM_CHANNELS; /* these channels reached their target brightness value lately */
uint8_t disabled:1; /* disable execution of this thread */
} flags;
struct script_handler_t handler_stack[MAX_THREAD_STACK_DEPTH];
uint8_t handler_stack_offset;
#if SCRIPT_SPEED_CONTROL
int8_t speed_adjustment;
uint16_t wait_speed_orig;
#endif
}; /* }}} */
struct playlist_t
{
void (*execute)(struct thread_t *current_thread);
uint16_t position;
};
/* global variables */
struct thread_t script_threads[MAX_THREADS];
/* prototypes */
void init_script_threads(void);
void execute_script_threads(void);
/* memory handlers */
void memory_handler_flash(struct thread_t *current_thread);
void memory_handler_eeprom(struct thread_t *current_thread);
void respeed(struct thread_t *current_thread);
#endif
#endif