Embedded C within a component. [Resolved]

Moderator: Benj

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:

Embedded C within a component. [Resolved]

Postby medelec35 » Mon Feb 18, 2019 10:04 am

I'm currently creating a component that has to retrieve data from Supplementary code Too much data for LUT's)
For example, very cut down data:

Code: Select all

char const unsigned  Image1[] ={175,165,10,153,74,169,74,173,73};
,

Code: Select all

char const unsigned  Image2[] ={41,165,41,165,41,37,,0,0,74,169,41,165,41,165,41,37,0,140,49,10};

....

Code: Select all

char const unsigned  Image11[] ={140,177,16,194,116,206,57,231,255,127,255,127,255,127,127,255,127,255,127
157,243,157,243,157};


For creating a component the Image variable followed by a number has to be unique and match all entries what's in the supplementary code window in the format of

Code: Select all

FCL_DATA = Image1[FCL_DATAPOINTER];
,

Code: Select all

FCL_DATA = Image2[FCL_DATAPOINTER];

....

Code: Select all

FCL_DATA = Image11[FCL_DATAPOINTER];

Currently I'm just using a loop:
RetSupData1.png
RetSupData1.png (66.67 KiB) Viewed 1297 times

The problem is there is not a fixed amount of entries within supplementary code window,
so it's not as easy as if there is a fixed 11 images for example.
Martin

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

mnf
Valued Contributor
Valued Contributor
Posts: 429
Joined: Wed May 31, 2017 11:57 am
Has thanked: 48 times
Been thanked: 242 times
Contact:

Re: Embedded C within a component.

Postby mnf » Mon Feb 18, 2019 10:56 am

How about an storing an array of start addresses to each image data

so then

Code: Select all

image_data = images[1]

Needs a bit more care in the setup - you'll need to know the size of each images data - but then easy to access the data for each image using image[0], image[1] instead of image0, image1

Can access data using image[0][n] where n is the byte you want - note that there is some overhead for the double indexing(but less than a switch statement). It's made slightly harder by FC not having a pointer type - but a drop of C would do - and you could cache the data_ptr to a 16/32 bit variable if needed

Code: Select all

MX_UINT8 *data_ptr= FCV_IMAGES[0];
FCL_DATA = data_ptr[FCL_N];


