Hello @TridentTD and @ZooM
Thank you for the relevant question and answer🙂
I’m also looking into creating a class and animating or moving the meter scale elements.
As a LVGL simulator I use
Version 9.3
I took the
C++ class
from this topic as a basis.
The class is written according to the classic scheme using two files:
hdg_class.h
hdg_class.cpp
Archive in attachment.
hdg_class.zip (2.2 KB)
#include "lvgl.h"
#include "app_hal.h"
#include "hdg_class.h"
#ifdef ARDUINO
#include <Arduino.h>
void setup() {
lv_init();
hal_setup();
// lv_demo_widgets();
}
void loop() {
hal_loop(); /* Do not use while loop in this function */
}
#else
int main(void)
{
lv_init();
hal_setup();
Hdg_class Meter1(lv_screen_active(), // screen
"1", // title
"Hello LVGL!", // meter name
120, // pos_x
120, // pos_y
0, // min_value
300, // max_value
250, // size_x
250 // size_y
);
// Hdg_class Meter1(hdg_meter, "1", "Hello LVGL!", 150, 150, 0, 300, 90, 120);
// Meter1.set(300); // set value with ANIM
// Meter1.set(300, 5); // set value with ANIM and 5 repeat
Meter1.set(75, LV_ANIM_OFF); // set value without ANIM
hal_loop();
// lv_scale_set_rotation(hdg_scale, HDG);
}
#endif /*ARDUINO*/
I added a class to the ability to repeat the animation, using the function:
lv_anim_set_repeat_count(&anim, repeat);
But for some reason the animation is repeated only once, but if you add the value manually:
lv_anim_set_repeat_count(&anim, 3);
Then the repetition will be 3 times.
I also tried to make a looped animation back and forth, in the file
hdg_class.cpp
there is a commented code of the modified function at the end of the file.
But when you run this code, the animation is performed once, then the LVGL simulator application crashes and the console shows this error:
*** [execute] Error 3221225477
The animation looks good
In general, this is all just a joke, I was just looking for ways to translate the rendering functions into
C++ class
And I found it, thanks again to the author of the topic and for the answers.
I have a different question, are there ways to animate or control the entire scale rotation position?
I use the EEZ_studio program to draw graphics for LVGL.
In this program, on the STYLES tab, you can set the parameters for rotating the scale and pivot.
The code that the program exports is this
// HDG scale
hdg_scale = lv_scale_create(hdg_screen);
lv_obj_set_pos(hdg_scale, 40, 40);
lv_obj_set_size(hdg_scale, 400, 400);
lv_scale_set_mode(hdg_scale, LV_SCALE_MODE_ROUND_INNER);
lv_obj_set_style_bg_opa(hdg_scale, LV_OPA_60, 0);
lv_obj_set_style_bg_color(hdg_scale, lv_color_black(), 0);
lv_obj_set_style_transform_pivot_x(hdg_scale, 200, LV_PART_INDICATOR | LV_STATE_DEFAULT);
lv_obj_set_style_transform_pivot_y(hdg_scale, 200, LV_PART_INDICATOR | LV_STATE_DEFAULT);
lv_obj_set_style_align(hdg_scale, LV_ALIGN_DEFAULT, LV_PART_INDICATOR | LV_STATE_DEFAULT);
lv_obj_set_style_transform_rotation(hdg_scale, 90, LV_PART_INDICATOR | LV_STATE_DEFAULT);
But the paradox of the situation is that when you start to rotate the scale
lv_obj_set_style_transform_rotation
in the LVGL simulator, only the label numbers rotate, but not the scale - as it was done in the EEZ_studio program.
I need the meter scale to rotate around the axis by a given value, but I can’t understand - is it possible in principle to implement this using the LVGL library?
I tried to rotate the scale in an infinite loop directly
lv_scale_set_angle_range(hdg_scale, i++);
And I got this picture:
Thanks for the tips and help!