Embedded C within a component. [Resolved]

Moderator: Benj

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: Embedded C within a component.

Post by Benj »

This demo is significantly improved in the Ev_Property respect. It will work with any number of properties as long as the the naming of the property variables remains consistent.

It also auto calculates the sizes for you now too :D .
Attachments
CGenDemo2.fcfx
(19.08 KiB) Downloaded 201 times

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: Embedded C within a component.

Post by Benj »

Without the size could be fine too, just remember to remove the line in the AddHeader that adds the size in the [] brackets.

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: Embedded C within a component.

Post by Benj »

There was a bug in example 2 in the Ev_Property loop. Now fixed with an additional MaxImages property. Also another bug in the ShowImages macro. Need to learn to slow down and take my time more but my dad rang me mid flow.
CGenDemo3.fcfx
(19.33 KiB) Downloaded 204 times
Here is the exported component, Named CGenDemo under Misc.
Demo.fcpx
(2.45 KiB) Downloaded 211 times
This is the generated header code from the exported component.

Code: Select all

//AddHeader Added Content

const char Image0[8] = {1,2,3,4,5,6,7,8};
const char Image1[4] = {1,2,3,4};

//AddHeader Added Content End
And here is the switch statement.

Code: Select all

    switch (FCL_IMAGEINDEX)
    {
        case 1:
        {
            #if (1) // 2 > 1

                FCV_RETURN = Image1[FCL_DATAPOINTER];

            // #else

            //Code has been optimised out by the pre-processor
            #endif

            break;
        }
        case 2:
        {
            #if (0) // 2 > 2

            //Code has been optimised out by the pre-processor
            // #else

            #endif

            break;
        }
        case 3:
        {
            #if (0) // 2 > 3

            //Code has been optimised out by the pre-processor
            // #else

            #endif

            break;
        }
        default:
        {
            #if (1) // 2 > 0

                FCV_RETURN = Image0[FCL_DATAPOINTER];

            // #else

            //Code has been optimised out by the pre-processor
            #endif

        }
    }
I've also noticed the ImageData properties should be "Line Of Text" type properties and not "Multiple Lines Of Text" as carriage returns in the data will likely break the code generation without correct \ termination.

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: Embedded C within a component.

Post by medelec35 »

Hi Ben,
You have Image Data 0 & Image Data 1 within properties.
All the image data (from 1 to whatever is required) will only be contained within supplementary code window in the form of:

Code: Select all

char const unsigned  Image1[]={75,165,10,153,74,169,74,173,73,165,42,153,241,177,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,09,161,138,193,43,234,235,209,138,189,138,185,170,197,11,226,11,222,41,161,51,186,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,42,157,43,230,170,193,138,189,11,226,108,250,108,254,76,246,0,0,0};
char const unsigned  Image2[] =
{255,127,255,127,255,127,255,127,255,127,255,127,255,127,255,127,255,127,255,127,255,127,255,127,255,127,255,127,255,127,255,127,255,127,255,127,255,127,239,189,157,243,90,235,83,202,255,127,255,127,255,127,255,127,255,127,255,127,255,127,255,127,255,127,
255,127,255,127,255,127,255,127,255,127,255,127,255,127,255,127,255,127,255,127,255,127,255,127,255,127,255,127,255,127,255,127,255,127,255,127,255,127,255,127,255,127,239,189,157,243,90,235,83,202,255,127,255,127,255,127,255,127,255,127,255,127,255,127,
255,127,255,127,255,127,255,127,255,127,255,127,255,127,255,127,255,127,255,127,255,127,255,127,255,127,255,127,255,127,255,127,255,127};
char const unsigned  Image3[] =
{,150,255,150,255,238,185,192,253,192,125,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,96,126,96,254,96,254,
128,254,128,254,160,254,160,254,192,254,192,254,224,254,0,127,0,0,64,125,32,253,32,253,64,253,64,253,96,253,96,253,128,253,128,253,173,169,150,255,150,255,15,190,192,253,192,125,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,96,254,128,254,128,254,160,254,160,254,192,254,192,254,192,254,224,254,224,126,0,0,32,125,32,253,64,253,64,253,96,253,96,253,96,253,128,253};
etc.


Can the properties just be deleted so the data within supplementary code window be picked up instead?
If the c code within ShowImage was left as:

Code: Select all

FCV_RETURN = Image1[FCL_DATAPOINTER];

Code: Select all

 FCV_RETURN = Image2[FCL_DATAPOINTER];

Code: Select all

 FCV_RETURN = Image3[FCL_DATAPOINTER];
etc I'm assuming all will work ok without any changes?
Martin

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: Embedded C within a component.

Post by Benj »

Hi Martin,

Yes you can simply have the array declarations in the supplementary code and then reference using the NumImages decisions and the switch statement.

I was probably over engineering things :wink:

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: Embedded C within a component.

Post by medelec35 »

Thanks Ben,
So I will just need number of images.
The Max number is determined by how many switch statements are added within ShowImage macro.
I think it would be better is this number was generated via a variable set within ShowImage macro

I will make adjustments and let you know how I get on.
Martin

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: Embedded C within a component.

Post by medelec35 »

I'm going to manually add image size.
The panel properties I'm happy with as it sets the value to my manually added MaxNumberOfImages:
Properties1.png
(92.16 KiB) Downloaded 3944 times
This is what I'm trying to replace:
Replace1.png
(58.93 KiB) Downloaded 3944 times
Modified flowchart and saved as a component (attached).
Created a flowchart using the new component (also attached).
Compile and got:

Code: Select all

