rgb16mpm/democode.c

198 lines
5.3 KiB
C
Raw Normal View History

2012-03-11 15:49:41 +01:00
/***************************************************************************
* some RGB demo modes *
* *
* Copyright (C) 2011 - 2012 by Olaf Rempel *
* razzor AT kopf MINUS tisch DOT de *
* *
* 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; version 2 of the License, *
* *
* 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., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#include <stdint.h>
#include <string.h>
#include "rgb16mpm.h"
struct dm001data {
2019-08-11 11:34:34 +02:00
uint8_t color;
2012-03-11 15:49:41 +01:00
uint8_t pos;
};
struct dm002data {
uint16_t ramp;
};
struct dm003data {
2019-08-11 11:34:34 +02:00
uint8_t pos;
uint16_t ramp;
uint8_t decay[16][3];
};
struct dm004data {
2012-03-11 15:49:41 +01:00
uint8_t step;
uint8_t pos[3];
};
union demodata {
struct dm001data dm001;
struct dm002data dm002;
struct dm003data dm003;
2019-08-11 11:34:34 +02:00
struct dm004data dm004;
2012-03-11 15:49:41 +01:00
};
static union demodata demo;
static uint16_t demomode000(void)
{
return 0;
}
static uint16_t demomode001(void)
{
struct dm001data *dm = &demo.dm001;
2019-08-11 11:34:34 +02:00
dm->pos = sequence_chase(dm->pos, nvram_data.channels);
2012-03-11 16:01:40 +01:00
uint8_t pos = dm->pos & POS_MASK;
2012-03-11 15:49:41 +01:00
uint8_t chan;
for (chan = 0; chan < 16; chan++) {
2012-03-11 16:01:40 +01:00
if (chan != pos) {
2019-08-11 11:34:34 +02:00
chan_value[chan][COLOR_RED] = 0x00;
chan_value[chan][COLOR_GREEN] = 0x00;
chan_value[chan][COLOR_BLUE] = 0x00;
} else {
chan_value[chan][dm->color] = 0xFF;
2012-03-11 15:49:41 +01:00
}
}
2019-08-11 11:34:34 +02:00
if (pos == 0) {
dm->color++;
if (dm->color == 3) {
dm->color = 0;
}
}
return 250;
2012-03-11 15:49:41 +01:00
}
static uint16_t demomode002(void)
{
struct dm002data *dm = &demo.dm002;
uint8_t color[3];
dm->ramp = color_ramp(dm->ramp +1, color);
uint8_t chan;
for (chan = 0; chan < 16; chan++) {
chan_value[chan][COLOR_RED] = color[COLOR_RED];
chan_value[chan][COLOR_GREEN] = color[COLOR_GREEN];
chan_value[chan][COLOR_BLUE] = color[COLOR_BLUE];
}
2019-08-11 11:34:34 +02:00
return 50;
2012-03-11 15:49:41 +01:00
}
static uint16_t demomode003(void)
{
struct dm003data *dm = &demo.dm003;
2019-08-11 11:34:34 +02:00
dm->pos = sequence_chase(dm->pos, nvram_data.channels);
uint8_t pos = dm->pos & POS_MASK;
dm->ramp = color_ramp(dm->ramp +8, chan_value[pos]);
color_div(chan_value[pos], 8, dm->decay[pos]);
uint8_t chan;
for (chan = 0; chan < 16; chan++) {
if (chan != pos) {
color_sub(chan_value[chan], dm->decay[chan], chan_value[chan]);
}
}
return 50;
}
static uint16_t demomode004(void)
{
struct dm004data *dm = &demo.dm004;
2012-03-11 15:49:41 +01:00
uint8_t color;
dm->step++;
if (dm->step == 2) {
dm->step = 0;
}
for (color = 0; color < 3; color++) {
if (dm->step == 0) {
2012-03-11 16:01:40 +01:00
dm->pos[color] = sequence_chase(dm->pos[color], nvram_data.channels);
2012-03-11 15:49:41 +01:00
}
uint8_t chan;
for (chan = 0; chan < 16; chan++) {
2012-03-11 16:01:40 +01:00
if (chan == (dm->pos[color] & POS_MASK)) {
2012-03-11 15:49:41 +01:00
chan_value[chan][color] = 0xFF;
} else if (chan_value[chan][color] > 16) {
chan_value[chan][color] -= 16;
} else {
chan_value[chan][color] = 0;
}
}
}
return 50;
}
uint16_t (* demomode_run)(void) = demomode000;
void demomode_init(uint8_t mode)
{
memset(&demo, 0x00, sizeof(union demodata));
memset(chan_value, 0x00, sizeof(chan_value));
switch (mode) {
case 0x00:
/* load initial values from eeprom */
memcpy(chan_value, nvram_data.initialRGB, sizeof(chan_value));
demomode_run = demomode000;
break;
case 0x01:
demomode_run = demomode001;
break;
case 0x02:
/* one color, all channes, rgb fader */
demomode_run = demomode002;
break;
case 0x03:
2019-08-11 11:34:34 +02:00
/* rgb chase */
demo.dm003.pos = DIR_UP | 0;
2012-03-11 15:49:41 +01:00
demomode_run = demomode003;
break;
2019-08-11 11:34:34 +02:00
case 0x04:
/* three color chaser */
demo.dm004.pos[COLOR_RED] = DIR_UP | 0;
demo.dm004.pos[COLOR_GREEN] = DIR_UP | 9;
demo.dm004.pos[COLOR_BLUE] = DIR_DOWN | 9;
demomode_run = demomode004;
break;
2012-03-11 15:49:41 +01:00
default:
/* stay black */
demomode_run = demomode000;
break;
}
}