as above, my data range from 0.0~100.0, float or double type
can meter support these data types or custom major tick labels to adjust the display requirement.
thanks
This is question?
If yes then try search float here Meter (lv_meter) — LVGL documentation and selfreply.
Hi @jianhaozh ,
Here is a code snippet based on lv_example_meter_1()
which demonstrates how to modify the labels on the meter to give a float representation. I think this is what you are asking:
static void meter_cb(lv_event_t * e) {
lv_obj_draw_part_dsc_t *dsc = (lv_obj_draw_part_dsc_t *)lv_event_get_param(e);
double value;
if( dsc->text != NULL ) { // Filter major ticks...
value = dsc->value / 10;
snprintf(dsc->text, sizeof(dsc->text), "%5.1f", value);
}
}
void meter_test( lv_obj_t *parent ) {
lv_obj_t *meter = lv_meter_create(parent);
lv_obj_center(meter);
lv_obj_set_size(meter, 300, 300);
/*Add a scale first*/
lv_meter_scale_t * scale = lv_meter_add_scale(meter);
lv_meter_set_scale_ticks(meter, scale, 41, 2, 10, lv_palette_main(LV_PALETTE_GREY));
lv_meter_set_scale_major_ticks(meter, scale, 8, 4, 15, lv_color_black(), 10);
lv_meter_set_scale_range(meter, scale, 0, 1000, 240, 135);
lv_meter_indicator_t * indic;
/*Add a blue arc to the start*/
indic = lv_meter_add_arc(meter, scale, 3, lv_palette_main(LV_PALETTE_BLUE), 0);
lv_meter_set_indicator_start_value(meter, indic, 0);
lv_meter_set_indicator_end_value(meter, indic, 200);
/*Make the tick lines blue at the start of the scale*/
indic = lv_meter_add_scale_lines(meter, scale, lv_palette_main(LV_PALETTE_BLUE), lv_palette_main(LV_PALETTE_BLUE),
false, 0);
lv_meter_set_indicator_start_value(meter, indic, 0);
lv_meter_set_indicator_end_value(meter, indic, 1000);
/*Add a red arc to the end*/
indic = lv_meter_add_arc(meter, scale, 3, lv_palette_main(LV_PALETTE_RED), 0);
lv_meter_set_indicator_start_value(meter, indic, 800);
lv_meter_set_indicator_end_value(meter, indic, 1000);
/*Make the tick lines red at the end of the scale*/
indic = lv_meter_add_scale_lines(meter, scale, lv_palette_main(LV_PALETTE_RED), lv_palette_main(LV_PALETTE_RED), false, 0);
lv_meter_set_indicator_start_value(meter, indic, 800);
lv_meter_set_indicator_end_value(meter, indic, 1000);
/*Add a needle line indicator*/
indic = lv_meter_add_needle_line(meter, scale, 4, lv_palette_main(LV_PALETTE_GREY), -10);
/*Add draw callback to override default values*/
lv_obj_add_event_cb(meter, meter_cb, LV_EVENT_DRAW_PART_BEGIN, NULL);
}
This is a scaling by a factor of 10 for 1 decimal place, if you want 2 decimal places you would scale by a factor of 100 and so on.
I hope that helps…
Kind Regards,
Pete
2 Likes
great thanks, it helps me a lot !!!
1 Like