Embedded C within a component. [Resolved]

Moderator: Benj

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

Re: Embedded C within a component.

Postby Benj » Mon Feb 25, 2019 9:53 pm

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 7 times
These users thanked the author Benj for the post:
medelec35 (Mon Feb 25, 2019 9:55 pm)
Rating: 5.88%
 

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

Re: Embedded C within a component.

Postby Benj » Mon Feb 25, 2019 10:18 pm

Without the size could be fine too, just remember to remove the line in the AddHeader that adds the size in the [] brackets.
These users thanked the author Benj for the post:
medelec35 (Mon Feb 25, 2019 10:38 pm)
Rating: 5.88%
 

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

Re: Embedded C within a component.

Postby Benj » Mon Feb 25, 2019 10:21 pm

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 12 times


Here is the exported component, Named CGenDemo under Misc.

Demo.fcpx
(2.45 KiB) Downloaded 6 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.
These users thanked the author Benj for the post:
medelec35 (Mon Feb 25, 2019 10:38 pm)
Rating: 5.88%
 

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8227
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2352 times
Been thanked: 3338 times
Contact:

Re: Embedded C within a component.

Postby medelec35 » Tue Feb 26, 2019 11:03 am

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

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.

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

Re: Embedded C within a component.

Postby Benj » Tue Feb 26, 2019 11:09 am

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:
These users thanked the author Benj for the post:
medelec35 (Tue Feb 26, 2019 11:11 am)
Rating: 5.88%
 

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8227
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2352 times
Been thanked: 3338 times
Contact:

Re: Embedded C within a component.

Postby medelec35 » Tue Feb 26, 2019 11:38 am

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.
These users thanked the author medelec35 for the post:
Benj (Tue Feb 26, 2019 12:42 pm)
Rating: 5.88%
 
Martin

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8227
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2352 times
Been thanked: 3338 times
Contact:

Re: Embedded C within a component.

Postby medelec35 » Tue Feb 26, 2019 1:09 pm

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
Properties1.png (92.16 KiB) Viewed 916 times

This is what I'm trying to replace:
Replace1.png
Replace1.png (58.93 KiB) Viewed 916 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 8 times
Flowcode1.fcfx
(7.35 KiB) Downloaded 7 times
Martin

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.

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

Re: Embedded C within a component.

Postby Benj » Tue Feb 26, 2019 1:51 pm

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.

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8227
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2352 times
Been thanked: 3338 times
Contact:

Re: Embedded C within a component.

Postby medelec35 » Tue Feb 26, 2019 2:34 pm

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
Local Return.png (51.47 KiB) Viewed 908 times
Martin

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.

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

Re: Embedded C within a component.

Postby Benj » Tue Feb 26, 2019 4:46 pm

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.
These users thanked the author Benj for the post:
medelec35 (Tue Feb 26, 2019 4:59 pm)
Rating: 5.88%
 

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8227
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2352 times
Been thanked: 3338 times
Contact:

Re: Embedded C within a component.

Postby medelec35 » Tue Feb 26, 2019 4:55 pm

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.
These users thanked the author medelec35 for the post:
Benj (Tue Feb 26, 2019 5:15 pm)
Rating: 5.88%
 
Martin

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.

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

Re: Embedded C within a component.

Postby Benj » Tue Feb 26, 2019 5:15 pm

Thanks Martin,

I've replied to your PM.
These users thanked the author Benj for the post:
medelec35 (Tue Feb 26, 2019 5:35 pm)
Rating: 5.88%
 

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8227
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2352 times
Been thanked: 3338 times
Contact:

Re: Embedded C within a component.

Postby medelec35 » Tue Feb 26, 2019 5:39 pm

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?
These users thanked the author medelec35 for the post:
Benj (Tue Feb 26, 2019 6:08 pm)
Rating: 5.88%
 
Martin

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.

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

Re: Embedded C within a component.

Postby Benj » Tue Feb 26, 2019 5:46 pm

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.
These users thanked the author Benj for the post:
medelec35 (Tue Feb 26, 2019 5:50 pm)
Rating: 5.88%
 

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8227
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2352 times
Been thanked: 3338 times
Contact:

Re: Embedded C within a component.

Postby medelec35 » Wed Feb 27, 2019 1:53 pm

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.
These users thanked the author medelec35 for the post:
Benj (Wed Feb 27, 2019 4:27 pm)
Rating: 5.88%
 
Martin

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8227
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2352 times
Been thanked: 3338 times
Contact:

Re: Embedded C within a component.

Postby medelec35 » Thu Feb 28, 2019 10:50 am

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
Dynamic Change1.png (3.93 KiB) Viewed 863 times

Dynamic Change2.png
Dynamic Change2.png (5.37 KiB) Viewed 862 times

Thanks Martin for your input.
Thanks again Ben, could not have complete the component without your valuable help.
These users thanked the author medelec35 for the post (total 2):
Benj (Thu Feb 28, 2019 12:04 pm) • kersing (Thu Feb 28, 2019 7:48 pm)
Rating: 11.76%
 
Martin

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.