summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gradient.h14
-rw-r--r--led_clear.c19
-rw-r--r--led_gradient.c214
-rw-r--r--led_info.h25
-rw-r--r--led_test.c28
-rw-r--r--makefile6
-rwxr-xr-xpush.sh2
-rw-r--r--shit.c95
8 files changed, 403 insertions, 0 deletions
diff --git a/gradient.h b/gradient.h
new file mode 100644
index 0000000..ea8635e
--- /dev/null
+++ b/gradient.h
@@ -0,0 +1,14 @@
+//program modes (I'll switch to an emum once I'm done)
+#define VIEW_MODE 0
+#define SELECT_MODE 1
+#define MODIFY_MODE 2
+#define MODIFY_R 3
+#define MODIFY_G 4
+#define MODIFY_B 5
+#define MODIFY_SIZE 6
+#define EXITED 7
+
+typedef struct splits {
+ unsigned int color;
+ unsigned int size;
+} segment_t;
diff --git a/led_clear.c b/led_clear.c
new file mode 100644
index 0000000..f723f2e
--- /dev/null
+++ b/led_clear.c
@@ -0,0 +1,19 @@
+#include <ws2811/ws2811.h>
+#include <stdio.h>
+
+#include "led_info.h"
+
+int main() {
+ printf("Clearing LED lights...\n");
+ ws2811_return_t ret;
+ if ((ret = ws2811_init(&ledstring)) != WS2811_SUCCESS) {
+ printf("Error initilizing ws8211 strip: %s\n", ws2811_get_return_t_str(ret));
+ return 1;
+ }
+ for(int i = 0; i < LED_COUNT; i++) {
+ ledstring.channel[0].leds[i] = 0;
+ }
+ ws2811_render(&ledstring);
+ ws2811_fini(&ledstring);
+ return 0;
+}
diff --git a/led_gradient.c b/led_gradient.c
new file mode 100644
index 0000000..40c3fc5
--- /dev/null
+++ b/led_gradient.c
@@ -0,0 +1,214 @@
+#include <stdio.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <ws2811/ws2811.h>
+#include <string.h>
+#include <ncurses.h>
+#include <wchar.h>
+
+#include "led_info.h"
+#include "gradient.h"
+
+void refresh_strip(ws2811_t *ledstring, segment_t *segments, unsigned int segment_amount) {
+ unsigned int s = 0;
+ unsigned int led;
+ for(; s < segment_amount; s++) {
+ for(; led < segments[s].size; led++) {
+ ledstring->channel[0].leds[led] = segments[s].color;
+ }
+ }
+ if(led < (LED_COUNT - 1)) {
+ for(; led < LED_COUNT; led++) {
+ ledstring->channel[0].leds[led] = segments[s].color;
+ }
+ }
+ ws2811_render(ledstring);
+}
+
+unsigned int find_starting_pos(segment_t *segments, unsigned int index) {
+ unsigned int position = 0;
+ for(int i = 0; i < position; i++) position += segments[i].size;
+ return(position);
+}
+
+int main() {
+
+ segment_t *segments = malloc(sizeof(segment_t)); //just start with one
+ segments[0].size = LED_COUNT - 1;
+
+ int prev_program_state = VIEW_MODE;
+ int program_state = VIEW_MODE;
+ int ui_selection = 0;
+ unsigned int i;
+ unsigned int starting_pos;
+ unsigned int segment_selection = 0;
+ unsigned int segment_quanity = 1;
+
+
+
+ int selection_state = 0; //just for asthetics
+
+ int user_key;
+
+ char *main_msg = "Press the arrow keys to select the segment, and enter to edit it.\nTo create new segments, select the segment you want to divide.\n";
+ char *modification_menu[6] = {
+ "Change red",
+ "Change green",
+ "Change blue",
+ "Change size",
+ "Subdivide (create segment)",
+ "Go back"
+ };
+ int modification_menu_items = 6;
+
+ for(;;) {
+ if(prev_program_state != program_state) {
+ switch(program_state) {
+ case MODIFY_MODE:
+ for(i = 0; i < modification_menu_items; i++) {
+ cbreak();
+ if(ui_selection = i) attron(A_STANDOUT);
+ printw("%s\n", modification_menu);
+ if(ui_selection = i) attroff(A_STANDOUT);
+ }
+ refresh();
+ break;
+ case MODIFY_R:
+ printw("Modifying red value.\n");
+ refresh();
+ break;
+ case MODIFY_G:
+ printw("Modifying green value.\n");
+ refresh();
+ break;
+ case MODIFY_B:
+ printw("Modifying blue value.\n");
+ refresh();
+ break;
+ case MODIFY_SIZE:
+ printw("Modifying size.\n");
+ refresh();
+ break;
+ case VIEW_MODE:
+ cbreak();
+ break;
+ case SELECT_MODE:
+ halfdelay(1);
+ break;
+ case EXITED:
+ for(i = 0; i < LED_COUNT; i++) {
+ ledstring.channel[0].leds[i] = 0;
+ }
+ ws2811_render(&ledstring);
+ ws2811_fini(&ledstring);
+ clear();
+ endwin();
+ printf("goodbye\n");
+ return 0;
+ break;
+ default:
+ break;
+ }
+ }
+
+ if((user_key = getch()) != ERR) {
+ switch(user_key) {
+
+ case KEY_LEFT:
+ switch(program_state) {
+ case VIEW_MODE:
+ program_state = SELECT_MODE;
+ segment_selection = segment_quanity;
+ break;
+ case SELECT_MODE:
+ if(segment_selection < segment_quanity) segment_selection++;
+ break;
+ default:
+ break;
+ }
+ break;
+
+ case KEY_RIGHT:
+ switch(program_state) {
+ case VIEW_MODE:
+ program_state = SELECT_MODE;
+ segment_selection = 0;
+ break;
+ case SELECT_MODE:
+ if(segment_selection > 0) segment_selection--;
+ break;
+ default:
+ break;
+ }
+ break;
+
+ case KEY_UP:
+ switch(program_state) {
+ case MODIFY_R:
+ if ((segments[segment_selection].color >> 16) < 0xff) segments[segment_selection].color += 0x10000;
+ break;
+ case MODIFY_G:
+ if ((segments[segment_selection].color >> 8 & 0xff) < 0xff) segments[segment_selection].color += 0x100;
+ break;
+ case MODIFY_B:
+ if ((segments[segment_selection].color & 0xff) < 0xff) segments[segment_selection].color += 1;
+ break;
+ case MODIFY_SIZE:
+ default:
+ break;
+ }
+ break;
+
+ case KEY_DOWN:
+ switch(program_state) {
+ default:
+ break;
+ }
+ break;
+
+ case KEY_ENTER:
+ switch(program_state) {
+ case VIEW_MODE:
+ program_state = SELECT_MODE;
+ default:
+ break;
+ }
+ break;
+
+ case 'q':
+ switch(program_state) {
+ case VIEW_MODE:
+ program_state = EXITED;
+ break;
+ case SELECT_MODE:
+ program_state = VIEW_MODE;
+ break;
+ case MODIFY_MODE:
+ program_state = SELECT_MODE;
+ break;
+ case MODIFY_R:
+ case MODIFY_G:
+ case MODIFY_B:
+ case MODIFY_SIZE:
+ program_state = MODIFY_MODE;
+ default:
+ break;
+ }
+ break;
+
+ default:
+ break;
+ }
+ prev_program_state = program_state;
+ }
+ else if(program_state = SELECT_MODE) {
+ starting_pos = find_starting_pos(segments, segment_selection);
+ for(i = starting_pos; i <= starting_pos + segments[segment_selection].size; i++) {
+ ledstring.channel[0].leds[i] = (selection_state ? (i % 2) : ((i+1) % 2)) ? 0xffffff : 0;
+ }
+ selection_state ? 0 : 1;
+ ws2811_render(&ledstring);
+ }
+ }
+ return 0;
+}
diff --git a/led_info.h b/led_info.h
new file mode 100644
index 0000000..bfa5b0c
--- /dev/null
+++ b/led_info.h
@@ -0,0 +1,25 @@
+#include <ws2811/ws2811.h>
+#define GPIO_PIN 18
+#define LED_COUNT 300
+#define STRIP_TYPE WS2812_STRIP
+#define DMA 10
+
+ws2811_t ledstring = {
+.freq = WS2811_TARGET_FREQ,
+.dmanum = DMA,
+.channel = {
+[0] = {
+ .gpionum = GPIO_PIN,
+ .count = LED_COUNT,
+ .invert = 0,
+ .brightness = 255,
+ .strip_type = STRIP_TYPE,
+},
+[1] = {
+ .gpionum = 0,
+ .count = 0,
+ .invert = 0,
+ .brightness = 0,
+ },
+ },
+};
diff --git a/led_test.c b/led_test.c
new file mode 100644
index 0000000..e5aa1f2
--- /dev/null
+++ b/led_test.c
@@ -0,0 +1,28 @@
+#include <ws2811/ws2811.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+#include "led_info.h"
+
+int main() {
+ ws2811_return_t ret;
+ if ((ret = ws2811_init(&ledstring)) != WS2811_SUCCESS) {
+ printf("Error initilizing ws2811 strip: %s\n", ws2811_get_return_t_str(ret));
+ return 1;
+ }
+ for(;;) {
+ for(int i = 0; i < LED_COUNT; i++) {
+ ledstring.channel[0].leds[i] = 0xff0000;
+ ws2811_render(&ledstring);
+ }
+ for(int i = 0; i < LED_COUNT; i++) {
+ ledstring.channel[0].leds[i] = 0x00ff00;
+ ws2811_render(&ledstring);
+ }
+ for(int i = 0; i < LED_COUNT; i++) {
+ ledstring.channel[0].leds[i] = 0x0000ff;
+ ws2811_render(&ledstring);
+ }
+ }
+}
diff --git a/makefile b/makefile
new file mode 100644
index 0000000..0591691
--- /dev/null
+++ b/makefile
@@ -0,0 +1,6 @@
+make tester:
+ gcc -o led_test led_test.c -lws2811 -lm
+make clear:
+ gcc -o led_clear led_clear.c -lws2811 -lm
+make grad:
+ gcc -o grad led_gradient.c -lws2811 -lm -lncurses
diff --git a/push.sh b/push.sh
new file mode 100755
index 0000000..a2ee8ae
--- /dev/null
+++ b/push.sh
@@ -0,0 +1,2 @@
+#!/usr/bin/bash
+printf "rm /root/projects/ledstrip/*\nput /home/indigo/projects/ledstrip/* /root/projects/ledstrip/" | sftp root@ledcontroller
diff --git a/shit.c b/shit.c
new file mode 100644
index 0000000..cca992b
--- /dev/null
+++ b/shit.c
@@ -0,0 +1,95 @@
+#include <stdio.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <ws2811/ws2811.h>
+#include <string.h>
+#include <ncurses.h>
+#include <wchar.h>
+
+#include "led_info.h"
+#include "gradient.h"
+
+
+void refresh_strip(ws2811_t *ledstring, split_t *splits, unsigned int split_amount) {
+ unsigned int on_led = 0;
+ for(unsigned int i = split_amount; i < split_amount; i++) {
+ for(; on_led < splits[i].size; on_led++) {
+ ledstring->channel[0].leds[on_led] = splits[i].color;
+ }
+ }
+ ws2811_render(&ledstring);
+}
+
+unsigned int find_starting_pos(split_t *split, unsigned int index) {
+ unsigned int position = 0;
+ for(int i = 0; i < position; i++) position += split[i].size;
+ return(position);
+}
+
+int main() {
+ split_t *splits = malloc(sizeof(split_t) * 1);
+ memcpy(splits, 0, sizeof(split_t));
+ unsigned int split_amount = 1;
+
+ int exited = 1;
+ int selection_mode = 0;
+ int section_highlighted = 0;
+ char usr_chr;
+ unsigned int selected_split = 0;
+ int selection_state = 0;
+ int ui_selection = 0;
+ unsigned int i = 0;
+ int modification_mode = 0;
+
+
+ char *usage_msg = "Press [n] to create a new split.\nSelect your section by pressing the arrow keys, and press enter to modify.\n";
+ char *newsplit_msg = "Press the arrow keys to select an option, and enter to modify.\nPress escape once done configuring.\n";
+
+ char *ui_segment_options[5] = {"Red", "Green", "Blue", "Subdivide", "Delete"};
+
+ ws2811_return_t ret;
+
+ if ((ret = ws2811_init(&ledstring)) != WS2811_SUCCESS) {
+ printf("Error initilizing ws2811 strip: %s\n", ws2811_get_return_t_str(ret));
+ return 1;
+ }
+
+ initscr();
+ cbreak();
+ noecho();
+
+
+ while(!exited) {
+ clear();
+ wprintf("%s", usage_msg);
+ if (selection_mode) {
+ halfdelay(10);
+ wprintf("Segment %i selected.\nPress enter to modify.", selected_split);
+ }
+ else if (modification_mode) {
+ cbreak();
+ wprintf("Segment %i selected.\nPress the arrow keys to navigate, and press enter on the action or value you wish to modify.");
+ }
+ else {
+ cbreak();
+ }
+ refresh();
+
+ printw("%s", usage_msg);
+ if((usr_chr = getch()) != ERR) {
+ switch(getch()) {
+ }
+
+ }
+ else {
+ // selection_mode is set, we've timed out
+ // TODO: test to see if were actually timed out and handle error approprietly
+ for(i = find_starting_pos(splits, selection); i < split[selection].size; i++) {
+ ledstring.channel[0].leds[i] = (selection_state ? (i % 2) : ((i+1) % 2)) ? 0xffffff : 0; //what the fuck is wrong with me
+ }
+ selection_state ? 0 : 1;
+ ws2811_render(&ledstring);
+ }
+
+ return 0;
+}