Flowcode1.c:
    84:	char const unsigned Image1[]={75,165,10,153,74,169,74,173,73,165,42,153,241,177,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,09,161,138,193,43,234,235,209,138,189,138,185,170,197,11,226,11,222,41,161,51,186,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,42,157,43,230,170,193,138,189,11,226,108,250,108,254,76,246,0,0,0};
	                            ^ (1098) conflicting declarations for variable "Image1" (Flowcode1.c:68)
(908) exit status = 1
(908) exit status = 1

Error returned from [xc8.exe]

C:\Program Files (x86)\Flowcode\Compilers\pic\batch\pic_xc8_comp.bat reported error code 1
Most likely I have mucked it up somehow?

Unfortunately, I believe this is to be advance component design.
I'm just learning basic component design, so feel I'm running before walking.
Attachments
CGenDemo3.fcfx
(20.35 KiB) Downloaded 205 times
Flowcode1.fcfx
(7.35 KiB) Downloaded 211 times
Martin

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: Embedded C within a component.

Post by Benj »

Hi Martin,

You can get rid of all the code in the Ev_AddHeader macro as this just declares the ROM arrays but you are already doing this in the supplementary code window.

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: Embedded C within a component.

Post by medelec35 »

Hi Ben,
completely removed all the code within AddHeader and deleted AddHeader from Events.
Exported component and refreshed the flwochart using the component.
on compiling I get:

Code: Select all

Flowcode1.c:
    72:	char const unsigned Image1[]={75,165,10,153,74,169,74,173,73,165,42,153,241,177,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,09,161,138,193,43,234,235,209,138,189,138,185,170,197,11,226,11,222,41,161,51,186,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,42,157,43,230,170,193,138,189,11,226,108,250,108,254,76,246,0,0,0};
	                                                                                                                 (223) digit out of range ^
Flowcode1.c: FCD_040e1_CGenDemo1__ShowImage()
   115:	FCV_RETURN = Image1[FCL_DATAPOINTER];
	^ (192) undefined identifier "FCV_RETURN"
	                    ^ (192) undefined identifier "FCL_DATAPOINTER"
   128:	FCV_RETURN = Image2[FCL_DATAPOINTER];
	^ (192) undefined identifier "FCV_RETURN"
	                    ^ (192) undefined identifier "FCL_DATAPOINTER"
(908) exit status = 1
(908) exit status = 1

Error returned from [xc8.exe]

C:\Program Files (x86)\Flowcode\Compilers\pic\batch\pic_xc8_comp.bat reported error code 1



FINISHED
I have added two component macros as NumImages is also set to 2

Now I have changed

Code: Select all

FCV_RETURN = Image1[FCL_DATAPOINTER];
to

Code: Select all

FCL_RETURN = Image1[FCL_DATAPOINTER];
but sill the RETURN is undeclared even though there is a local Return:
Local Return.png
(51.47 KiB) Downloaded 3936 times
Martin

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: Embedded C within a component.

Post by Benj »

Hi Martin,

Did you send me the right file?

If you did then where in your project do you reference the Image1 variables using the switch icon? I'll make the changes for you just need to know where to look.

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: Embedded C within a component.

Post by medelec35 »

Hi Ben,
Benj wrote:Did you send me the right file?
Yes I believe I did, but there are so many macros I should have said, sorry.
Benj wrote:where in your project do you reference the Image1
The Code within switch statement is in

Code: Select all

StoreBitmapData
call macro
Benj wrote:'ll make the changes for you just need to know where to look.
Fantastic, Thanks Ben you're a star.
Martin

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: Embedded C within a component.

Post by Benj »

Thanks Martin,

I've replied to your PM.

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: Embedded C within a component.

Post by medelec35 »

Thanks Ben, it's really appreciated.
I will check it out and let you know how the testing went.
Does it work as is , or only will work when the whole flowchart is converted to a component?
Martin

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: Embedded C within a component.

Post by Benj »

Hi Martin,

The decisions will generate if until you export and then they will use #if.

So you will probably get compile errors until you export.

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: Embedded C within a component.

Post by medelec35 »

Hi Ben,
Thank you for the updated flowchart.
Wow, You're a genius!
I don't get an undefined message relating to ImageX unless I deliberately set Numimages to 4 when I have 3 images stored.
This is expected of course:

Code: Select all

Component 480 x 275 47K40 Test1.c: FCD_00fa1_FT810__StoreBitmapData()
  3499:	FCL_DATA = Image4[FCL_DATAPOINTER];
	           ^ (192) undefined identifier "Image4"
	           (981) pointer required ^
	           (981) pointer required ^
Component 480 x 275 47K40 Test1.c: main()
  4285:	FCD_00fa1_FT810__Initialise();
	^ (361) function declared implicit int (warning)
(908) exit status = 1
(908) exit status = 1

Error returned from [xc8.exe]

C:\Program Files (x86)\Flowcode\Compilers\pic\batch\pic_xc8_comp.bat reported error code 1
Thank you for all your help.

Flowchart compiles OK with the component added. :D

Now for testing.
Martin

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: Embedded C within a component.

Post by medelec35 »

Update:
Component is working great after exporting.
After adding another 30 switch branches (50 in total), I found the example CGenDemo really useful as well.
I have added a routine within both EV, Components,Property and EV, Components, Initialise to dynamically update total images left:
Dynamic Change1.png
(3.93 KiB) Downloaded 3891 times
Dynamic Change2.png
(5.37 KiB) Downloaded 3890 times
Thanks Martin for your input.
Thanks again Ben, could not have complete the component without your valuable help.
Martin

Post Reply