-
Notifications
You must be signed in to change notification settings - Fork 337
/
led.h
247 lines (213 loc) · 6.55 KB
/
led.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
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
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
/************************************************************
* <bsn.cl fy=2014 v=onl>
*
* Copyright 2014, 2015 Big Switch Networks, Inc.
*
* Licensed under the Eclipse Public License, Version 1.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.eclipse.org/legal/epl-v10.html
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the
* License.
*
* </bsn.cl>
********************************************************//**
*
* @file
* @brief LED Management.
* @addtogroup oid-led
* @{
*
***********************************************************/
#ifndef __ONLP_LED_H__
#define __ONLP_LED_H__
#include <onlp/onlp.h>
#include <onlp/oids.h>
/* <auto.start.enum(tag:led).define> */
/** onlp_led_caps */
typedef enum onlp_led_caps_e {
ONLP_LED_CAPS_OFF = (1 << 0),
ONLP_LED_CAPS_AUTO = (1 << 1),
ONLP_LED_CAPS_AUTO_BLINKING = (1 << 2),
ONLP_LED_CAPS_CHAR = (1 << 3),
ONLP_LED_CAPS_RED = (1 << 4),
ONLP_LED_CAPS_RED_BLINKING = (1 << 5),
ONLP_LED_CAPS_ORANGE = (1 << 6),
ONLP_LED_CAPS_ORANGE_BLINKING = (1 << 7),
ONLP_LED_CAPS_YELLOW = (1 << 8),
ONLP_LED_CAPS_YELLOW_BLINKING = (1 << 9),
ONLP_LED_CAPS_GREEN = (1 << 10),
ONLP_LED_CAPS_GREEN_BLINKING = (1 << 11),
ONLP_LED_CAPS_BLUE = (1 << 12),
ONLP_LED_CAPS_BLUE_BLINKING = (1 << 13),
ONLP_LED_CAPS_PURPLE = (1 << 14),
ONLP_LED_CAPS_PURPLE_BLINKING = (1 << 15),
} onlp_led_caps_t;
/** onlp_led_mode */
typedef enum onlp_led_mode_e {
ONLP_LED_MODE_OFF,
ONLP_LED_MODE_AUTO,
ONLP_LED_MODE_AUTO_BLINKING,
ONLP_LED_MODE_CHAR,
ONLP_LED_MODE_RED,
ONLP_LED_MODE_RED_BLINKING,
ONLP_LED_MODE_ORANGE,
ONLP_LED_MODE_ORANGE_BLINKING,
ONLP_LED_MODE_YELLOW,
ONLP_LED_MODE_YELLOW_BLINKING,
ONLP_LED_MODE_GREEN,
ONLP_LED_MODE_GREEN_BLINKING,
ONLP_LED_MODE_BLUE,
ONLP_LED_MODE_BLUE_BLINKING,
ONLP_LED_MODE_PURPLE,
ONLP_LED_MODE_PURPLE_BLINKING,
ONLP_LED_MODE_LAST = ONLP_LED_MODE_PURPLE_BLINKING,
ONLP_LED_MODE_COUNT,
ONLP_LED_MODE_INVALID = -1,
} onlp_led_mode_t;
/* <auto.end.enum(tag:led).define> */
/**
* LED information structure.
*/
typedef struct onlp_led_info_s {
/** Header */
onlp_oid_hdr_t hdr;
/** Capabilities - a combination of @ref onlp_led_caps_e */
uint32_t caps;
/** Current mode, if capable. */
onlp_led_mode_t mode;
/** Current char, if capable. */
char character;
} onlp_led_info_t;
/**
* @brief Software initialization of the LED module.
*/
int onlp_led_sw_init(void);
/**
* @brief Hardware initialization of the LED module.
*/
int onlp_led_hw_init(uint32_t flags);
/**
* @brief Deinitialize the led software module.
* @note The primary purpose of this API is to properly
* deallocate any resources used by the module in order
* faciliate detection of real resouce leaks.
*/
int onlp_led_sw_denit(void);
/**
* @brief Get the LED header.
* @param oid The LED OID
* @param[out] rv Receives the header.
*/
int onlp_led_hdr_get(onlp_oid_t oid, onlp_oid_hdr_t* rv);
/**
* @brief Get LED information.
* @param oid The LED OID.
* @param[out] rv Receives the information structure.
*/
int onlp_led_info_get(onlp_oid_t oid, onlp_led_info_t* rv);
/**
* @brief Get the LED caps.
* @param oid The LED OID.
* @param[out] caps Receives the caps.
*/
int onlp_led_caps_get(onlp_oid_t oid, uint32_t* caps);
/**
* @brief Set the LED mode.
* @param oid The LED OID.
* @param mode The mode. .
* @note Only relevant if the LED supports the color capability.
*/
int onlp_led_mode_set(onlp_oid_t oid, onlp_led_mode_t mode);
/**
* @brief Set the LED char
* @param oid The LED OID
* @param c The character.
* @note Only relevant if the LED supports the char capability.
*/
int onlp_led_char_set(onlp_oid_t oid, char c);
/**
* @brief Convert an LED info structure to user JSON.
* @param info The LED info structure.
* @param [out] cj Receives the JSON object.
* @param flags The JSON format flags.
*/
int onlp_led_info_to_user_json(onlp_led_info_t* info, cJSON** cj, uint32_t flags);
/**
* @brief Convert an LED info structure to JSON.
* @param info The LED info structure.
* @param [out] cj Receives the JSON object.
* @param flags The JSON format flags.
*/
int onlp_led_info_to_json(onlp_led_info_t* info, cJSON** cj, uint32_t flags);
/**
* @brief Convert a JSON object to an LED info structure.
* @param cj The JSON oibject.
* @param [out] info Receives the LED info structure.
*/
int onlp_led_info_from_json(cJSON* cj, onlp_led_info_t* info);
/******************************************************************************
*
* Enumeration Support Definitions.
*
* Please do not add additional code beyond this point.
*
*****************************************************************************/
/* <auto.start.enum(tag:led).supportheader> */
/** Enum names. */
const char* onlp_led_caps_name(onlp_led_caps_t e);
/** Enum values. */
int onlp_led_caps_value(const char* str, onlp_led_caps_t* e, int substr);
/** Enum descriptions. */
const char* onlp_led_caps_desc(onlp_led_caps_t e);
/** Enum validator. */
int onlp_led_caps_valid(onlp_led_caps_t e);
/** validator */
#define ONLP_LED_CAPS_VALID(_e) \
(onlp_led_caps_valid((_e)))
/** onlp_led_caps_map table. */
extern aim_map_si_t onlp_led_caps_map[];
/** onlp_led_caps_desc_map table. */
extern aim_map_si_t onlp_led_caps_desc_map[];
/** Strings macro. */
#define ONLP_LED_MODE_STRINGS \
{\
"OFF", \
"AUTO", \
"AUTO_BLINKING", \
"CHAR", \
"RED", \
"RED_BLINKING", \
"ORANGE", \
"ORANGE_BLINKING", \
"YELLOW", \
"YELLOW_BLINKING", \
"GREEN", \
"GREEN_BLINKING", \
"BLUE", \
"BLUE_BLINKING", \
"PURPLE", \
"PURPLE_BLINKING", \
}
/** Enum names. */
const char* onlp_led_mode_name(onlp_led_mode_t e);
/** Enum values. */
int onlp_led_mode_value(const char* str, onlp_led_mode_t* e, int substr);
/** Enum descriptions. */
const char* onlp_led_mode_desc(onlp_led_mode_t e);
/** validator */
#define ONLP_LED_MODE_VALID(_e) \
( (0 <= (_e)) && ((_e) <= ONLP_LED_MODE_PURPLE_BLINKING))
/** onlp_led_mode_map table. */
extern aim_map_si_t onlp_led_mode_map[];
/** onlp_led_mode_desc_map table. */
extern aim_map_si_t onlp_led_mode_desc_map[];
/* <auto.end.enum(tag:led).supportheader> */
#endif /* __ONLP_LED_H__ */
/* @} */