-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcsal_ledmatrix.h
171 lines (147 loc) · 4.52 KB
/
csal_ledmatrix.h
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
#ifndef _CSAL_LEDMATRIX_H
#define _CSAL_LEDMATRIX_H
#include "CSAL_SHARED/os_error.h"
#include "color_conv.h"
/**
* @brief function pointer for initializing a led matrix
* @param void *ptr to whatever data struct holding the actual ledmatrix implementation data
* @param int width
* @param int height
*/
typedef int (*os_init_ledmatrix_ptr)(void *ptr, int width, int height);
/**
* @brief Function pointer to set a specific pixel to a specific color
* @param void *ptr to whatever data struct holding the actual ledmatrix implementation data
* @param int x pos
* @param int y pos
* @param rgb_t col color
*/
typedef int (*os_matrix_setpixel_ptr)(void *ptr, int x, int y, uint8_t r, uint8_t g, uint8_t b);
/**
* @brief Function pointer to update the led matrix
* @param void *ptr to whatever data struct holding the actual ledmatrix implementation data
*/
typedef int (*os_matrix_update_ptr)(void *ptr);
/**
* @brief Populate these with the relevant matrix update commands
* @param os_init_ledmatrix_ptr init_func: pointer to function that will initialize the led matrix
* @param os_matrix_setpixel_ptr setpixel_func: pointer to the function that will set
* @param os_matrix_update_ptr update fun: Function that updates the led matrix to the specific color
* @param int width width of led matrix
* @param int height height of led matrix
* @param void *matrix_ptr pointer to data structure used for whatever eld matrix
*/
typedef struct os_ledmatrix_init
{
os_init_ledmatrix_ptr init_func;
os_matrix_setpixel_ptr setpixel_func;
os_matrix_update_ptr update_func;
int width;
int height;
void *matrix_ptr;
} os_ledmatrix_init_t;
typedef enum os_ledmatrix_fill_type
{
MATRIX_2D_FILL_OUTLINE,
MATRIX_2D_FILL_FULL
} os_ledmatrix_fill_type_t;
/**
* @brief LED matrix handler
*/
typedef struct os_ledmatrix
{
os_init_ledmatrix_ptr init_func;
os_matrix_setpixel_ptr setpixel_func;
os_matrix_update_ptr update_fun;
void *data_ptr;
int width;
int height;
void *matrix_mut;
} os_ledmatrix_t;
typedef struct os_2d_point_t
{
int x;
int y;
} os_2d_point_t;
typedef struct os_2d_line_t
{
os_2d_point_t p1;
os_2d_point_t p2;
} os_2d_line_t;
typedef struct os_2d_circle_t
{
os_2d_point_t p;
int intensity;
} os_2d_circle_t;
/**
* @brief Initialize matrix
* @param os_ledmatrix_init_t matrix initialization structure
* @param os_ledmatrix_t *matrix that we want to initialize
*/
int os_init_ledmatrix(os_ledmatrix_init_t matrix_init, os_ledmatrix_t *matrix);
/**
* @brief Set pixel ledmatrix
* @param os_ledmatrix_t *matrix that we want to initialize
* @param int x pos
* @param int y pos
* @param rgb_t col color
*/
int os_setpixel_ledmatrix(os_ledmatrix_t *matrix, int x, int y, rgb_t rgb);
/**
* @brief Renders a line on the matrix
* @param os_2d_line_t line
* @param rgb_t line
* @return successful
*/
int os_drawline_ledmatrix(os_ledmatrix_t *matrix, os_2d_line_t line, rgb_t rgb);
/**
* @brief Renders a line on the matrix
* @param os_2d_line_t line
* @param hsv_t line
* @return successful
*/
int os_drawline_ledmatrix_hsv(os_ledmatrix_t *matrix, os_2d_line_t line, hsv_t hsv);
/**
* @brief Renders a circle on the matrix
* @param os_ledmatrix_t *matrix
* @param os_2d_circle_t circle
* @param rgb_t rgb color structure
* @returns os return status
*/
int os_drawcircle_ledmatrix(os_ledmatrix_t *matrix, os_2d_circle_t circle, rgb_t rgb, os_ledmatrix_fill_type_t fill_type);
/**
* @brief Checks if line flows from left to right
* @param os_2d_line_t line
*/
bool is_valid_line(os_2d_line_t line);
/**
* @brief Makes line valid
*/
int os_make_line_valid(os_2d_line_t *line);
/**
* @brief Set pixel ledmatrix to specific hsv value
* @param os_ledmatrix_t *matrix that we want to initialize
* @param int x pos
* @param int y pos
* @param hsv_t col color
*/
int os_setpixel_ledmatrix_hsv(os_ledmatrix_t *matrix, int x, int y, hsv_t hsv);
/**
* @brief Set pixel ledmatrix all in one(prevents too much wasted time spent unlocking and locking mutexes)
* @param os_ledmatrix_t *matrix that we want to initialize
* @param int x pos
* @param int y pos
* @param hsv_t col color
*/
int os_setpixel_ledmatrix_hsv_image(os_ledmatrix_t *matrix, hsv_t *hsv_range);
/**
* @brief Updates the ledmatrix
* @param os_ledmatrix_t *matrix that we want to initialize
*/
int os_ledmatrix_update(os_ledmatrix_t *matrix);
/**
* @brief Clears the ledmatrix or sets it to zero
* @param os_ledmatrix_t *matrix that we want to initialize
*/
int os_clear_ledmatrix(os_ledmatrix_t *matrix);
#endif