diff options
author | Josh Rahm <joshuarahm@gmail.com> | 2022-12-01 22:44:20 -0700 |
---|---|---|
committer | Josh Rahm <joshuarahm@gmail.com> | 2022-12-01 22:44:20 -0700 |
commit | 10a5077234e9b76dc100b9029a9e2d71801e7242 (patch) | |
tree | 13e42a3c91f1672c6ce7b6daba776366aa71ef85 /main/ws2812b_writer.c | |
parent | 05e3f6bb7293c771629c7b3599392c8f335e7dd8 (diff) | |
download | esp32-ws2812b-10a5077234e9b76dc100b9029a9e2d71801e7242.tar.gz esp32-ws2812b-10a5077234e9b76dc100b9029a9e2d71801e7242.tar.bz2 esp32-ws2812b-10a5077234e9b76dc100b9029a9e2d71801e7242.zip |
Diffstat (limited to 'main/ws2812b_writer.c')
-rw-r--r-- | main/ws2812b_writer.c | 20 |
1 files changed, 9 insertions, 11 deletions
diff --git a/main/ws2812b_writer.c b/main/ws2812b_writer.c index 36fa666..3b90cd3 100644 --- a/main/ws2812b_writer.c +++ b/main/ws2812b_writer.c @@ -3,18 +3,19 @@ #include <stdlib.h> #include <string.h> -const int NUMBER_PARAMS = +const int NUMBER_PARAMS = #define STATE_PARAM(...) +1 #include "state_params.i" #undef STATE_PARAM -; + ; #define SIZE 300 /* Returns round(sin(2πn / 256) * 127.5 + 127.5). */ uint8_t byte_sin(uint8_t n); -static inline uint8_t byte_scale(uint8_t n, uint8_t sc) { +static inline uint8_t byte_scale(uint8_t n, uint8_t sc) +{ return n * sc / 255; } @@ -28,15 +29,12 @@ void reset_parameters(ws_params_t* params) { memset(¶ms->state, 0, sizeof(params->state)); -#define STATE_PARAM(type, attr, displ, def, ...) \ - params->state. attr = def; +#define STATE_PARAM(type, attr, displ, def, ...) params->state.attr = def; #include "state_params.i" #undef STATE_PARAM } -void calculate_colors( - ws_params_t* ws_params, - ws2812b_buffer_t* buffer) +void calculate_colors(ws_params_t* ws_params, ws2812b_buffer_t* buffer) { uint32_t red = 0, green = 0, blue = 0; int time; @@ -50,7 +48,8 @@ void calculate_colors( continue; } - red = byte_scale(byte_sin(time / 1000 + x * 4), 255 - ws_params->state.n_red) + + red = byte_scale( + byte_sin(time / 1000 + x * 4), 255 - ws_params->state.n_red) + ws_params->state.n_red; green = 255 - red; @@ -104,13 +103,12 @@ void calculate_colors( portTASK_FUNCTION(ws2812b_write_task, params) { - ws_params_t* ws_params = (ws_params_t*) params; + ws_params_t* ws_params = (ws_params_t*)params; reset_parameters(ws_params); ws2812b_buffer_t* buffer = ws2812b_new_buffer(SIZE); for (;;) { - // Copy the parameters to avoid a change occuring during the calculation. ws_params_t copy_params; memcpy(©_params, ws_params, sizeof(ws_params_t)); |