-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathRMTT_MatrixEffect.cpp
219 lines (185 loc) · 6.21 KB
/
RMTT_MatrixEffect.cpp
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
/*
* Copyright (C) 2020 DJI.
*
* SPDX-License-Identifier: BSD-3-Clause-Clear
*
* Change Logs:
* Date Author Notes
* 2020-08-25 robomaster first version
*/
#include "RMTT_Libs.h"
uint8_t matrix_effect_mode = MATRIX_EFFECT_FACTORY_MODE;
uint8_t matrix_effect_next_mode = MATRIX_EFFECT_FACTORY_MODE;
/* string move */
static char string_move_mode = 'l';
static char matrix_color_mode = 'r';
static int move_time_interval = MOVE_MIN_TIME;
static int matrix_str_len = 0;
static uint8_t matrix_str_buff[256] = {0};
static uint8_t next_cache = NONE_CACHE_INDEX;
static uint8_t first_cache[128] = {0};
static uint8_t second_cache[128] = {0};
static uint8_t matrix_buff[128] = {0};
/* letter point */
int next_str_index = 1;
/* font buff cs/sw point */
int str_c_index = 0;
uint8_t matrix_bright = 0;
uint8_t matrix_next_bright = 0;
/* graph move */
static uint8_t graph_index = 0;
static uint8_t graph_move_buff[128] = {0};
TaskHandle_t matrixEffectTaskHandle = NULL;
void matrix_effect_init(uint8_t bright)
{
xTaskCreateUniversal(matrix_effect_task, "matrix_effect_task", 8192, &bright, 4, &matrixEffectTaskHandle, 1);
}
void matrix_effect_deinit(void)
{
matrix_effect_mode = MATRIX_EFFECT_FACTORY_MODE;
matrix_effect_next_mode = MATRIX_EFFECT_FACTORY_MODE;
}
void matrix_effect_move_str(char *str, int len, char color, char move_mode, float freq)
{
string_move_mode = move_mode;
matrix_color_mode = color;
if (freq != 0)
{
move_time_interval = max(1/freq * 1000 / 8, (float)MOVE_MIN_TIME);
}
matrix_str_len = min(len, (int)sizeof(matrix_str_buff));
memcpy(matrix_str_buff, str, matrix_str_len);
matrix_effect_next_mode = MATRIX_EFFECT_STRING_MOVE_MODE;
next_cache = NONE_CACHE_INDEX;
}
void matrix_effect_move_graph(uint8_t *buff, char move_mode, float freq)
{
memcpy(graph_move_buff, buff, 128);
string_move_mode = move_mode;
if (freq != 0)
{
move_time_interval = max(1/freq * 1000 / 8, (float)MOVE_MIN_TIME);
}
matrix_effect_next_mode = MATRIX_EFFECT_GRAPH_MOVE_MODE;
graph_index = 0;
}
void matrix_effect_set_graph(uint8_t *graph)
{
matrix_effect_next_mode = MATRIX_EFFECT_STATIC_MODE;
memcpy(matrix_buff, graph, 128);
}
uint8_t get_matrix_effect_mode(void)
{
return matrix_effect_mode;
}
void matrix_effect_set_bright(uint8_t bright)
{
matrix_next_bright = bright;
}
void matrix_effect_task(void *param)
{
matrix_next_bright = *(uint8_t *)param;
while (1)
{
matrix_bright = matrix_next_bright;
matrix_effect_mode = matrix_effect_next_mode;
switch (matrix_effect_mode)
{
case MATRIX_EFFECT_FACTORY_MODE:
/* do nothing */
delay(50);
break;
case MATRIX_EFFECT_STATIC_MODE:
RMTT_Matrix::SetAllPWM(matrix_buff);
delay(50);
break;
case MATRIX_EFFECT_GRAPH_MOVE_MODE:
{
if (graph_index == 8)
{
graph_index = 0;
}
graph_move_effect2buff(graph_move_buff, matrix_buff, string_move_mode, graph_index);
if (matrix_effect_mode == MATRIX_EFFECT_GRAPH_MOVE_MODE)
{
RMTT_Matrix::SetAllPWM(matrix_buff);
}
graph_index++;
delay(move_time_interval);
break;
}
case MATRIX_EFFECT_STRING_MOVE_MODE:
{
if (next_cache == NONE_CACHE_INDEX)
{
/* first init */
next_cache = FIRST_CACHE_INDEX;
if ((string_move_mode == 'r') || (string_move_mode == 'd'))
{
for (int i = 0; i < matrix_str_len / 2; i++)
{
char chr = matrix_str_buff[i];
matrix_str_buff[i] = matrix_str_buff[matrix_str_len - i - 1];
matrix_str_buff[matrix_str_len - i - 1] = chr;
}
}
if (matrix_str_len == 1)
{
mled_font2buff(first_cache, matrix_str_buff[0], matrix_color_mode, matrix_bright);
mled_font2buff(second_cache, matrix_str_buff[0], matrix_color_mode, matrix_bright);
}
else
{
next_str_index = 1;
str_c_index = 0;
mled_font2buff(first_cache, matrix_str_buff[0], matrix_color_mode, matrix_bright);
mled_font2buff(second_cache, matrix_str_buff[1], matrix_color_mode, matrix_bright);
}
}
if (str_c_index == 8)
{
str_c_index = 0;
if (matrix_str_len != 1)
{
next_str_index++;
if (next_str_index == matrix_str_len)
{
next_str_index = 0;
}
if (next_cache == FIRST_CACHE_INDEX)
{
mled_font2buff(first_cache, matrix_str_buff[next_str_index], matrix_color_mode, matrix_bright);
next_cache = SECOND_CACHE_INDEX;
}
else if (next_cache == SECOND_CACHE_INDEX)
{
mled_font2buff(second_cache, matrix_str_buff[next_str_index], matrix_color_mode, matrix_bright);
next_cache = FIRST_CACHE_INDEX;
}
}
}
if (next_cache == FIRST_CACHE_INDEX)
{
string_move_effect2buff(first_cache, second_cache, matrix_buff, string_move_mode, str_c_index);
}
else if (next_cache == SECOND_CACHE_INDEX)
{
string_move_effect2buff(second_cache, first_cache, matrix_buff, string_move_mode, str_c_index);
}
if (matrix_effect_mode == MATRIX_EFFECT_STRING_MOVE_MODE)
{
RMTT_Matrix::SetAllPWM(matrix_buff);
}
str_c_index++;
delay(move_time_interval);
}
break;
default:
{
/* error mode */
delay(100);
}
break;
}
}
}