Overview

The gauge is a meter with scale labels and needles. You can use the lv_gauge_set_scale(gauge, angle, line_num, label_cnt ) function to adjust the scale angle and the number of the scale lines and labels. The default settings are: 220 degree angle, 6 scale label and 21 lines.

The gauge can show more then one needles . Use the lv_gauge_set_needle_count(gauge, needle_num, color_array) function the set the number of needles and an array with colors for each needle. (The array must be static or global variable)

You can use lv_gauge_set_value(gauge, needle_id, value) to set the value of a needle.

To set a critical value use lv_gauge_set_critical_value(gauge, value). The scale color ill be changed to line.color after ti value. (default: 80)

The range of the gauge can be specified by lv_gauge_set_range(gauge, min, max)

Style usage

The gauge uses one style which can be set by lv_gauge_set_style(gauge, &style) The gauge's properties are derived from the following style attributes:

  • body.main_color line's color at the beginning of the scale
  • body.grad_color line's color at the end of the scale (gradient with main color)
  • body.padding.hor line length
  • body.padding.inner label distance from the scale lines
  • line.width line width
  • line.color line's color after the critical value
  • text.font/color/letter_space label attributes

Notes

Example of Gauge in Littlev Graphics Library

						/*Create a style*/
static lv_style_t style;
lv_style_copy(&style, &lv_style_pretty_color);
style.body.main_color = LV_COLOR_HEX3(0x666);     /*Line color at the beginning*/
style.body.grad_color =  LV_COLOR_HEX3(0x666);    /*Line color at the end*/
style.body.padding.hor = 10;                      /*Scale line length*/
style.body.padding.inner = 8 ;                    /*Scale label padding*/
style.body.border.color = LV_COLOR_HEX3(0x333);   /*Needle middle circle color*/
style.line.width = 3;
style.text.color = LV_COLOR_HEX3(0x333);
style.line.color = LV_COLOR_RED;                  /*Line color after the critical value*/


/*Describe the color for the needles*/
static lv_color_t needle_colors[] = {LV_COLOR_BLUE, LV_COLOR_ORANGE, LV_COLOR_PURPLE};

/*Create a gauge*/
lv_obj_t * gauge1 = lv_gauge_create(lv_scr_act(), NULL);
lv_gauge_set_style(gauge1, &style);
lv_gauge_set_needle_count(gauge1, 3, needle_colors);
lv_obj_align(gauge1, NULL, LV_ALIGN_CENTER, 0, 20);

/*Set the values*/
lv_gauge_set_value(gauge1, 0, 10);
lv_gauge_set_value(gauge1, 1, 20);
lv_gauge_set_value(gauge1, 2, 30);

lv_obj_t *

lv_gauge_create

(lv_obj_t * par, lv_obj_t * copy);

Create a gauge objects

par pointer to an object, it will be the parent of the new gauge

copy pointer to a gauge object, if not NULL then the new object will be copied from it

return pointer to the created gauge

void

lv_gauge_set_needle_count

(lv_obj_t * gauge, uint8_t needle_cnt, const lv_color_t * colors);

Set the number of needles

gauge pointer to gauge object

needle_cnt new count of needles

colors an array of colors for needles (with 'num' elements)

void

lv_gauge_set_value

(lv_obj_t * gauge, uint8_t needle_id, int16_t value);

Set the value of a needle

gauge pointer to a gauge

needle_id the id of the needle

value the new value

void

lv_gauge_set_range

(lv_obj_t *gauge, int16_t min, int16_t max);

Set minimum and the maximum values of a gauge

gauge pointer to he gauge object

min minimum value

max maximum value

void

lv_gauge_set_critical_value

(lv_obj_t * gauge, int16_t value);

Set a critical value on the scale. After this value 'line.color' scale lines will be drawn

gauge pointer to a gauge object

value the critical value

void

lv_gauge_set_scale

(lv_obj_t * gauge, uint16_t angle, uint8_t line_cnt, uint8_t label_cnt);

Set the scale settings of a gauge

gauge pointer to a gauge object

angle angle of the scale (0..360)

line_cnt count of scale lines

label_cnt count of scale labels

void

lv_gauge_set_style

(lv_obj_t *gauge, lv_style_t *bg);

Set the styles of a gauge

gauge pointer to a gauge object

bg set the style of the gauge

int16_t

lv_gauge_get_value

(lv_obj_t * gauge, uint8_t needle);

Get the value of a needle

gauge pointer to gauge object

needle the id of the needle

return the value of the needle [min,max]

uint8_t

lv_gauge_get_needle_count

(lv_obj_t * gauge);

Get the count of needles on a gauge

gauge pointer to gauge

return count of needles

int16_t

lv_gauge_get_min_value

(lv_obj_t * lmeter);

Get the minimum value of a gauge

gauge pointer to a gauge object

return the minimum value of the gauge

int16_t

lv_gauge_get_max_value

(lv_obj_t * lmeter);

Get the maximum value of a gauge

gauge pointer to a gauge object

return the maximum value of the gauge

int16_t

lv_gauge_get_critical_value

(lv_obj_t * gauge);

Get a critical value on the scale.

gauge pointer to a gauge object

return the critical value

uint8_t

lv_gauge_get_label_count

(lv_obj_t * gauge);

Set the number of labels (and the thicker lines too)

gauge pointer to a gauge object

return count of labels

uint8_t

lv_gauge_get_line_count

(lv_obj_t * gauge);

Get the scale number of a gauge

gauge pointer to a gauge object

return number of the scale units

uint16_t

lv_gauge_get_scale_angle

(lv_obj_t * gauge);

Get the scale angle of a gauge

gauge pointer to a gauge object

return angle of the scale

lv_style_t *

lv_gauge_get_style

(lv_obj_t *gauge);

Get the style of a gauge

gauge pointer to a gauge object

return pointer to the gauge's style

LittlevGL - Open-source Embedded GUI Library

LittlevGL is a free and open-source graphics library providing everything you need to create embedded GUI with easy-to-use graphical elements, beautiful visual effects and low memory footprint.

If you like LittlevGL, please
support its deveopment!


The founder of Littlev Graphics Library (LittlevGL) and related software modules is:
Gábor Kiss-Vámosi
All Rights Reserved ©  2018 Hungary