use bitmask for direction
This commit is contained in:
parent
8d8a50a4f7
commit
fa8bc109cd
26
democode.c
26
democode.c
@ -24,7 +24,6 @@
|
||||
|
||||
struct dm001data {
|
||||
uint8_t pos;
|
||||
uint8_t dir;
|
||||
uint16_t ramp;
|
||||
uint8_t decay[16][3];
|
||||
};
|
||||
@ -36,7 +35,6 @@ struct dm002data {
|
||||
struct dm003data {
|
||||
uint8_t step;
|
||||
uint8_t pos[3];
|
||||
uint8_t dir[3];
|
||||
};
|
||||
|
||||
union demodata {
|
||||
@ -56,13 +54,14 @@ 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]);
|
||||
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], 4, dm->decay[pos]);
|
||||
|
||||
uint8_t chan;
|
||||
for (chan = 0; chan < 16; chan++) {
|
||||
if (chan != dm->pos) {
|
||||
if (chan != pos) {
|
||||
color_sub(chan_value[chan], dm->decay[chan], chan_value[chan]);
|
||||
}
|
||||
}
|
||||
@ -100,12 +99,12 @@ static uint16_t demomode003(void)
|
||||
|
||||
for (color = 0; color < 3; color++) {
|
||||
if (dm->step == 0) {
|
||||
dm->pos[color] = sequence_chase(dm->pos[color], &dm->dir[color], nvram_data.channels);
|
||||
dm->pos[color] = sequence_chase(dm->pos[color], nvram_data.channels);
|
||||
}
|
||||
|
||||
uint8_t chan;
|
||||
for (chan = 0; chan < 16; chan++) {
|
||||
if (chan == dm->pos[color]) {
|
||||
if (chan == (dm->pos[color] & POS_MASK)) {
|
||||
chan_value[chan][color] = 0xFF;
|
||||
} else if (chan_value[chan][color] > 16) {
|
||||
chan_value[chan][color] -= 16;
|
||||
@ -134,7 +133,7 @@ void demomode_init(uint8_t mode)
|
||||
|
||||
case 0x01:
|
||||
/* rgb chase */
|
||||
demo.dm001.dir = 1;
|
||||
demo.dm001.pos = DIR_UP | 0;
|
||||
demomode_run = demomode001;
|
||||
break;
|
||||
|
||||
@ -145,12 +144,9 @@ void demomode_init(uint8_t mode)
|
||||
|
||||
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;
|
||||
demo.dm003.pos[COLOR_RED] = DIR_UP | 0;
|
||||
demo.dm003.pos[COLOR_GREEN] = DIR_UP | 9;
|
||||
demo.dm003.pos[COLOR_BLUE] = DIR_DOWN | 9;
|
||||
demomode_run = demomode003;
|
||||
break;
|
||||
|
||||
|
17
demohelper.c
17
demohelper.c
@ -22,21 +22,22 @@
|
||||
#include <string.h>
|
||||
#include "rgb16mpm.h"
|
||||
|
||||
uint8_t sequence_chase(uint8_t old_value, uint8_t *dir, uint16_t mask)
|
||||
uint8_t sequence_chase(uint8_t old_pos, uint16_t mask)
|
||||
{
|
||||
uint8_t value = old_value;
|
||||
uint8_t pos = (old_pos & POS_MASK);
|
||||
uint8_t dir = (old_pos & DIR_MASK);
|
||||
|
||||
do {
|
||||
value = (*dir) ? value +1 : value -1;
|
||||
value &= 0x0F;
|
||||
pos = (dir == DIR_DOWN) ? pos -1 : pos +1;
|
||||
pos &= 0x0F;
|
||||
|
||||
if (value == 0x00 || value == 0x0F) {
|
||||
*dir = (value == 0x00);
|
||||
if (pos == 0x00 || pos == 0x0F) {
|
||||
dir = (pos == 0x00) ? DIR_UP : DIR_DOWN;
|
||||
}
|
||||
|
||||
} while (!((1<<value) & mask) || value == old_value);
|
||||
} while (!((1<<pos) & mask) || pos == (old_pos & ~(DIR_MASK)));
|
||||
|
||||
return value;
|
||||
return dir | pos;
|
||||
}
|
||||
|
||||
uint16_t color_ramp(uint16_t value, uint8_t *color)
|
||||
|
12
rgb16mpm.h
12
rgb16mpm.h
@ -58,8 +58,14 @@ void demomode_init(uint8_t mode);
|
||||
extern uint16_t (*demomode_run)(void);
|
||||
|
||||
/* demohelper.c funcs */
|
||||
uint8_t sequence_chase(uint8_t old_value, uint8_t *dir, uint16_t mask);
|
||||
uint16_t color_ramp(uint16_t value, uint8_t *color);
|
||||
uint8_t sequence_chase(uint8_t old_value, uint16_t mask);
|
||||
|
||||
#define POS_MASK 0x7F
|
||||
#define DIR_MASK 0x80
|
||||
#define DIR_UP 0x80
|
||||
#define DIR_DOWN 0x00
|
||||
uint16_t color_ramp(uint16_t pos, uint8_t *color);
|
||||
|
||||
void color_add(uint8_t *color1, uint8_t *color2, uint8_t *output);
|
||||
void color_sub(uint8_t *color1, uint8_t *color2, uint8_t *output);
|
||||
void color_div(uint8_t *color, uint8_t div, uint8_t *output);
|
||||
@ -73,10 +79,10 @@ extern uint8_t chan_value[16][3];
|
||||
|
||||
/* rgbctrl.c funcs */
|
||||
void rgb_init(void);
|
||||
uint8_t rgb_update(uint8_t dirty_mask, uint8_t update_mode);
|
||||
|
||||
#define UPDATE_NONE 0x00
|
||||
#define UPDATE_PARTIAL 0x01
|
||||
#define UPDATE_BLOCKING 0x02
|
||||
uint8_t rgb_update(uint8_t dirty_mask, uint8_t update_mode);
|
||||
|
||||
#endif /* _RGB16MPM_H_ */
|
||||
|
Loading…
Reference in New Issue
Block a user