1 /**
2 * @file lv_gauge.h
3 *
4 */
5
6 #ifndef LV_GAUGE_H
7 #define LV_GAUGE_H
8
9 #ifdef __cplusplus
10 extern "C" {
11 #endif
12
13 /*********************
14 * INCLUDES
15 *********************/
16 #ifdef LV_CONF_INCLUDE_SIMPLE
17 #include "lv_conf.h"
18 #else
19 #include "../../lv_conf.h"
20 #endif
21
22 #if LV_USE_GAUGE != 0
23
24 /*Testing of dependencies*/
25 #if LV_USE_LMETER == 0
26 #error "lv_gauge: lv_lmeter is required. Enable it in lv_conf.h (LV_USE_LMETER 1) "
27 #endif
28
29 #include "../lv_core/lv_obj.h"
30 #include "lv_lmeter.h"
31 #include "lv_label.h"
32 #include "lv_line.h"
33
34 /*********************
35 * DEFINES
36 *********************/
37
38 /**********************
39 * TYPEDEFS
40 **********************/
41
42 /*Data of gauge*/
43 typedef struct
44 {
45 lv_lmeter_ext_t lmeter; /*Ext. of ancestor*/
46 /*New data for this type */
47 int16_t * values; /*Array of the set values (for needles) */
48 const lv_color_t * needle_colors; /*Color of the needles (lv_color_t my_colors[needle_num])*/
49 uint8_t needle_count; /*Number of needles*/
50 uint8_t label_count; /*Number of labels on the scale*/
51 } lv_gauge_ext_t;
52
53 /*Styles*/
54 enum {
55 LV_GAUGE_STYLE_MAIN,
56 };
57 typedef uint8_t lv_gauge_style_t;
58
59 /**********************
60 * GLOBAL PROTOTYPES
61 **********************/
62
63 /**
64 * Create a gauge objects
65 * @param par pointer to an object, it will be the parent of the new gauge
66 * @param copy pointer to a gauge object, if not NULL then the new object will be copied from it
67 * @return pointer to the created gauge
68 */
69 lv_obj_t * lv_gauge_create(lv_obj_t * par, const lv_obj_t * copy);
70
71 /*=====================
72 * Setter functions
73 *====================*/
74
75 /**
76 * Set the number of needles
77 * @param gauge pointer to gauge object
78 * @param needle_cnt new count of needles
79 * @param colors an array of colors for needles (with 'num' elements)
80 */
81 void lv_gauge_set_needle_count(lv_obj_t * gauge, uint8_t needle_cnt, const lv_color_t colors[]);
82
83 /**
84 * Set the value of a needle
85 * @param gauge pointer to a gauge
86 * @param needle_id the id of the needle
87 * @param value the new value
88 */
89 void lv_gauge_set_value(lv_obj_t * gauge, uint8_t needle_id, int16_t value);
90
91 /**
92 * Set minimum and the maximum values of a gauge
93 * @param gauge pointer to he gauge object
94 * @param min minimum value
95 * @param max maximum value
96 */
lv_gauge_set_range(lv_obj_t * gauge,int16_t min,int16_t max)97 static inline void lv_gauge_set_range(lv_obj_t * gauge, int16_t min, int16_t max)
98 {
99 lv_lmeter_set_range(gauge, min, max);
100 }
101
102 /**
103 * Set a critical value on the scale. After this value 'line.color' scale lines will be drawn
104 * @param gauge pointer to a gauge object
105 * @param value the critical value
106 */
lv_gauge_set_critical_value(lv_obj_t * gauge,int16_t value)107 static inline void lv_gauge_set_critical_value(lv_obj_t * gauge, int16_t value)
108 {
109 lv_lmeter_set_value(gauge, value);
110 }
111
112 /**
113 * Set the scale settings of a gauge
114 * @param gauge pointer to a gauge object
115 * @param angle angle of the scale (0..360)
116 * @param line_cnt count of scale lines.
117 * The get a given "subdivision" lines between label, `line_cnt` = (sub_div + 1) * (label_cnt - 1) +
118 * 1
119 * @param label_cnt count of scale labels.
120 */
121 void lv_gauge_set_scale(lv_obj_t * gauge, uint16_t angle, uint8_t line_cnt, uint8_t label_cnt);
122
123 /**
124 * Set the styles of a gauge
125 * @param gauge pointer to a gauge object
126 * @param type which style should be set (can be only `LV_GAUGE_STYLE_MAIN`)
127 * @param style set the style of the gauge
128 * */
lv_gauge_set_style(lv_obj_t * gauge,lv_gauge_style_t type,lv_style_t * style)129 static inline void lv_gauge_set_style(lv_obj_t * gauge, lv_gauge_style_t type, lv_style_t * style)
130 {
131 (void)type; /*Unused*/
132 lv_obj_set_style(gauge, style);
133 }
134
135 /*=====================
136 * Getter functions
137 *====================*/
138
139 /**
140 * Get the value of a needle
141 * @param gauge pointer to gauge object
142 * @param needle the id of the needle
143 * @return the value of the needle [min,max]
144 */
145 int16_t lv_gauge_get_value(const lv_obj_t * gauge, uint8_t needle);
146
147 /**
148 * Get the count of needles on a gauge
149 * @param gauge pointer to gauge
150 * @return count of needles
151 */
152 uint8_t lv_gauge_get_needle_count(const lv_obj_t * gauge);
153
154 /**
155 * Get the minimum value of a gauge
156 * @param gauge pointer to a gauge object
157 * @return the minimum value of the gauge
158 */
lv_gauge_get_min_value(const lv_obj_t * lmeter)159 static inline int16_t lv_gauge_get_min_value(const lv_obj_t * lmeter)
160 {
161 return lv_lmeter_get_min_value(lmeter);
162 }
163
164 /**
165 * Get the maximum value of a gauge
166 * @param gauge pointer to a gauge object
167 * @return the maximum value of the gauge
168 */
lv_gauge_get_max_value(const lv_obj_t * lmeter)169 static inline int16_t lv_gauge_get_max_value(const lv_obj_t * lmeter)
170 {
171 return lv_lmeter_get_max_value(lmeter);
172 }
173
174 /**
175 * Get a critical value on the scale.
176 * @param gauge pointer to a gauge object
177 * @return the critical value
178 */
lv_gauge_get_critical_value(const lv_obj_t * gauge)179 static inline int16_t lv_gauge_get_critical_value(const lv_obj_t * gauge)
180 {
181 return lv_lmeter_get_value(gauge);
182 }
183
184 /**
185 * Set the number of labels (and the thicker lines too)
186 * @param gauge pointer to a gauge object
187 * @return count of labels
188 */
189 uint8_t lv_gauge_get_label_count(const lv_obj_t * gauge);
190
191 /**
192 * Get the scale number of a gauge
193 * @param gauge pointer to a gauge object
194 * @return number of the scale units
195 */
lv_gauge_get_line_count(const lv_obj_t * gauge)196 static inline uint8_t lv_gauge_get_line_count(const lv_obj_t * gauge)
197 {
198 return lv_lmeter_get_line_count(gauge);
199 }
200
201 /**
202 * Get the scale angle of a gauge
203 * @param gauge pointer to a gauge object
204 * @return angle of the scale
205 */
lv_gauge_get_scale_angle(const lv_obj_t * gauge)206 static inline uint16_t lv_gauge_get_scale_angle(const lv_obj_t * gauge)
207 {
208 return lv_lmeter_get_scale_angle(gauge);
209 }
210
211 /**
212 * Get the style of a gauge
213 * @param gauge pointer to a gauge object
214 * @param type which style should be get (can be only `LV_GAUGE_STYLE_MAIN`)
215 * @return pointer to the gauge's style
216 */
lv_gauge_get_style(const lv_obj_t * gauge,lv_gauge_style_t type)217 static inline const lv_style_t * lv_gauge_get_style(const lv_obj_t * gauge, lv_gauge_style_t type)
218 {
219 (void)type; /*Unused*/
220 return lv_obj_get_style(gauge);
221 }
222
223 /**********************
224 * MACROS
225 **********************/
226
227 #endif /*LV_USE_GAUGE*/
228
229 #ifdef __cplusplus
230 } /* extern "C" */
231 #endif
232
233 #endif /*LV_GAUGE_H*/
234