LVGL Canvas Draw Line - execute in lambda

Ok - with a bit of research and a lucky guess that the canvas name in the code is the same as it is named in yaml, I came up with this:

        - lambda: |-
            lv_draw_line_dsc_t line_dsc;
            lv_draw_line_dsc_init(&line_dsc);
            line_dsc.width = 1;
            line_dsc.color = lv_palette_lighten(LV_PALETTE_GREEN, 3);
            line_dsc.opa = LV_OPA_COVER;
            line_dsc.round_start = 0;
            line_dsc.round_end = 0;      
              
            for (int ax = 0; ax < 30; ++ax)  {
              int x1 = 90 + (90 * (cos((id(hist_dir)[ax]-90)*PI/180)));
              int y1 = 90 + (90 * (sin((id(hist_dir)[ax]-90)*PI/180)));
              int x2 = 90 + ((90-(70*id(hist_wind)[ax]/id(maxwind))) * (cos((id(hist_dir)[ax]-90)*PI/180)));
              int y2 = 90 + ((90-(70*id(hist_wind)[ax]/id(maxwind))) * (sin((id(hist_dir)[ax]-90)*PI/180)));
              lv_point_t line_points[2] = {
                { static_cast<lv_coord_t>(x1), static_cast<lv_coord_t>(y1) },
                { static_cast<lv_coord_t>(x2), static_cast<lv_coord_t>(y2) }
              };
              lv_canvas_draw_line(wind_stick, line_points, 2, &line_dsc);
            }

It works - no stack overflows - all 30 values from the array are written. I will let it run for a bit to test stability - if anyone else has suggestions for improvement they are welcome. Otherwise this time tomorrow I will mark as the solution.

Does anyone think it’s worthwhile logging an issue on Github for the overflow using larger values of YAML based loops?

1 Like