leds.c 2.65 KB
Newer Older
1
#include "leds.h"
fleur's avatar
fleur committed
2
#include "pmic.h"
3
4
5
6
7
8
#include "FreeRTOS.h"
#include "task.h"
#include "epicardium.h"
#include "modules.h"

#include <stdbool.h>
fleur's avatar
fleur committed
9
10

//TODO: create smth like vTaskDelay(pdMS_TO_TICKS(//put ms here)) for us, remove blocking delay from /lib/leds.c to avoid process blocking
11

12
13
14
15
16
17
18
19
20
21
#define NUM_LEDS 15 /* Take from lib/card10/leds.c */

static void update_if_needed()
{
	if (personal_state_enabled() == 0) {
		leds_update_power();
		leds_update();
	}
}

22
23
void epic_leds_set(int led, uint8_t r, uint8_t g, uint8_t b)
{
24
25
26
	if (led == PERSONAL_STATE_LED && personal_state_enabled())
		return;

fleur's avatar
fleur committed
27
28
29
30
31
32
33
	leds_prep(led, r, g, b);
	leds_update_power();
	leds_update();
}

void epic_leds_set_hsv(int led, float h, float s, float v)
{
34
35
36
	if (led == PERSONAL_STATE_LED && personal_state_enabled())
		return;

fleur's avatar
fleur committed
37
	leds_prep_hsv(led, h, s, v);
38
	update_if_needed();
fleur's avatar
fleur committed
39
40
41
42
}

void epic_leds_prep(int led, uint8_t r, uint8_t g, uint8_t b)
{
43
44
45
	if (led == PERSONAL_STATE_LED && personal_state_enabled())
		return;

fleur's avatar
fleur committed
46
47
48
49
50
	leds_prep(led, r, g, b);
}

void epic_leds_prep_hsv(int led, float h, float s, float v)
{
51
52
53
	if (led == PERSONAL_STATE_LED && personal_state_enabled())
		return;

fleur's avatar
fleur committed
54
55
56
57
58
59
60
	leds_prep_hsv(led, h, s, v);
}

void epic_leds_set_all(uint8_t *pattern_ptr, uint8_t len)
{
	uint8_t(*pattern)[3] = (uint8_t(*)[3])pattern_ptr;
	for (int i = 0; i < len; i++) {
61
62
63
		if (i == PERSONAL_STATE_LED && personal_state_enabled())
			continue;

fleur's avatar
fleur committed
64
65
		leds_prep(i, pattern[i][0], pattern[i][1], pattern[i][2]);
	}
66
	update_if_needed();
fleur's avatar
fleur committed
67
68
69
70
71
72
}

void epic_leds_set_all_hsv(float *pattern_ptr, uint8_t len)
{
	float(*pattern)[3] = (float(*)[3])pattern_ptr;
	for (int i = 0; i < len; i++) {
73
74
75
		if (i == PERSONAL_STATE_LED && personal_state_enabled())
			continue;

fleur's avatar
fleur committed
76
77
		leds_prep_hsv(i, pattern[i][0], pattern[i][1], pattern[i][2]);
	}
78
	update_if_needed();
fleur's avatar
fleur committed
79
80
81
82
83
}

void epic_leds_dim_top(uint8_t value)
{
	leds_set_dim_top(value);
84
85
	if (personal_state_enabled() == 0)
		leds_update();
fleur's avatar
fleur committed
86
87
88
89
90
}

void epic_leds_dim_bottom(uint8_t value)
{
	leds_set_dim_bottom(value);
91
92
	if (personal_state_enabled() == 0)
		leds_update();
fleur's avatar
fleur committed
93
94
95
96
}

void epic_leds_set_rocket(int led, uint8_t value)
{
Rahix's avatar
Rahix committed
97
	value = value > 31 ? 31 : value;
fleur's avatar
fleur committed
98
99
100
101
102
103
104
105
106
107
	pmic_set_led(led, value);
}

void epic_set_flashlight(bool power)
{
	leds_flashlight(power);
}

void epic_leds_update(void)
{
108
	update_if_needed();
fleur's avatar
fleur committed
109
110
111
112
113
114
115
116
117
118
119
}

void epic_leds_set_powersave(bool eco)
{
	leds_powersave(eco);
}

void epic_leds_set_gamma_table(uint8_t rgb_channel, uint8_t gamma_table[256])
{
	leds_set_gamma_table(rgb_channel, gamma_table);
}
120
121
122
123

void epic_leds_clear_all(uint8_t r, uint8_t g, uint8_t b)
{
	for (int i = 0; i < NUM_LEDS; i++) {
124
		if (i == PERSONAL_STATE_LED && personal_state_enabled())
125
126
127
128
129
130
131
132
			continue;

		leds_prep(i, r, g, b);
	}

	leds_update_power();
	leds_update();
}