Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EEZ Flow: optionally export enum and struct definitions #228

Open
fietser28 opened this issue Dec 26, 2022 · 5 comments
Open

EEZ Flow: optionally export enum and struct definitions #228

fietser28 opened this issue Dec 26, 2022 · 5 comments
Assignees
Milestone

Comments

@fietser28
Copy link
Collaborator

Please add the option to export the enum and structs defined in a studio to an appropriate .h file (vars.h?)
This allows for a more consistent integration between flow and code.

@mvladic mvladic self-assigned this Dec 28, 2022
@prasimix prasimix added the task label May 18, 2023
@prasimix prasimix added this to the M15 milestone May 18, 2023
@prasimix prasimix changed the title flow: optionally export enum and struct definitions EEZ Flow: optionally export enum and struct definitions May 24, 2023
@mvladic
Copy link
Contributor

mvladic commented May 26, 2023

In the next version of EEZ Studio there will be a better support for enums in LVGL projects.

For example, if you have following enum definition in a project:

image

and following native variable definition in a project:

image

you can implement get and set native functions for this variable.

First, you must enable in vars.h file template option to generate enum definitions:

image

This will be already enabled for the new projects.

Now, in vars.c you can implement get and set functions like this:

MyEnum my_enum_var = MyEnum_Member2;

extern MyEnum get_var_my_enum_var() { return my_enum_var; }
extern void set_var_my_enum_var(MyEnum value) { my_enum_var = value; }

@mvladic
Copy link
Contributor

mvladic commented May 26, 2023

In the next version of EEZ Studio there will be a better support for structs in LVGL projects. First of all, struct variable can't be a native variable, it can only be a flow variable. But, it will be possible to access and modify these variables from the native code.

For example, let say you have following struct definition in a project:

image

and following global variable definition in a project:

image

First, you must include following in vars.h (it will be already include for the new project):

image

And you must have a new file template called structs.h (it will be already include for the new project):

#ifndef EEZ_LVGL_UI_STRUCTS_H
#define EEZ_LVGL_UI_STRUCTS_H

#include <eez/flow/flow.h>
#include <stdint.h>
#include <stdbool.h>

#include "vars.h"

using namespace eez;

//${eez-studio FLOW_STRUCTS}

//${eez-studio FLOW_STRUCT_VALUES}

#endif /*EEZ_LVGL_UI_STRUCTS_H*/

Now, you can access and modify struct variable like this:

#include "vars.h"
#include "structs.h"

// in this native action we will access the field values of options struct variable
void action_options_from_flow_to_native(lv_event_t* e) {
  // get options global variable as OptionsValue object which can be used to get/set field values
  OptionsValue options = flow::getGlobalVariable(FLOW_GLOBAL_VARIABLE_OPTIONS);

  // get switch_option field (boolean)
  bool switch_option = options.switch_option();
  
  // get num_options_arr (integer array)
  auto num_options_arr = options.num_options_arr();
  // iterate over array values
  for (unsigined int i = 0; i < num_options_arr.length(); i++) {
    // get i-th value in array
    int value = num_options_arr.at(i);
  }

  // get my_enum_field field (enum MyEnum)
  auto my_enum_field = options.my_enum_field();
}

// in this native action we will modify the field values of options struct variable
void action_options_from_native_to_flow(lv_event_t* e) {
  OptionsValue options = flow::getGlobalVariable(FLOW_GLOBAL_VARIABLE_OPTIONS);

  // modify switch_option field
  options.switch_option(false);

    // set "num_options_arr" field to [10, 20, 30]
    ArrayOfInteger arr(3);
    arr.at(0, 10);
    arr.at(1, 20);
    arr.at(2, 30);
    options.num_options_arr(arr);

  // modify my_enum_field
  options.my_enum_field(MyEnum_Member2);
}

mvladic added a commit that referenced this issue May 26, 2023
@fietser28
Copy link
Collaborator Author

If I try to include the structs.h in my project I get a lot of errors:

image

I checked al the necessary statements in the .h files and they look fine. I can't find where the StringValue/FloatValue should be defined.

I have a struct defined as:
image

Am I doing something wrong?

@mvladic
Copy link
Contributor

mvladic commented Jun 13, 2023

Did you update eez-framework to the latest version?

@fietser28
Copy link
Collaborator Author

fietser28 commented Jun 13, 2023

That fixed it. Thanks.

@mvladic mvladic modified the milestones: M15, M16 Jun 30, 2023
@mvladic mvladic modified the milestones: M16, M17 Jul 27, 2023
@mvladic mvladic modified the milestones: M17, v1.0 Sep 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants