diff --git a/democode.c b/democode.c index e79b16c..7eef768 100644 --- a/democode.c +++ b/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; diff --git a/demohelper.c b/demohelper.c index 0e98918..c07f7b1 100644 --- a/demohelper.c +++ b/demohelper.c @@ -22,21 +22,22 @@ #include #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<