aboutsummaryrefslogtreecommitdiff
path: root/control/ledctl.c
blob: 76bdc67d213b0f92b2957d6b26d377e1239904a9 (plain)
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#include "ledctl.h"
#include <bcl.h>
#include "state.h"
#include "gui.h"


const char *mode_string[] = {
	[MODE_SOLID_RED] = "#FF0000",
	[MODE_SOLID_GREEN] = "#00FF00",
	[MODE_SOLID_BLUE] = "#0000FF",
	[MODE_SOLID_YELLOW] = "#FFFF00",
	[MODE_RAINBOW] = "rainbow",
};


int current_brightness = 0;

void update_brightness() {
	if (!enabled)
		current_brightness = 0;
	else
		current_brightness = brightness >= brightness_max ? 100 : (1 << (brightness - 1));
	bc_radio_pub_int("led/brightness/set", &current_brightness);
}

void update_mode() {
	if (mode == MODE_RAINBOW)
		bc_radio_pub_string("led/effect/set", mode_string[mode]);
	else
		bc_radio_pub_string("led/color/set", mode_string[mode]);
}

void click_left() {
	switch (state) {
		case STATE_DEFAULT:
			enabled = 1;
			update_brightness();
			break;
		case STATE_BRIGHTNESS_SELECT:
			if (brightness < brightness_max)
				brightness++;
			update_brightness();
			break;
		case STATE_COLOR_SELECT:
			if (mode >= MODE_RAINBOW)
				mode = MODE_SOLID_RED;
			else
				mode++;
			update_mode();
			break;
		default:
			break;
	}
}

void click_right() {
	switch (state) {
		case STATE_DEFAULT:
			enabled = 0;
			update_brightness();
			break;
		case STATE_BRIGHTNESS_SELECT:
			if (brightness > 1)
				brightness--;
			update_brightness();
			break;
		case STATE_COLOR_SELECT:
			if (mode <= MODE_SOLID_RED)
				mode = MODE_RAINBOW;
			else
				mode--;
			update_mode();
			break;
		default:
			break;
	}
}

void hold_left() {
	switch (state) {
		case STATE_DEFAULT:
			state = STATE_BRIGHTNESS_SELECT;
			break;
		case STATE_COLOR_SELECT:
			state = STATE_COLOR_SELECT;
			break;
		case STATE_BRIGHTNESS_SELECT:
			state = STATE_DEFAULT;
			break;
		default:
			break;
	}
}

void hold_right() {
	switch (state) {
		case STATE_DEFAULT:
			state = STATE_COLOR_SELECT;
			break;
		case STATE_COLOR_SELECT:
			state = STATE_DEFAULT;
			break;
		case STATE_BRIGHTNESS_SELECT:
			state = STATE_BRIGHTNESS_SELECT;
			break;
		default:
			break;
	}
}