There are no examples in the Arduino IDE for LVGL LV_CHART_TYPE_SCATTER. I've looked at a number of versions (v8.4, v9.0, v9.5) of the github repo for LVGL and lv_example_chart_7.c (lvgl/examples/widgets/chart/lv_example_chart_7.c at release/v9.0 · lvgl/lvgl · GitHub). All LVGL versions seem to have the same lv_example_chart_7.c and all versions contain references to symbols that don't exist in the Arduino_H7_Video library. Compiling for GIGA and GIGA DISPLAY shield.
By some poking around, and stripping out missing features, I got the example plot working with static colors just fine. But I'm trying to manipulate scatter plot points in the same way as the demo to fade out older points. The example code is from a significantly different LVGL version.
This code cribbed from the examples and stripped down works great:
lv_obj_t *chart = lv_chart_create(grid);
lv_obj_set_grid_cell(chart, LV_GRID_ALIGN_STRETCH, 0, 2, LV_GRID_ALIGN_STRETCH, 1, 1);
lv_obj_set_size(chart, lv_obj_get_width(obj), lv_obj_get_height(obj));
lv_obj_align(chart, LV_ALIGN_CENTER, 0, 0);
lv_obj_add_event_cb(chart, draw_event_cb, LV_EVENT_DRAW_MAIN_BEGIN, NULL);
lv_obj_set_style_line_width(chart, 0, LV_PART_ITEMS); /*Remove the lines*/
lv_chart_set_type(chart, LV_CHART_TYPE_SCATTER);
lv_chart_set_range(chart, LV_CHART_AXIS_PRIMARY_X, CHART_X_MIN, CHART_X_MAX);
lv_chart_set_range(chart, LV_CHART_AXIS_PRIMARY_Y, CHART_Y_MIN, CHART_Y_MAX);
lv_chart_set_point_count(chart, GRAPH_LEN);
lv_chart_set_div_line_count(chart, 8, 8);
lv_chart_series_t *ser = lv_chart_add_series(chart, lv_palette_main(LV_PALETTE_RED), LV_CHART_AXIS_PRIMARY_Y);
[...]
lv_chart_set_next_value2(chart, ser, x, y);
This callback from the example is for some other version of LVGL:
static void draw_event_cb(lv_event_t *e) {
lv_draw_task_t * draw_task = lv_event_get_draw_task(e);
lv_draw_dsc_base_t * base_dsc = draw_task->draw_dsc;
if(base_dsc->part == LV_PART_INDICATOR) {
lv_obj_t * obj = lv_event_get_target(e);
lv_chart_series_t * ser = lv_chart_get_series_next(obj, NULL);
lv_draw_rect_dsc_t * rect_draw_dsc = draw_task->draw_dsc;
uint32_t cnt = lv_chart_get_point_count(obj);
/*Make older value more transparent*/
rect_draw_dsc->bg_opa = (LV_OPA_COVER * base_dsc->id2) / (cnt - 1);
/*Make smaller values blue, higher values red*/
int32_t * x_array = lv_chart_get_x_array(obj, ser);
int32_t * y_array = lv_chart_get_y_array(obj, ser);
/*dsc->id is the tells drawing order, but we need the ID of the point being drawn.*/
uint32_t start_point = lv_chart_get_x_start_point(obj, ser);
uint32_t p_act = (start_point + base_dsc->id2) % cnt; /*Consider start point to get the index of the array*/
lv_opa_t x_opa = (x_array[p_act] * LV_OPA_50) / 200;
lv_opa_t y_opa = (y_array[p_act] * LV_OPA_50) / 1000;
rect_draw_dsc->bg_color = lv_color_mix(lv_palette_main(LV_PALETTE_RED),
lv_palette_main(LV_PALETTE_BLUE),
x_opa + y_opa);
}
}
compiling:
/Users/john/Documents/Arduino/giga-2core-main/giga-2core-main.ino: In function 'void draw_event_cb(lv_event_t*)':
/Users/john/Documents/Arduino/giga-2core-main/giga-2core-main.ino:445:46: error: invalid use of incomplete type 'lv_draw_task_t {aka struct _lv_draw_task_t}'
lv_draw_dsc_base_t * base_dsc = draw_task->draw_dsc;
^~
In file included from /Users/john/Documents/Arduino/libraries/lvgl/src/../src/lv_init.h:17:0,
from /Users/john/Documents/Arduino/libraries/lvgl/src/../lvgl.h:21,
from /Users/john/Documents/Arduino/libraries/lvgl/src/lvgl.h:16,
from /Users/john/Documents/Arduino/giga-2core-main/giga-2core-main.ino:3:
/Users/john/Documents/Arduino/libraries/lvgl/src/../src/misc/lv_types.h:121:16: note: forward declaration of 'lv_draw_task_t {aka struct _lv_draw_task_t}'
typedef struct _lv_draw_task_t lv_draw_task_t;
^~~~~~~~~~~~~~~
/Users/john/Documents/Arduino/giga-2core-main/giga-2core-main.ino:445:48: error: invalid use of incomplete type 'lv_draw_task_t {aka struct _lv_draw_task_t}'
lv_draw_dsc_base_t * base_dsc = draw_task->draw_dsc;
^~~~~~~~
In file included from /Users/john/Documents/Arduino/libraries/lvgl/src/../src/lv_init.h:17:0,
from /Users/john/Documents/Arduino/libraries/lvgl/src/../lvgl.h:21,
from /Users/john/Documents/Arduino/libraries/lvgl/src/lvgl.h:16,
from /Users/john/Documents/Arduino/giga-2core-main/giga-2core-main.ino:3:
/Users/john/Documents/Arduino/libraries/lvgl/src/../src/misc/lv_types.h:121:16: note: forward declaration of 'lv_draw_task_t {aka struct _lv_draw_task_t}'
typedef struct _lv_draw_task_t lv_draw_task_t;
^~~~~~~~~~~~~~~
/Users/john/Documents/Arduino/giga-2core-main/giga-2core-main.ino:447:45: error: invalid conversion from 'void*' to 'lv_obj_t* {aka _lv_obj_t*}' [-fpermissive]
lv_obj_t * obj = lv_event_get_target(e);
~~~~~~~~~~~~~~~~~~~^~~
/Users/john/Documents/Arduino/giga-2core-main/giga-2core-main.ino:449:55: error: invalid use of incomplete type 'lv_draw_task_t {aka struct _lv_draw_task_t}'
lv_draw_rect_dsc_t * rect_draw_dsc = draw_task->draw_dsc;
^~
In file included from /Users/john/Documents/Arduino/libraries/lvgl/src/../src/lv_init.h:17:0,
from /Users/john/Documents/Arduino/libraries/lvgl/src/../lvgl.h:21,
from /Users/john/Documents/Arduino/libraries/lvgl/src/lvgl.h:16,
from /Users/john/Documents/Arduino/giga-2core-main/giga-2core-main.ino:3:
/Users/john/Documents/Arduino/libraries/lvgl/src/../src/misc/lv_types.h:121:16: note: forward declaration of 'lv_draw_task_t {aka struct _lv_draw_task_t}'
typedef struct _lv_draw_task_t lv_draw_task_t;
^~~~~~~~~~~~~~~
/Users/john/Documents/Arduino/giga-2core-main/giga-2core-main.ino:449:57: error: invalid use of incomplete type 'lv_draw_task_t {aka struct _lv_draw_task_t}'
lv_draw_rect_dsc_t * rect_draw_dsc = draw_task->draw_dsc;
^~~~~~~~
In file included from /Users/john/Documents/Arduino/libraries/lvgl/src/../src/lv_init.h:17:0,
from /Users/john/Documents/Arduino/libraries/lvgl/src/../lvgl.h:21,
from /Users/john/Documents/Arduino/libraries/lvgl/src/lvgl.h:16,
from /Users/john/Documents/Arduino/giga-2core-main/giga-2core-main.ino:3:
/Users/john/Documents/Arduino/libraries/lvgl/src/../src/misc/lv_types.h:121:16: note: forward declaration of 'lv_draw_task_t {aka struct _lv_draw_task_t}'
typedef struct _lv_draw_task_t lv_draw_task_t;
^~~~~~~~~~~~~~~
Not sure where to go next. I'm probably just missing something obvious with versions.
TIA