1
0
mirror of https://github.com/lvgl/lvgl.git synced 2025-01-21 06:53:01 +08:00
lvgl/src/lv_widgets/lv_gauge.h

276 lines
7.6 KiB
C
Raw Normal View History

/**
* @file lv_gauge.h
2018-06-19 09:49:58 +02:00
*
*/
#ifndef LV_GAUGE_H
#define LV_GAUGE_H
2017-07-09 15:32:49 +02:00
#ifdef __cplusplus
extern "C" {
#endif
/*********************
* INCLUDES
*********************/
#include "../lv_conf_internal.h"
#if LV_USE_GAUGE != 0
2017-01-15 21:52:21 +01:00
/*Testing of dependencies*/
#if LV_USE_LINEMETER == 0
#error "lv_gauge: lv_linemeter is required. Enable it in lv_conf.h (LV_USE_LINEMETER 1) "
2017-01-15 21:52:21 +01:00
#endif
2017-11-30 11:35:33 +01:00
#include "../lv_core/lv_obj.h"
#include "lv_linemeter.h"
#include "lv_label.h"
#include "lv_line.h"
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
2020-03-20 04:15:38 -07:00
typedef void (*lv_gauge_format_cb_t)(lv_obj_t * gauge, char buf[], int bufsize, int32_t value);
2020-03-17 04:14:58 -07:00
/*Data of gauge*/
2020-02-26 19:48:27 +01:00
typedef struct {
lv_linemeter_ext_t lmeter; /*Ext. of ancestor*/
/*New data for this type */
2020-03-20 03:49:50 -07:00
int32_t * values; /*Array of the set values (for needles) */
2019-04-04 07:15:40 +02:00
const lv_color_t * needle_colors; /*Color of the needles (lv_color_t my_colors[needle_num])*/
2019-11-30 11:41:18 +01:00
const void * needle_img;
lv_point_t needle_img_pivot;
lv_style_list_t style_needle;
lv_style_list_t style_strong;
uint8_t needle_count; /*Number of needles*/
uint8_t label_count; /*Number of labels on the scale*/
2020-03-20 04:15:38 -07:00
lv_gauge_format_cb_t format_cb;
2018-06-19 09:49:58 +02:00
} lv_gauge_ext_t;
/*Styles*/
enum {
LV_GAUGE_PART_MAIN = LV_LINEMETER_PART_MAIN,
2020-03-06 13:14:25 +01:00
LV_GAUGE_PART_MAJOR = _LV_LINEMETER_PART_VIRTUAL_LAST,
LV_GAUGE_PART_NEEDLE,
_LV_GAUGE_PART_VIRTUAL_LAST = _LV_LINEMETER_PART_VIRTUAL_LAST,
_LV_GAUGE_PART_REAL_LAST = _LV_LINEMETER_PART_REAL_LAST,
};
typedef uint8_t lv_gauge_style_t;
/**********************
* GLOBAL PROTOTYPES
**********************/
/**
* Create a gauge objects
* @param par pointer to an object, it will be the parent of the new gauge
* @param copy pointer to a gauge object, if not NULL then the new object will be copied from it
* @return pointer to the created gauge
*/
lv_obj_t * lv_gauge_create(lv_obj_t * par, const lv_obj_t * copy);
2017-11-11 14:23:05 +01:00
/*=====================
* Setter functions
*====================*/
/**
2017-04-21 17:11:47 +02:00
* Set the number of needles
* @param gauge pointer to gauge object
* @param needle_cnt new count of needles
2017-04-21 17:11:47 +02:00
* @param colors an array of colors for needles (with 'num' elements)
*/
void lv_gauge_set_needle_count(lv_obj_t * gauge, uint8_t needle_cnt, const lv_color_t colors[]);
/**
* Set the value of a needle
* @param gauge pointer to a gauge
* @param needle_id the id of the needle
* @param value the new value
*/
2020-03-20 03:49:50 -07:00
void lv_gauge_set_value(lv_obj_t * gauge, uint8_t needle_id, int32_t value);
2017-11-11 14:23:05 +01:00
/**
* Set minimum and the maximum values of a gauge
* @param gauge pointer to he gauge object
* @param min minimum value
* @param max maximum value
*/
2020-03-20 03:49:50 -07:00
static inline void lv_gauge_set_range(lv_obj_t * gauge, int32_t min, int32_t max)
2017-11-11 14:23:05 +01:00
{
lv_linemeter_set_range(gauge, min, max);
2017-11-11 14:23:05 +01:00
}
2017-12-19 22:00:32 +01:00
/**
* Set a critical value on the scale. After this value 'line.color' scale lines will be drawn
* @param gauge pointer to a gauge object
* @param value the critical value
*/
2020-03-20 03:49:50 -07:00
static inline void lv_gauge_set_critical_value(lv_obj_t * gauge, int32_t value)
2017-12-19 22:00:32 +01:00
{
lv_linemeter_set_value(gauge, value);
2017-12-19 22:00:32 +01:00
}
/**
* Set the scale settings of a gauge
* @param gauge pointer to a gauge object
* @param angle angle of the scale (0..360)
* @param line_cnt count of scale lines.
2019-11-30 11:41:18 +01:00
* To get a given "subdivision" lines between labels:
* `line_cnt = (sub_div + 1) * (label_cnt - 1) + 1 `
* @param label_cnt count of scale labels.
*/
void lv_gauge_set_scale(lv_obj_t * gauge, uint16_t angle, uint8_t line_cnt, uint8_t label_cnt);
2020-03-06 13:14:25 +01:00
/**
* Set the set an offset for the gauge's angles to rotate it.
* @param gauge pointer to a line meter object
* @param angle angle offset (0..360), rotates clockwise
*/
static inline void lv_gauge_set_angle_offset(lv_obj_t * gauge, uint16_t angle)
{
lv_linemeter_set_angle_offset(gauge, angle);
}
2019-11-30 11:41:18 +01:00
/**
* Set an image to display as needle(s).
* The needle image should be horizontal and pointing to the right (`--->`).
* @param gauge pointer to a gauge object
* @param img_src pointer to an `lv_img_dsc_t` variable or a path to an image
* (not an `lv_img` object)
* @param pivot_x the X coordinate of rotation center of the image
* @param pivot_y the Y coordinate of rotation center of the image
*/
void lv_gauge_set_needle_img(lv_obj_t * gauge, const void * img, lv_coord_t pivot_x, lv_coord_t pivot_y);
2020-03-17 04:14:58 -07:00
/**
* Assign a function to format gauge values
* @param gauge pointer to a gauge object
2020-03-20 04:15:38 -07:00
* @param format_cb pointer to function of lv_gauge_format_cb_t
2020-03-17 04:14:58 -07:00
*/
2020-03-20 04:15:38 -07:00
void lv_gauge_set_formatter_cb(lv_obj_t * gauge, lv_gauge_format_cb_t format_cb);
2020-03-17 04:14:58 -07:00
2017-11-11 14:23:05 +01:00
/*=====================
* Getter functions
*====================*/
2017-04-21 17:11:47 +02:00
/**
* Get the value of a needle
* @param gauge pointer to gauge object
* @param needle the id of the needle
* @return the value of the needle [min,max]
2017-04-21 17:11:47 +02:00
*/
2020-03-20 03:49:50 -07:00
int32_t lv_gauge_get_value(const lv_obj_t * gauge, uint8_t needle);
2017-04-21 17:11:47 +02:00
/**
* Get the count of needles on a gauge
* @param gauge pointer to gauge
* @return count of needles
*/
uint8_t lv_gauge_get_needle_count(const lv_obj_t * gauge);
/**
* Get the minimum value of a gauge
* @param gauge pointer to a gauge object
* @return the minimum value of the gauge
*/
2020-03-20 03:49:50 -07:00
static inline int32_t lv_gauge_get_min_value(const lv_obj_t * lmeter)
{
return lv_linemeter_get_min_value(lmeter);
}
/**
* Get the maximum value of a gauge
* @param gauge pointer to a gauge object
* @return the maximum value of the gauge
*/
2020-03-20 03:49:50 -07:00
static inline int32_t lv_gauge_get_max_value(const lv_obj_t * lmeter)
{
return lv_linemeter_get_max_value(lmeter);
}
2017-12-19 22:00:32 +01:00
/**
* Get a critical value on the scale.
* @param gauge pointer to a gauge object
* @return the critical value
*/
2020-03-20 03:49:50 -07:00
static inline int32_t lv_gauge_get_critical_value(const lv_obj_t * gauge)
2017-12-19 22:00:32 +01:00
{
return lv_linemeter_get_value(gauge);
2017-12-19 22:00:32 +01:00
}
2017-11-11 14:23:05 +01:00
/**
* Set the number of labels (and the thicker lines too)
* @param gauge pointer to a gauge object
* @return count of labels
*/
uint8_t lv_gauge_get_label_count(const lv_obj_t * gauge);
/**
* Get the scale number of a gauge
* @param gauge pointer to a gauge object
* @return number of the scale units
*/
static inline uint16_t lv_gauge_get_line_count(const lv_obj_t * gauge)
{
return lv_linemeter_get_line_count(gauge);
}
2017-04-21 17:11:47 +02:00
/**
* Get the scale angle of a gauge
2017-04-21 17:11:47 +02:00
* @param gauge pointer to a gauge object
* @return angle of the scale
2017-04-21 17:11:47 +02:00
*/
static inline uint16_t lv_gauge_get_scale_angle(const lv_obj_t * gauge)
{
return lv_linemeter_get_scale_angle(gauge);
}
2020-03-06 13:14:25 +01:00
/**
* Get the offset for the gauge.
* @param gauge pointer to a gauge object
* @return angle offset (0..360)
*/
static inline uint16_t lv_gauge_get_angle_offset(lv_obj_t * gauge)
{
return lv_linemeter_get_angle_offset(gauge);
}
2019-11-30 11:41:18 +01:00
/**
* Get an image to display as needle(s).
* @param gauge pointer to a gauge object
* @return pointer to an `lv_img_dsc_t` variable or a path to an image
* (not an `lv_img` object). `NULL` if not used.
*/
const void * lv_gauge_get_needle_img(lv_obj_t * gauge, const void * img, lv_coord_t pivot_x, lv_coord_t pivot_y);
/**
* Get the X coordinate of the rotation center of the needle image
* @param gauge pointer to a gauge object
* @return the X coordinate of rotation center of the image
*/
lv_coord_t lv_gauge_get_needle_img_pivot_x(lv_obj_t * gauge);
/**
* Get the Y coordinate of the rotation center of the needle image
* @param gauge pointer to a gauge object
* @return the X coordinate of rotation center of the image
*/
lv_coord_t lv_gauge_get_needle_img_pivot_y(lv_obj_t * gauge);
/**********************
* MACROS
**********************/
2019-04-04 07:15:40 +02:00
#endif /*LV_USE_GAUGE*/
2017-07-09 15:32:49 +02:00
#ifdef __cplusplus
} /* extern "C" */
#endif
2017-07-09 15:32:49 +02:00
2019-04-04 07:15:40 +02:00
#endif /*LV_GAUGE_H*/