eez-open / studio

Cross-platform low-code GUI and automation
https://www.envox.eu/studio/studio-introduction/
GNU General Public License v3.0
299 stars 69 forks source link

[LVGL] Var types incompatible in screen tick #347

Open Luke-Shepp opened 2 months ago

Luke-Shepp commented 2 months ago

My generated screens.c looks something like this;

void tick_screen_main() {
    [...trimmed...]
    {
        const char *new_val = get_var_speed();
        const char *cur_val = lv_label_get_text(objects.obj2);
        if (strcmp(new_val, cur_val) != 0) {
            tick_value_change_obj = objects.obj2;
            lv_label_set_text(objects.obj2, new_val);
            tick_value_change_obj = NULL;
        }
    }
    [....trimmed....]
}

get_var_speed is defined in the generated vars.h as:

extern float get_var_speed();

That is because I have chosen it to be a float value in the UI:

Screenshot 2024-04-22 at 19 16 43

Due to the type mismatch, the error on build is:

ui/screens.c: In function 'tick_screen_main':
ui/screens.c:166:31: error: incompatible types when initializing type 'const char *' using type 'float'
  166 |         const char *new_val = get_var_speed();
      |                               ^~~~~~~~~~~~~
ui/screens.c: In function 'tick_screen_settings':

There's another warning for another variable, but it's not a hard error this one:

ui/screens.c:292:31: warning: initialization of 'const char *' from 'int32_t' {aka 'long int'} makes pointer from integer without a cast [-Wint-conversion]
  292 |         const char *new_val = get_var_wifi_state();
      |                               ^~~~~~~~~~~~~~~~~~
make: *** [ui/screens.o] Error 1
mvladic commented 2 months ago

You are not using EEZ Flow, so conversion of variable types, in this case float to string (const char * in C) will not be done in generated code. That means, variable speed in your case must be of type string not float as Label widget is expecting string. But, we can say this is bug since there is no error reported for this case. Also, we should consider to put type conversion code in generated code in this case even if EEZ Flow is not used.