1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
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;
}
|