Trying to create a Line meter in v8.3?

Hi everyone!

I’ve been trying to create a simple line meter in LVGL 8.3.4. I followed the documentation and read through the library code however, I’ve been trying for a few days now. Can someone please point out what am I doing wrong?

image
This is a simple line meter in v7.0, which doesn’t work in V8.3 as the functions have been changed.

This is what I have so far just the ticks, can’t figure out how to use the indicator)

Here’s the LVGL code snippet:

void lv_example_meter_1(void)
{
    meter = lv_meter_create(lv_scr_act());
    lv_obj_center(meter);
    lv_obj_set_size(meter, 235, 235);

    /*Add a scale first*/
    lv_meter_scale_t * scale = lv_meter_add_scale(meter);
    lv_meter_set_scale_ticks(meter, scale, 36, 4, 20, lv_palette_main(LV_PALETTE_GREY));
    

    // remove the center dot
    lv_obj_remove_style(meter, NULL, LV_PART_INDICATOR);
    lv_meter_indicator_t * indic;

    indic = lv_meter_add_scale_lines(meter, scale, lv_palette_main(LV_PALETTE_PURPLE),
                                                lv_palette_main(LV_PALETTE_BLUE), true, 20);

    lv_meter_set_indicator_start_value(meter, indic, 0);
    lv_meter_set_indicator_start_value(meter, indic, 20);

}

And here’s the entire code:


#include <lvgl.h>

#include <Arduino_GFX_Library.h>

#define GFX_BL 21 // default backlight pin, you may replace DF_GFX_BL to actual backlight pin

/* More dev device declaration: https://github.com/moononournation/Arduino_GFX/wiki/Dev-Device-Declaration */
#if defined(DISPLAY_DEV_KIT)
Arduino_GFX *gfx = create_default_Arduino_GFX();
#else /* !defined(DISPLAY_DEV_KIT) */

/* More data bus class: https://github.com/moononournation/Arduino_GFX/wiki/Data-Bus-Class */
Arduino_DataBus *bus = create_default_Arduino_DataBus();

/* More display class: https://github.com/moononournation/Arduino_GFX/wiki/Display-Class */
Arduino_GFX *gfx = new Arduino_GC9A01(
  bus, 7 /* RST */, 1 /* rotation */, true /* IPS */);
#endif /* !defined(DISPLAY_DEV_KIT) */
/*******************************************************************************
 * End of Arduino_GFX setting
 ******************************************************************************/

/* Change to your screen resolution */
static uint32_t screenWidth;
static uint32_t screenHeight;
static lv_disp_draw_buf_t draw_buf;
static lv_color_t *disp_draw_buf;
static lv_disp_drv_t disp_drv;

/* Display flushing */
void my_disp_flush(lv_disp_drv_t *disp, const lv_area_t *area, lv_color_t *color_p)
{
  uint32_t w = (area->x2 - area->x1 + 1);
  uint32_t h = (area->y2 - area->y1 + 1);

#if (LV_COLOR_16_SWAP != 0)
  gfx->draw16bitBeRGBBitmap(area->x1, area->y1, (uint16_t *)&color_p->full, w, h);
#else
  gfx->draw16bitRGBBitmap(area->x1, area->y1, (uint16_t *)&color_p->full, w, h);
#endif

  lv_disp_flush_ready(disp);
}


/* CUSTOM LVGL FUNCTIONS*/

static lv_obj_t * meter;

// static void set_value(void * indic, int32_t v)
// {
//     lv_meter_set_indicator_value(meter, indic, v);
// }

/**
 * A simple meter
 */
void lv_example_meter_1(void)
{
    meter = lv_meter_create(lv_scr_act());
    lv_obj_center(meter);
    lv_obj_set_size(meter, 235, 235);

    /*Add a scale first*/
    lv_meter_scale_t * scale = lv_meter_add_scale(meter);
    lv_meter_set_scale_ticks(meter, scale, 36, 4, 20, lv_palette_main(LV_PALETTE_GREY));
    

    // remove the center dot
    lv_obj_remove_style(meter, NULL, LV_PART_INDICATOR);
    lv_meter_indicator_t * indic;

    indic = lv_meter_add_scale_lines(meter, scale, lv_palette_main(LV_PALETTE_PURPLE),
                                                lv_palette_main(LV_PALETTE_BLUE), true, 20);

    lv_meter_set_indicator_start_value(meter, indic, 0);
    lv_meter_set_indicator_start_value(meter, indic, 20);

}

/*----------------------*/
void setup()
{
  Serial.begin(115200);
  // Serial.setDebugOutput(true);
  // while(!Serial);
  Serial.println("LVGL Hello World Demo");

#ifdef GFX_EXTRA_PRE_INIT
  GFX_EXTRA_PRE_INIT();
#endif

  // Init Display
  gfx->begin();
  gfx->fillScreen(BLACK);

#ifdef GFX_BL
  pinMode(GFX_BL, OUTPUT);
  digitalWrite(GFX_BL, HIGH);
#endif

  lv_init();

  screenWidth = gfx->width();
  screenHeight = gfx->height();
#ifdef ESP32
  disp_draw_buf = (lv_color_t *)heap_caps_malloc(sizeof(lv_color_t) * screenWidth * 32, MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT);
#else
  disp_draw_buf = (lv_color_t *)malloc(sizeof(lv_color_t) * screenWidth * 32);
#endif
  if (!disp_draw_buf)
  {
    Serial.println("LVGL disp_draw_buf allocate failed!");
  }
  else
  {
    lv_disp_draw_buf_init(&draw_buf, disp_draw_buf, NULL, screenWidth * 32);

    /* Initialize the display */
    lv_disp_drv_init(&disp_drv);
    /* Change the following line to your display resolution */
    disp_drv.hor_res = screenWidth;
    disp_drv.ver_res = screenHeight;
    disp_drv.flush_cb = my_disp_flush;
    disp_drv.draw_buf = &draw_buf;
    lv_disp_drv_register(&disp_drv);

    /* Initialize the (dummy) input device driver */
    static lv_indev_drv_t indev_drv;
    lv_indev_drv_init(&indev_drv);
    indev_drv.type = LV_INDEV_TYPE_POINTER;
    lv_indev_drv_register(&indev_drv);

    lv_example_meter_1();


  }
}

void loop()
{
  lv_timer_handler(); /* let the GUI do its work */
  delay(5);
}


Any help is really appreciated!