First completed version
This commit is contained in:
parent
6f9d1474c6
commit
1402dad8c3
@ -17,6 +17,7 @@ static void reset_rainbow_to_start(struct animation *ani)
|
|||||||
ani->rb_start_color.red = RAINBOW_MAX_COL;
|
ani->rb_start_color.red = RAINBOW_MAX_COL;
|
||||||
ani->rb_start_color.blue = 0u;
|
ani->rb_start_color.blue = 0u;
|
||||||
ani->rb_start_color.green = 0u;
|
ani->rb_start_color.green = 0u;
|
||||||
|
ani->rb_start_color.white = 0u;
|
||||||
}
|
}
|
||||||
|
|
||||||
void animation_reset(struct animation *ani)
|
void animation_reset(struct animation *ani)
|
||||||
@ -68,7 +69,7 @@ static enum animation_state next_col_state(enum animation_state current)
|
|||||||
* @param[in,out] current_state Current rainbow state
|
* @param[in,out] current_state Current rainbow state
|
||||||
* @param[in, out] col Current color
|
* @param[in, out] col Current color
|
||||||
*/
|
*/
|
||||||
static void rainbow_color_advance(enum rainbow_state *current_state, struct rgb_color *col)
|
static void rainbow_color_advance(enum rainbow_state *current_state, struct rgbw_color *col)
|
||||||
{
|
{
|
||||||
enum rainbow_state state;
|
enum rainbow_state state;
|
||||||
|
|
||||||
@ -134,7 +135,7 @@ static bool animation_rainbow(struct animation *ani, uint8_t *dmx_universe)
|
|||||||
{
|
{
|
||||||
bool ret = false;
|
bool ret = false;
|
||||||
enum rainbow_state led_state;
|
enum rainbow_state led_state;
|
||||||
struct rgb_color color;
|
struct rgbw_color color;
|
||||||
uint32_t idx;
|
uint32_t idx;
|
||||||
|
|
||||||
/* Get the start state of first led */
|
/* Get the start state of first led */
|
||||||
@ -146,7 +147,7 @@ static bool animation_rainbow(struct animation *ani, uint8_t *dmx_universe)
|
|||||||
dmx_universe[idx * 4 + 0] = color.red;
|
dmx_universe[idx * 4 + 0] = color.red;
|
||||||
dmx_universe[idx * 4 + 1] = color.green;
|
dmx_universe[idx * 4 + 1] = color.green;
|
||||||
dmx_universe[idx * 4 + 2] = color.blue;
|
dmx_universe[idx * 4 + 2] = color.blue;
|
||||||
dmx_universe[idx * 4 + 3] = 0u;
|
dmx_universe[idx * 4 + 3] = color.white;
|
||||||
|
|
||||||
/* Sdvance rainbow color */
|
/* Sdvance rainbow color */
|
||||||
rainbow_color_advance(&led_state, &color);
|
rainbow_color_advance(&led_state, &color);
|
||||||
|
@ -11,10 +11,11 @@ enum animation_state {
|
|||||||
ANI_FLASH_WHITE,
|
ANI_FLASH_WHITE,
|
||||||
};
|
};
|
||||||
|
|
||||||
struct rgb_color {
|
struct rgbw_color {
|
||||||
uint8_t red;
|
uint8_t red;
|
||||||
uint8_t green;
|
uint8_t green;
|
||||||
uint8_t blue;
|
uint8_t blue;
|
||||||
|
uint8_t white;
|
||||||
};
|
};
|
||||||
|
|
||||||
enum rainbow_state {
|
enum rainbow_state {
|
||||||
@ -29,7 +30,7 @@ enum rainbow_state {
|
|||||||
struct animation {
|
struct animation {
|
||||||
enum animation_state state;
|
enum animation_state state;
|
||||||
enum rainbow_state rb_start_state;
|
enum rainbow_state rb_start_state;
|
||||||
struct rgb_color rb_start_color;
|
struct rgbw_color rb_start_color;
|
||||||
uint32_t step;
|
uint32_t step;
|
||||||
uint32_t last_tick;
|
uint32_t last_tick;
|
||||||
uint32_t next_interval;
|
uint32_t next_interval;
|
||||||
|
78
main.c
78
main.c
@ -19,9 +19,9 @@ enum color_mode {
|
|||||||
MODE_BLUE,
|
MODE_BLUE,
|
||||||
MODE_RGB,
|
MODE_RGB,
|
||||||
MODE_WHITE_DISCRETE,
|
MODE_WHITE_DISCRETE,
|
||||||
MODE_WHITE_ANGLE,
|
|
||||||
MODE_RED_BLUE_RING,
|
|
||||||
MODE_ANIMATION,
|
MODE_ANIMATION,
|
||||||
|
MODE_GREEN_BLUE_ANGLE,
|
||||||
|
MODE_WHITE_ANGLE,
|
||||||
MODE_DMX_SHUTDOWN,
|
MODE_DMX_SHUTDOWN,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -66,12 +66,61 @@ static void setup_pins(void)
|
|||||||
GPIOB->PUPDR = PULLUP(1);
|
GPIOB->PUPDR = PULLUP(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static uint32_t map_index_to_range(int32_t index, uint32_t len)
|
||||||
|
{
|
||||||
|
int32_t mapped;
|
||||||
|
|
||||||
|
if (index < 0) {
|
||||||
|
mapped = len - (-index) % len;
|
||||||
|
} else {
|
||||||
|
mapped = index % len;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (uint32_t)mapped;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void dmx_universe_set_rgbw(uint32_t led_idx, const struct rgbw_color *col)
|
||||||
|
{
|
||||||
|
dmx_universe[led_idx * 4 + 0] = col->red;
|
||||||
|
dmx_universe[led_idx * 4 + 1] = col->green;
|
||||||
|
dmx_universe[led_idx * 4 + 2] = col->blue;
|
||||||
|
dmx_universe[led_idx * 4 + 3] = col->white;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void set_angle(uint32_t led_count, uint32_t pos, uint32_t width, const struct rgbw_color *col, const struct rgbw_color *rest)
|
||||||
|
{
|
||||||
|
int32_t lower_end;
|
||||||
|
int32_t upper_end;
|
||||||
|
int32_t idx;
|
||||||
|
int32_t mapped_idx;
|
||||||
|
|
||||||
|
if (width > led_count)
|
||||||
|
return;
|
||||||
|
|
||||||
|
upper_end = pos + width / 2u;
|
||||||
|
lower_end = pos - width / 2u;
|
||||||
|
|
||||||
|
/* Set leds to color */
|
||||||
|
for (idx = lower_end; idx <= upper_end; idx++) {
|
||||||
|
mapped_idx = map_index_to_range(idx, led_count);
|
||||||
|
dmx_universe_set_rgbw(mapped_idx, col);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Set the rest ring to rest color */
|
||||||
|
for (idx = upper_end + 1; idx < (upper_end + 1 + (led_count - width)); idx++) {
|
||||||
|
mapped_idx = map_index_to_range(idx, led_count);
|
||||||
|
dmx_universe_set_rgbw(mapped_idx, rest);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void process_mode(enum color_mode mode, const struct poti_values *poti_vals)
|
static void process_mode(enum color_mode mode, const struct poti_values *poti_vals)
|
||||||
{
|
{
|
||||||
uint32_t odr;
|
uint32_t odr;
|
||||||
static bool last_blink_state = false;
|
static bool last_blink_state = false;
|
||||||
bool blink_state;
|
bool blink_state;
|
||||||
int i;
|
int i;
|
||||||
|
struct rgbw_color col1 = {0, 0, 0, 0};
|
||||||
|
struct rgbw_color col2 = {0, 0, 0, 0};
|
||||||
|
|
||||||
odr = GPIOA->ODR;
|
odr = GPIOA->ODR;
|
||||||
odr &= ~((1<<5) | (1<<6) | (1<<7));
|
odr &= ~((1<<5) | (1<<6) | (1<<7));
|
||||||
@ -119,8 +168,25 @@ static void process_mode(enum color_mode mode, const struct poti_values *poti_va
|
|||||||
}
|
}
|
||||||
last_blink_state = blink_state;
|
last_blink_state = blink_state;
|
||||||
break;
|
break;
|
||||||
|
case MODE_GREEN_BLUE_ANGLE:
|
||||||
|
dmx_universe[128] = 0u;
|
||||||
|
odr |= (1<<5) | (1<<6) | (1<<7);
|
||||||
|
col1.blue = poti_vals->pot_vals_filtered[0];
|
||||||
|
col2.green = poti_vals->pot_vals_filtered[0];
|
||||||
|
set_angle(32u, (int32_t)poti_vals->pot_vals_filtered[1] * 32u / 255u,
|
||||||
|
(int32_t)poti_vals->pot_vals_filtered[2] * 32u / 255u, &col1, &col2);
|
||||||
|
break;
|
||||||
|
case MODE_WHITE_ANGLE:
|
||||||
|
dmx_universe[128] = 0u;
|
||||||
|
odr |= (1<<5) | (1<<6) | (1<<7);
|
||||||
|
col1.white = poti_vals->pot_vals_filtered[0];
|
||||||
|
col1.red = poti_vals->pot_vals_filtered[0];
|
||||||
|
col1.green = poti_vals->pot_vals_filtered[0];
|
||||||
|
col1.blue = poti_vals->pot_vals_filtered[0];
|
||||||
|
set_angle(32u, (int32_t)poti_vals->pot_vals_filtered[1] * 32u / 255u,
|
||||||
|
(int32_t)poti_vals->pot_vals_filtered[2] * 32u / 255u, &col1, &col2);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -230,6 +296,12 @@ int main(void)
|
|||||||
case 5:
|
case 5:
|
||||||
mode = MODE_WHITE_DISCRETE;
|
mode = MODE_WHITE_DISCRETE;
|
||||||
break;
|
break;
|
||||||
|
case 6:
|
||||||
|
mode = MODE_WHITE_ANGLE;
|
||||||
|
break;
|
||||||
|
case 7:
|
||||||
|
mode = MODE_GREEN_BLUE_ANGLE;
|
||||||
|
break;
|
||||||
case 8:
|
case 8:
|
||||||
animation_reset(&led_animation);
|
animation_reset(&led_animation);
|
||||||
mode = MODE_ANIMATION;
|
mode = MODE_ANIMATION;
|
||||||
|
Loading…
Reference in New Issue
Block a user