summaryrefslogtreecommitdiff
path: root/sequencer.c
diff options
context:
space:
mode:
Diffstat (limited to 'sequencer.c')
-rw-r--r--sequencer.c87
1 files changed, 87 insertions, 0 deletions
diff --git a/sequencer.c b/sequencer.c
new file mode 100644
index 0000000..f3b9d85
--- /dev/null
+++ b/sequencer.c
@@ -0,0 +1,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);
+ }
+}