MPM controlled 16ch RGB LED dimmer
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

162 lines
4.7 KiB

/***************************************************************************
* 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 {
uint8_t pos;
uint8_t dir;
uint16_t ramp;
uint8_t decay[16][3];
};
struct dm002data {
uint16_t ramp;
};
struct dm003data {
uint8_t step;
uint8_t pos[3];
uint8_t dir[3];
};
union demodata {
struct dm001data dm001;
struct dm002data dm002;
struct dm003data dm003;
};
static union demodata demo;
static uint16_t demomode000(void)
{
return 0;
}
static uint16_t demomode001(void)
{
struct dm001data *dm = &demo.dm001;
dm->pos = sequence_chase(dm->pos, &dm->dir, nvram_data.channels);
dm->ramp = color_ramp(dm->ramp +8, chan_value[dm->pos]);
color_div(chan_value[dm->pos], 4, dm->decay[dm->pos]);
uint8_t chan;
for (chan = 0; chan < 16; chan++) {
if (chan != dm->pos) {
color_sub(chan_value[chan], dm->decay[chan], chan_value[chan]);
}
}
return 50;
}
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];
}
return 0;
}
static uint16_t demomode003(void)
{
struct dm003data *dm = &demo.dm003;
uint8_t color;
dm->step++;
if (dm->step == 2) {
dm->step = 0;
}
for (color = 0; color < 3; color++) {
if (dm->step == 0) {
dm->pos[color] = sequence_chase(dm->pos[color], &dm->dir[color], nvram_data.channels);
}
uint8_t chan;
for (chan = 0; chan < 16; chan++) {
if (chan == dm->pos[color]) {
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:
/* rgb chase */
demo.dm001.dir = 1;
demomode_run = demomode001;
break;
case 0x02:
/* one color, all channes, rgb fader */
demomode_run = demomode002;
break;
case 0x03:
/* three color chaser */
demo.dm003.pos[COLOR_RED] = 0;
demo.dm003.pos[COLOR_GREEN] = 9;
demo.dm003.pos[COLOR_BLUE] = 9;
demo.dm003.dir[COLOR_RED] = 1;
demo.dm003.dir[COLOR_GREEN] = 1;
demo.dm003.dir[COLOR_BLUE] = 0;
demomode_run = demomode003;
break;
default:
/* stay black */
demomode_run = demomode000;
break;
}
}