aboutsummaryrefslogtreecommitdiff
path: root/main/ws2812b_writer.c
diff options
context:
space:
mode:
authorJosh Rahm <joshuarahm@gmail.com>2021-11-30 23:50:53 -0700
committerJosh Rahm <joshuarahm@gmail.com>2021-11-30 23:50:53 -0700
commitd89195e2144df51ca02a860f4b46fd38b4dfeb29 (patch)
treebf94208b2538c8039729f7b30a7dd5504ebf7fb2 /main/ws2812b_writer.c
parent6df4a4ed74621ce5df26791b84b9157902aeaa83 (diff)
downloadesp32-ws2812b-d89195e2144df51ca02a860f4b46fd38b4dfeb29.tar.gz
esp32-ws2812b-d89195e2144df51ca02a860f4b46fd38b4dfeb29.tar.bz2
esp32-ws2812b-d89195e2144df51ca02a860f4b46fd38b4dfeb29.zip
Reorganize tasks into their own files.
Diffstat (limited to 'main/ws2812b_writer.c')
-rw-r--r--main/ws2812b_writer.c54
1 files changed, 54 insertions, 0 deletions
diff --git a/main/ws2812b_writer.c b/main/ws2812b_writer.c
new file mode 100644
index 0000000..fc3c777
--- /dev/null
+++ b/main/ws2812b_writer.c
@@ -0,0 +1,54 @@
+#include "ws2812b_writer.h"
+
+#include <stdlib.h>
+#include <string.h>
+
+#define SIZE 300
+
+void calculate_colors(
+ ws_params_t* ws_params,
+ ws2812b_buffer_t* buffer)
+{
+ /* RACE Conditions for sure. Need to fix that. */
+ ws2812b_rgb_t color = {0};
+ if (!strcmp(ws_params->color, "black\n")) {
+ } else if (!strcmp(ws_params->color, "green\n")) {
+ color.g = 255;
+ } else if (!strcmp(ws_params->color, "red\n")) {
+ color.r = 255;
+ } else if (!strcmp(ws_params->color, "blue\n")) {
+ color.b = 255;
+ } else if (!strcmp(ws_params->color, "yellow\n")) {
+ color.r = 255;
+ color.g = 255;
+ } else if (!strcmp(ws_params->color, "magenta\n")) {
+ color.r = 255;
+ color.b = 255;
+ } else if (!strcmp(ws_params->color, "teal\n")) {
+ color.g = 255;
+ color.b = 255;
+ } else {
+ color.r = 128;
+ color.g = 128;
+ color.b = 128;
+ }
+
+ int i;
+ for (i = 0; i < SIZE; ++i) {
+ ws2812b_buffer_set_color(buffer, i, &color);
+ }
+}
+
+portTASK_FUNCTION(ws2812b_write_task, params)
+{
+ ws_params_t* ws_params = (ws_params_t*) params;
+
+ strcpy(ws_params->color, "red\n");
+
+ ws2812b_buffer_t* buffer = ws2812b_new_buffer(SIZE);
+ for (;;) {
+ calculate_colors(ws_params, buffer);
+ ws2812b_write(ws_params->drv, buffer);
+ vTaskDelay(10 / portTICK_PERIOD_MS);
+ }
+}