Flowcode V6 : Adding C functions

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 6.

Moderator: Benj

Post Reply
User avatar
Steve_L
Flowcode v5 User
Posts: 10
Joined: Tue Feb 04, 2014 4:39 pm
Has thanked: 6 times
Contact:

Flowcode V6 : Adding C functions

Post by Steve_L »

Hello everyone!
I have to thank people who manage this forum because on each of my questions, someone answered me so quickly and each time it was realy helpfull.

This time, I am working with the EB006 on a 16F877A.

I'm working on a quite big project and I would like to use my own functions in my Flowcode project. I currently use C element to include some custom code.
The thing is that in C elements, I manipulate some variables with the "FCV_MYVAR" style which are created by Flowcode.
I would like to manipulate those variables with functions I have created and writen in an external .c file.
The final aim is for example to write something like this in the C element:

Code: Select all

FCV_MY_VAR = 4, FCV_MY_VAR2 = 0;

FCV_MY_VAR2 = my_function( FCV_MY_VAR );
And to have in an external .c file something like:

Code: Select all

int my_function( int var );

int my_function( int var ) {
      return ( var / 2 );
}
In this case, after the C element, my_var2 will equals to my_var/2=4/2=2 because it has been treated by my custom function.

I do not know if I am clear but I hope someone would be able to tell me how to do that.

Thank you in advance for your help :D

Regards,

Steve_L

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Flowcode V6 : Adding C functions

Post by Benj »

Hi Steve,

Have you seen this blog post it might be just the information your looking for.

http://matrixmultimedia.com/blog/?p=146

Let me know how you get on.

User avatar
Steve_L
Flowcode v5 User
Posts: 10
Joined: Tue Feb 04, 2014 4:39 pm
Has thanked: 6 times
Contact:

Re: Flowcode V6 : Adding C functions

Post by Steve_L »

Great! It seems to be exactly what I was looking for. I didn't knew this blog.

I maybe missed something because I don't succeed to make it appear in the component list.
  • 1) First I write my code with the "Supplementary code" button :

    Code: Select all

     int div2(int var){return var/2;}
  1. 2) Then I check "use supplementary header code" in the "Advanced" interface of the "Settings manager".
  • 3) I create a macro named "div2_mac", I add a parameter named "var" and Int type. It is weird because in my case, I can not uncheck "Make a local copy of the value". It is disabled. Then a choose an INT return value.
  • 4) I add a "calculation" element in the middle of the macro "div2_mac" and i write inside of it :

    Code: Select all

    .Return = div2(.var)
  • 5) In the Interface Manager, I choose the "Enbedded macro" type, I write "div2" in the "Native macro" field.
  • 6) Again in the "Settings manager", I name the component "div2_lib". Same for the "Cosmetic Name". I choose "Advanced" category, I uncheck "Use an image of the panel", I give an author and a description.
  • 7)There is no "Ok" button so I close this window.
  • 8) I look for my new component in "Advanced" but nothing about it.
Where is my mistake?
Do I have to post this question on the blog article or stay in the forum?

Thank you for your answers again.

Regards,

Steve_L

User avatar
JonnyW
Posts: 1230
Joined: Fri Oct 29, 2010 9:13 am
Location: Matrix Multimedia Ltd
Has thanked: 63 times
Been thanked: 290 times
Contact:

Re: Flowcode V6 : Adding C functions

Post by JonnyW »

Hi Steve.

You have not exported your component (by the sounds of it).

Go to Menu->File->Export Component...

You will see the component creator windows in a tabbed dialog (they are provided in the properties window as well for convenience). It is opened here to make last minute mods/reviews before export.

Flowcode will guide you through in that it will open a save dialog in a folder it will scan for components. If you can not save into that folder (some Windoze do not let you save to Program Files) you can add a folder to use for additional components in Menu->Edit->Global Options->Locations... (see http://www.matrixmultimedia.com/mmforum ... 404#p57255).

Once the component is exported as a FCPX file you should see it in the list you have selected.

PS:
I add a "calculation" element in the middle of the macro "div2_mac" and i write inside of it :

Code: Select all
.Return = div2(.var)
I am surprised Flowcode lets you do this. What the macro is is the simulation version of your embedded code. There is no need to add your code as well. When your component is exported it will use your macro for simulation and the C code for download. You can leave the macro empty if you do not need to simulate (the macro is needed so Flowcode knows how to call your C code).

Let me know how you get on,

Jonny

User avatar
Steve_L
Flowcode v5 User
Posts: 10
Joined: Tue Feb 04, 2014 4:39 pm
Has thanked: 6 times
Contact:

Re: Flowcode V6 : Adding C functions

Post by Steve_L »

Hello Jonny,

Oh yes exuse me! I didn't understood very well the article I guess :(

Now I know how to use it (component creation), I would like to know if it is possible to use BoostC functions as strlen() or strtok() with this method?

Moreover, I read somewhere that BoostC does not accept mathematical functions as pow(), sin(), sqrt()... Then I tried to install and use HI TEC compiler following procedure in this wiki page: http://www.matrixmultimedia.com/wiki/in ... ICmicro%29
The problem is that the directory "Dummy" does not exists in C:\Program Files\Flowcode 6\tools so Flowcode can not launch "DoNothing.exe" (i guess).


PS: I do not use simulation for this project so I removed the "calculation" element.

Sorry for all those questions but this part of Flowcode is a little bit confused to me :?

Have a good day :)

Regards,

Steve_L

User avatar
JonnyW
Posts: 1230
Joined: Fri Oct 29, 2010 9:13 am
Location: Matrix Multimedia Ltd
Has thanked: 63 times
Been thanked: 290 times
Contact:

Re: Flowcode V6 : Adding C functions

Post by JonnyW »

Evening.

No problems, ask as many questions as needed.

Yes, you can use any existing C function in this way - all you need to do is provide a macro to Flowcode so the system knows how to call your program. Bear in mind there are some conventions for this though, such as a string variable will always be paired with a length variable. There are ways round this, but they involve events.

As far as the DoNothing exe goes, this was an omission we have sorted for the next release. In the meantime it is located here:
http://www.matrixmultimedia.com/mmforum ... exe#p56176

I hope this helps,

Jonny

Post Reply