Martin
These users thanked the author mnf for the post:
medelec35 (Mon Feb 18, 2019 11:01 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 » Mon Feb 18, 2019 11:13 am

Hi Martin,
Thanks for your reply.
The start address or total bytes for each set data is not known at the point of component creation.
After component is created then used, data is then added as and when required.
At that point only the data size is known not the start address.
The flowchart is then ran and the start address is sent via UART.
I'ts not a case of

Code: Select all

next start address = previous start address + total bytes used

Since there will have to be padding null bytes added to the end.
That is required to make sure the total number of bytes is divisible by 4:
RetSupData2.png
RetSupData2.png (65.4 KiB) Viewed 1283 times
Martin

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

mnf
Valued Contributor
Valued Contributor
Posts: 429
Joined: Wed May 31, 2017 11:57 am
Has thanked: 48 times
Been thanked: 242 times
Contact:

Re: Embedded C within a component.

Postby mnf » Mon Feb 18, 2019 11:38 am

Can you just populate the images array as created?

In 'thought' code:

Code: Select all

Image[n] = current_start
// Populate image data padding as reqd
….
Image[n+1] = new_start


Of course this means that the Image array will need to be stored in non volatile memory (as per the actual image data) and will probably need an end marker (-1?) - also will need to be large enough to store a 'maximum' number of images. An alternative is to set up a linked list - where a pointer (before) the image data points to the next image data (0 for end of list) - and finding image 'n' will involve walking the list - again in pseudocode:

Code: Select all

 
n = image_no_to_retrieve
data_ptr = start_of_image_data
while(n && data_ptr != 0) {
   data_ptr = data_ptr[0]
   n = n -1
}
if data_ptr != 0 {      // We'll assume at least one image
   image_data_ptr = data_ptr + size_of_ptr (2 or 4 bytes)
} else {
   no_such_image - use a default?
}


Did you ever get any joy with the RLE compression - not sure I ever managed to get the compressor working correctly :( - If you are transmitting to the MCU (via UART) the MCU and FC could do the hard work?

Martin
These users thanked the author mnf for the post:
medelec35 (Mon Feb 18, 2019 1:04 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 » Mon Feb 18, 2019 12:04 pm

Hi Martin,
mnf wrote:Of course this means that the Image array will need to be stored in non volatile memory (as per the actual image data) and will probably need an end marker (-1?)

As the images can be fairly large.
To give you an idea:

Code: Select all

Image1 = Q actions 40 'x' 58, total size 4640, Address:0 Tag1
Image2 = Schedule 34 'x' 34,total size 2312, Address:4644 Tag2
Image3 = Settings 35 'x' 35, total size 2450, Address:6960 Tag3
Image4 = Logo, No Text 99, 'x' 34 total size 6732, Address:9412 Tag4
Image5 = S Brightness icon 31, 'x' 32, total size 1984, Address:16148 Tag5
Image6 = Exit Icon 25 'x' 34, total size 1700, Address:18136 Tag6
Image7 = U Arrow 56 'x' 35, total size 3920 , Address:19840 Tag7
Image8 = D Arrow 56 'x' 35, total size 3920, Address:23764 Tag8
Image9 = S Fan 34 'x' 45, total size 3060, Address:27688 Tag9
Image10 = T Fan 34 'x' 45, total size 3060, Address:30752 Tag10
Image11 = Heating Override 35 'x'48, total size 3360, Address:33816 Tag11

So storing in nonvolatile area is not achievable.
mnf wrote:and will probably need an end marker (-1?)

The data is RGB so has a value of 0 to 255.
Only way to set to -1 is is using signed int.
That will double the amount of room required.
Using 18F47K40 and with 11 sets of data is currently using:

Code: Select all

Program space        used  E12Ah ( 57642) of 1E200h bytes   ( 46.7%)

The data is being used to update gLCD with images via SPI.
Implementing data read via UART will just slow things down as all the data will require adding first.
mnf wrote:Did you ever get any joy with the RLE compression

No, as it made things extremely complex and all is working with data within supplementary code window.
Martin

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

mnf
Valued Contributor
Valued Contributor
Posts: 429
Joined: Wed May 31, 2017 11:57 am
Has thanked: 48 times
Been thanked: 242 times
Contact:

Re: Embedded C within a component.

Postby mnf » Mon Feb 18, 2019 12:25 pm

The data is RGB so has a value of 0 to 255.
Only way to set to -1 is is using signed int.

- End marker for the images[] array - 0 would do as well .... Rather than the for the image data. (the image data will need a width and height if size varies? and doesn't need an end marker)
If the image data is volatile then the array of addresses can also be so.

Start address sent via UART
- I'd assumed that all the data would be also - but same principle applies for SPI, you need to store the data and some way to store the start addresses.

- How often does the data need transferring over SPI (and where from?) (Every image or power outs - I would have thought storing it all 'onboard' would be simpler :?:

Martin
These users thanked the author mnf for the post:
medelec35 (Mon Feb 18, 2019 1:04 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 » Mon Feb 18, 2019 1:02 pm

I'm using as mentioned earlier 18F47K40.
All the data is stored using supplementary code window.
All the data is sent via SPI to FT810 embedded video engine RAM only once.
The image is then displayed on the gLCD by specifying FT810 RAM_G address the imaged is stored.
The data sheet is here if you wanted to see what's involved.
mnf wrote:- End marker for the images[] array - 0 would do as wel

0 is used for image data.
This is one of the smaller images will the full data to give you an idea:

Code: Select all

char const unsigned  Image1[] ={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,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,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,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,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,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,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,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,175,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,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,109,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,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,235,217,106,177,235,217,138,185,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,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,43,153,43,234,106,177,75,242,108,254,108,254,108,254,108,254,108,254,108,254,
108,254,138,185,235,217,74,169,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,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,50,186,235,213,106,181,
75,246,108,254,108,254,108,254,108,254,108,254,108,254,108,254,108,254,108,254,74,173,43,234,208,173,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,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,42,153,11,222,235,213,108,254,108,254,108,254,108,254,108,254,108,254,108,254,108,254,108,254,108,254,235,217,235,209,74,165,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,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,138,185,138,185,108,254,108,254,108,254,108,254,108,254,11,226,74,169,235,217,108,254,108,254,108,254,108,254,106,181,138,193,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,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,202,205,138,185,108,254,108,254,108,254,108,254,75,242,10,149,49,247,107,165,108,250,
108,254,108,254,108,254,138,185,235,209,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,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,235,213,138,189,108,254,
108,254,108,254,108,254,138,185,46,198,82,255,204,181,43,234,108,254,108,254,108,254,138,185,235,217,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,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,203,209,138,189,108,254,108,254,108,254,108,254,75,161,112,210,82,255,172,173,43,234,108,254,108,254,108,254,138,189,235,213,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,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,170,193,138,185,108,254,108,254,108,254,108,250,140,165,112,206,111,210,233,136,75,246,108,254,108,254,108,250,138,189,138,189,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,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,74,165,203,209,11,226,108,254,108,254,75,238,173,173,150,255,19,235,140,169,108,254,
108,254,108,254,203,209,43,230,75,165,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,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,17,182,43,230,106,177,
108,254,108,254,43,238,173,173,150,255,150,255,205,181,108,254,108,254,76,246,106,181,235,217,116,194,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,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,42,161,11,226,106,181,108,250,43,238,173,173,19,235,210,218,205,185,108,254,76,242,106,177,75,238,109,165,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,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,74,165,43,230,106,177,170,201,173,169,150,255,150,255,238,185,170,197,138,185,75,238,107,169,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,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,11,218,235,217,173,169,150,255,150,255,14,186,43,234,
11,222,75,161,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,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,83,190,76,161,173,169,150,255,150,255,15,190,75,161,50,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,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,0,0,173,173,150,255,150,255,47,190,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,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,0,0,0,0,0,0,173,173,150,255,150,255,47,194,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,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,0,0,0,0,0,0,173,169,84,247,52,239,80,198,76,153,
14,186,80,198,108,161,18,182,141,161,141,165,208,173,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,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,140,165,150,255,149,255,145,210,47,194,150,255,150,255,117,251,43,149,150,255,150,255,117,251,206,173,206,173,174,169,18,182,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,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,108,161,149,255,149,255,242,226,206,177,149,255,149,255,149,255,47,190,149,255,149,255,149,255,112,206,84,243,149,255,19,231,110,157,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,0,0,0,0,0,0,0,0,0,0,0,0,0,75,153,149,255,149,255,117,251,75,153,149,255,149,255,149,255,79,198,117,255,149,255,149,255,19,239,
145,214,149,255,149,255,108,161,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,0,0,0,0,0,0,0,0,0,0,0,0,0,42,145,149,255,149,255,149,255,108,161,
116,251,149,255,149,255,177,218,210,226,149,255,149,255,117,255,14,190,149,255,117,255,80,198,116,198,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,0,0,0,0,0,
0,0,0,0,0,0,234,140,149,255,117,255,117,255,47,194,210,226,117,255,117,255,51,239,15,190,117,255,117,255,117,255,108,161,117,255,117,255,19,235,208,169,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,0,0,0,0,0,0,0,0,0,0,0,234,136,117,255,117,255,117,255,210,222,80,206,117,255,117,255,116,251,42,149,117,255,117,255,117,255,242,230,116,255,117,255,116,255,109,157,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,0,0,0,0,0,0,0,0,0,0,0,44,149,84,247,116,255,116,255,84,247,14,190,116,255,116,255,84,247,75,157,116,255,116,255,116,255,
116,255,116,255,116,255,116,255,108,161,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,0,0,0,0,0,0,0,0,0,0,0,109,157,19,243,116,255,116,255,116,255,
112,206,116,255,116,255,116,255,116,255,116,255,116,255,116,255,116,255,116,255,116,255,116,255,205,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,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,11,141,242,234,116,255,116,255,116,255,116,255,116,255,116,255,116,255,116,255,116,255,116,255,116,255,116,255,116,255,116,255,116,255,14,190,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,0,0,0,0,0,0,0,0,0,18,182,201,128,242,234,116,255,116,255,116,255,116,255,116,255,116,255,116,255,116,255,116,255,116,255,116,255,116,255,116,255,116,255,116,255,79,202,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,0,0,0,0,0,0,0,0,0,42,149,107,161,18,239,84,255,84,255,84,255,84,255,84,255,84,255,84,255,84,255,84,255,84,255,84,255,
84,255,84,255,84,255,84,255,144,218,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,0,0,0,0,0,0,0,142,161,209,230,108,165,83,251,83,255,83,255,83,255,
83,255,83,255,83,255,83,255,83,255,83,255,83,255,83,255,83,255,83,255,83,255,83,255,242,238,83,190,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,0,0,0,
0,0,140,165,83,255,205,181,83,255,83,255,83,255,83,255,83,255,83,255,83,255,83,255,83,255,83,255,83,255,83,255,83,255,83,255,83,255,83,255,51,251,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,0,0,0,0,0,0,0,0,0,205,181,83,255,241,234,83,255,83,255,83,255,83,255,83,255,83,255,83,255,83,255,83,255,83,255,83,255,83,255,83,255,83,255,83,255,83,255,83,255,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,0,0,0,0,0,0,0,0,0,237,185,83,255,83,255,83,255,83,255,83,255,83,255,83,255,83,255,83,255,83,255,83,255,83,255,83,255,83,255,
83,255,83,255,83,255,83,255,18,251,51,190,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,0,0,0,0,0,238,185,50,255,50,255,50,255,50,255,50,255,50,255,
50,255,50,255,50,255,50,255,50,255,50,255,50,255,50,255,50,255,50,255,50,255,50,255,209,234,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,0,0,0,0,0,
0,0,239,185,50,255,50,255,50,255,50,255,50,255,50,255,50,255,50,255,50,255,50,255,50,255,50,255,50,255,50,255,50,255,50,255,50,255,50,255,143,218,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,0,0,0,0,0,0,0,240,181,50,255,50,255,50,255,50,255,50,255,50,255,50,255,50,255,50,255,50,255,50,255,50,255,50,255,50,255,50,255,50,255,50,255,50,255,46,202,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,0,0,0,0,0,0,0,241,177,50,255,50,255,50,255,50,255,50,255,50,255,50,255,50,255,50,255,50,255,50,255,50,255,50,255,50,255,
50,255,50,255,50,255,50,255,204,181,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,0,0,0,0,0,0,0,51,186,176,230,50,255,50,255,50,255,50,255,50,255,
50,255,50,255,50,255,50,255,50,255,50,255,50,255,50,255,50,255,50,255,50,255,50,255,107,165,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,0,0,0,0,0,
0,0,0,0,237,189,49,255,49,255,49,255,49,255,49,255,49,255,49,255,49,255,49,255,49,255,49,255,49,255,49,255,49,255,49,255,49,255,49,255,10,149,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,0,0,0,0,0,0,0,0,0,234,140,240,242,17,255,17,255,17,255,17,255,17,255,17,255,17,255,17,255,17,255,17,255,17,255,17,255,17,255,17,255,17,255,17,255,233,136,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,0,0,0,0,0,0,0,0,0,0,0,75,157,241,250,17,255,49,255,17,255,17,255,17,255,17,255,17,255,17,255,17,255,49,255,17,255,
17,255,17,255,17,255,17,255,234,136,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,0,0,0,0,0,0,0,0,0,0,0,51,190,75,161,240,250,17,255,17,255,
17,255,17,255,17,255,17,255,17,255,17,255,17,255,17,255,17,255,17,255,17,255,241,250,234,136,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,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,108,165,240,250,17,255,17,255,17,255,17,255,17,255,17,255,17,255,17,255,17,255,17,255,17,255,16,255,17,255,10,145,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,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,204,185,16,255,16,255,16,255,16,255,16,255,16,255,16,255,16,255,16,255,16,255,16,255,16,255,16,255,107,169,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,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,50,186,207,242,16,255,16,255,240,254,240,254,240,254,240,254,240,254,240,254,
240,254,240,254,240,254,240,254,45,206,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,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,13,202,
240,254,240,254,240,254,240,254,240,254,240,254,240,254,240,254,240,254,240,254,240,254,240,254,207,246,84,194,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,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,172,177,240,254,240,254,240,254,240,254,240,254,240,254,240,254,240,254,240,254,240,254,240,254,240,254,240,254,15,190,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,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,206,177,240,254,240,254,240,254,240,254,240,254,240,254,240,254,240,254,240,254,239,254,239,254,240,254,239,254,237,197,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,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,207,173,239,254,239,254,239,254,239,254,239,254,239,254,239,254,239,254,
239,254,239,254,239,254,239,254,239,254,77,218,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,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,208,173,
239,254,239,254,239,254,239,254,239,254,239,254,239,254,239,254,239,254,239,254,239,254,17,255,52,255,22,235,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,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,208,173,207,254,207,254,207,254,207,254,239,254,18,255,53,255,119,255,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,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,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,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,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,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};

That is for a png image converted to ARGB1555 format.
mnf wrote:but same principle applies for SPI, you need to store the data and some way to store the start addresses.

UART comms is only used to transmit data to Teraterm on initial start up:
RetSupData3.png
RetSupData3.png (35.49 KiB) Viewed 1273 times

Then it can be used within the LoadBitmap component, e.g for image 10:
RetSupData4.png
RetSupData4.png (94.21 KiB) Viewed 1273 times

It does get complicated.
Martin

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

mnf
Valued Contributor
Valued Contributor
Posts: 429
Joined: Wed May 31, 2017 11:57 am
Has thanked: 48 times
Been thanked: 242 times
Contact:

Re: Embedded C within a component.

Postby mnf » Mon Feb 18, 2019 1:16 pm

I didn't explain it well...

The images array I proposed contains a list of pointers to the actual image data. It doesn't matter what values it contains as an end marker, as it isn't the actual image data...
Hence the double dereferencing mentioned..
[quote]MX_UINT8 *data_ptr= FCV_IMAGES[0];
FCL_DATA = data_ptr[FCL_N];/quote]
These users thanked the author mnf for the post:
medelec35 (Tue Feb 19, 2019 7:01 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 » Mon Feb 18, 2019 5:01 pm

Thanks, Martin.
I will see how practical it is to implement and let you know.
I know it's using pointers, but I'm not that good with C so not sure if I can implement it or if pointers work ok within Flowcode?
Martin

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

mnf
Valued Contributor
Valued Contributor
Posts: 429
Joined: Wed May 31, 2017 11:57 am
Has thanked: 48 times
Been thanked: 242 times
Contact:

Re: Embedded C within a component.

Postby mnf » Mon Feb 18, 2019 6:55 pm

As another idea, and avoiding pointers.
Just store an array of offsets to the start of each image.
So in pseudo code: to access image n data.

Code: Select all

Offset =images [n]
For n =0 to image size{
   Red = image_data[offset]
   Green = image_data[offset+1]
   Blue = ....
   Offset = offset +3
   }
   


Which should work in FC without using pointers?

Martin

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 » Mon Feb 18, 2019 9:06 pm

Hi Martin,
An issue I can think of is the variable names are embedded within a component macro e.g

Code: Select all

FCL_DATA = Image1[FCL_DATAPOINTER];
,
Therefore you won't have access to the macro that accesses it.
But the variables are declared within Supplementary Code window.
As the total number of variables can vary, you can only used the declared ones.
So the only way it could work if you can check to see how many variables have been declared.
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 » Mon Feb 18, 2019 10:52 pm

One important thing I need to mention.
We must use

Code: Select all

char const
within supplementary code as that does not use RAM therefore the RAM limit restriction is removed.
As far as I'm aware, we can't use flowcode variables to store the data.
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 » Wed Feb 20, 2019 9:25 am

Trying alternatives, but no sure why this:
ifdef code.png
ifdef code.png (33.04 KiB) Viewed 1216 times

Does not work if I have:
Sup code1.png
Sup code1.png (91.8 KiB) Viewed 1216 times
?
There is no compile error, but image is not displayed.
Therefore

Code: Select all

FCL_DATA = Image1[FCL_DATAPOINTER];
wihin

Code: Select all

#ifdef Image1
FCL_DATA = Image1[FCL_DATAPOINTER];
#endif
is being ignored due to

Code: Select all

#ifdef Image1

It's a shame as if the imageX does not exist with an if define then there is no compile error.
Without if define there is. :(
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 » Wed Feb 20, 2019 9:57 am

Just thought, the image variable has not been defined by

Code: Select all

#define
.
I don't believe it can be done this way?

Is there a way of preprocessor checking for the imageX variables please?
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 » Mon Feb 25, 2019 12:50 pm

If I have a variable that could contain a number from 1 to 100,
Does anyone know how I can use

Code: Select all

Ev_AddHeadder

Ev_AddHeadder1.png
Ev_AddHeadder1.png (63.68 KiB) Viewed 1184 times

To dynamically change the 1 in

Code: Select all

FCL_DATA = Image1[FCL_DATAPOINTER];

to the value of the variable please?
So if variable = 6 then The above should also change to

Code: Select all

FCL_DATA = Image6[FCL_DATAPOINTER];

This is the one thing holding me back so would be great if it can be done?
Thanks go to Ben for pointing me in that direction.
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 » Mon Feb 25, 2019 6:25 pm

Hi Martin,

AddHeader is called by Flowcode once at compile time. So you basically have to create code in AddHeader to see how many image variables to create and then create them all in one go. You could maybe use hidden properties to store values until the AddHeader macro is called.
These users thanked the author Benj for the post:
medelec35 (Mon Feb 25, 2019 6:48 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 » Mon Feb 25, 2019 6:48 pm

Hi Ben,
Is it possible for an example of what you just stated please?
Martin

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

mnf
Valued Contributor
Valued Contributor
Posts: 429
Joined: Wed May 31, 2017 11:57 am
Has thanked: 48 times
Been thanked: 242 times
Contact:

Re: Embedded C within a component.

Postby mnf » Mon Feb 25, 2019 7:07 pm

Hi Martin,

I still think an array is the way to go - otherwise as well as creating all the variables you'll need a mighty switch statement to access all the images..

I got a simple example up and running - it requires a 'setup' macro to be called, but that is quite usual for a component. I'd also retrieve data a 'line' or a 'block' at a time for speed...

data_array.fcfx
(10.67 KiB) Downloaded 13 times

Here just two 5 byte 'images' - and no checking for a null image either - just outputs the 'image' data to UART.... I also haven't addressed storage of width and height etc (first 4 bytes of image data?) - a client doesn't need any knowledge of variable names etc

Martin
These users thanked the author mnf for the post:
medelec35 (Mon Feb 25, 2019 7:44 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 » Mon Feb 25, 2019 7:44 pm

Hi Martin,
The issues with arrays is with the code

Code: Select all

FCL_DATA = Image1[FCL_DATAPOINTER];
is embedded within a component.
when you add the component call macro for the 1st image the return value will be

Code: Select all

1

Then when you add another image then

Code: Select all

FCL_DATA = Image2[FCL_DATAPOINTER];
is required.
The issue is if only ever add one image then

Code: Select all

FCL_DATA = Image2[FCL_DATAPOINTER];
will cause an error when compiling as that don't exist.
So I believe having and array won't work for that reason.
To give you a better idea.
If you just delete

Code: Select all

const unsigned char image2[] = {6,7,8,9,10};

and leave

Code: Select all

images[0] = &image1;
images[1] = &image2;

Then there will be a compile error.
As

Code: Select all

images[0] = &image1;
images[1] = &image2;
will be built into a component there will be no way of accessing that C code to edit it.

Hope I have explained ok?
Martin

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

mnf
Valued Contributor
Valued Contributor
Posts: 429
Joined: Wed May 31, 2017 11:57 am
Has thanked: 48 times
Been thanked: 242 times
Contact:

Re: Embedded C within a component.

Postby mnf » Mon Feb 25, 2019 7:58 pm

I don't quite follow - at some point you have to define the images you need... Defined in the supplementary code for the component and Setup is also defined in the component and will need editing to whatever images you are using. However, I don't think it is possible to build a completely general version at compile time either, if you use a switch statement, how many images do you allow for, for example?
You possibly could alter setup to have an #ifdef imageN #endif but it isn't very elegant? If you want to add the images at run time and download them- then they can only be stored in RAM?

Martin
These users thanked the author mnf for the post:
medelec35 (Mon Feb 25, 2019 9:17 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 » Mon Feb 25, 2019 8:17 pm

mnf wrote:at some point you have to define the images you need

Thats the issue.
At runtime it's not known what images are required.
You need to add 1 image then that one image is defined there and then.
Then another image is added then that second image gets defined.
You can't use a switch statement as if the switch statement contained say the definition of 10 images, you only may end up either using 4 or 15 images.
Both will cause an undefined error.
mnf wrote:You possibly could alter setup to have an #ifdef imageN #endif

I have tried that and that does not work (see post Wed Feb 20, 2019 8:25 am).
I'm guessing only because a register is expected and not an array?
mnf wrote: then they can only be stored in RAM?

Can't use ram for reasons stated in a previous post.
medelec35 wrote:within supplementary code as that does not use RAM therefore the RAM limit restriction is removed.

There is RAM limitation and the bit maps can exceed that.
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 » Mon Feb 25, 2019 9:07 pm

Hi Martin,

You can't use a switch statement as if the switch statement contained say the definition of 10 images, you only may end up either using 4 or 15 images.


Could you have a property called NumImages or similar. The user can then set the number of images they want to use.

You then have a switch statement and in each branch of the switch include a decision icon.

Switch(ImageIdx)

Case 0:
Decision: NumImages > 0

Case1:
Decision: NumImages > 1

...

This will be an "if" in the component source but once exported as a component the if will change to "#if" which uses the preprocessor to chop out unused code and hence get rid of the compile errors. I've used this in a few components.

Just making you a quick demo.
These users thanked the author Benj for the post:
medelec35 (Mon Feb 25, 2019 9:17 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 » Mon Feb 25, 2019 9:17 pm

Hi Ben,
Benj wrote:but once exported as a component the if will change to "#if" which uses the preprocessor to chop out unused code and hence get rid of the compile errors. I've used this in a few components.

Yes that is the way to go.
I have tried #if def but if you can make it work than that will be great!

Benj wrote:Just making you a quick demo.

That is brilliant thank, you as its the only thing now stopping me from creating the component.
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 » Mon Feb 25, 2019 9:31 pm

Here's an example. Hope it makes sense. A lot of the c gen magic doesn't happen until you export and use as a component.

CGenDemo.fcfx
(18.95 KiB) Downloaded 14 times


Any questions let me know :D

If you wanted to scale up the number of images rather then having to add icons everywhere and edit each one by hand you can edit the xml directly in a text editor, should save you a bit of time. Just look at the current project code in a text editor for reference. Maybe make a backup first just in case :wink:

ImageSize properties ideally should be auto calculated in the Ev_Property macro.
These users thanked the author Benj for the post:
medelec35 (Mon Feb 25, 2019 9:34 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 » Mon Feb 25, 2019 9:44 pm

Thanks Ben,
Image size is not required within properties as the image size is only entered when a new image is added.
Will it all work ok if image size was deleted from properties?
Or is that required for it to work?
The software I use for image conversion automatically displays the image size, so very easy to add on each image.
These users thanked the author medelec35 for the post:
Benj (Mon Feb 25, 2019 10:00 pm)
Rating: 5.88%
 
Martin

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