aboutsummaryrefslogtreecommitdiff
path: root/main/ws2812b_writer.c
diff options
context:
space:
mode:
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);
+ }
+}