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
|
/*
* Copyright 2012 (C) Christian Franke <nobody at nowhere dot ws>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* 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, see <http://www.gnu.org/licenses/>.
*
*/
#include <stdint.h>
#include "sequencer.h"
#include "pwm.h"
#include "shiftbrite.h"
struct sequencer_entry {
uint8_t len;
uint8_t lamp;
uint8_t red;
uint8_t blue;
uint8_t green;
};
volatile static uint8_t seq_enabled = 0; /* whether to process sequencer or not */
volatile static uint8_t seq_pos; /* pending slot to execute */
volatile static uint8_t seq_timeout; /* timeout for progress to next slot */
volatile static struct sequencer_entry seq_slots[64]; /* the actual slots */
volatile static uint8_t seq_len; /* the number of slots */
static void sequencer_progress(uint8_t pos)
{
if (seq_slots[pos].lamp) {
sb_setcolor(seq_slots[pos].lamp - 1, seq_slots[pos].red,
seq_slots[pos].green, seq_slots[pos].blue);
} else {
pwm_set_rgb(seq_slots[pos].red, seq_slots[pos].green,
seq_slots[pos].blue);
}
seq_timeout = seq_slots[pos].len;
seq_pos = pos + 1;
if (seq_pos >= seq_len)
seq_pos = 0;
}
void sequencer_set(uint8_t step, uint8_t len, uint8_t lamp,
uint8_t r, uint8_t g, uint8_t b)
{
if (step >= 64)
return;
seq_slots[step].len = len;
seq_slots[step].lamp = lamp;
seq_slots[step].red = r;
seq_slots[step].green = g;
seq_slots[step].blue = b;
}
void sequencer_len(uint8_t len)
{
seq_len = len;
}
void sequencer_enable(void)
{
sequencer_progress(0);
seq_enabled = 1;
}
void sequencer_disable(void)
{
seq_enabled = 0;
}
void sequencer_tick(void)
{
while (seq_enabled && !(--seq_timeout)) {
sequencer_progress(seq_pos);
}
}
|