PSoC 5LP, project with outsourced functions

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Anonymous
Not applicable

Hello,

   

 

   

I am writing a program for PSoC 5LP (Prototyping Kit) working with the RGB-sensor VEML6040 by Vishay.

   

I try to outsource most of the functions and only have the core-code remaining in the file main.c. So i created two files: veml6040.h and veml6040.c and added them to the project (in header and source files).

   

 

   

Extract from veml6040.h

   

 

   

#include "veml6040.c"
#include "main.c"
#include <project.h>

   

// definitions

   

// function headers

   

 

   

extract from veml6040.c

   

#include "veml6040.h"

   

uint16_t ReadSensor(uint8_t CommandCode)
{
    // awesome code
}

   

// other functions ...

   

 

   

When i do so and i change the files following message appears (translated from german by me):

   

The file cannot be saved: (The process cannot access file "C:\Users\username\Documents\PSoC Creator\PSoC5LP-VEML6040\PSoC5LP-VEML6040.cydsn\main.c", because another process is accessing it.)

   

 

   

None of the files can be saved (not even main.c). Also the Build ends with the PSoC Creator crashing.

   

When i remove the files from the project, everything works fine again.

   

 

   

Can someone help me with this problem?

   

 

   

 

   

Best regards,

   

Jeroen

0 Likes
1 Solution
lock attach
Attachments are accessible only for community members.
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

That's right. There usually is a #ifdef to allow a .h file to be #included into several files of a project, see attached example.

   

 

   

Bob

   

PS: Where in Germany are you located? I live near Bremen.

View solution in original post

0 Likes
5 Replies
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Welcome in the forum.

   

Do not include .c files!!! just include the corresponding .h files.

   

 

   

Bob

0 Likes
Anonymous
Not applicable

Thank you.

   

I don't have to include the .c file in the corresponding header?

   

Only the .h file in the .c file?

0 Likes
lock attach
Attachments are accessible only for community members.
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

That's right. There usually is a #ifdef to allow a .h file to be #included into several files of a project, see attached example.

   

 

   

Bob

   

PS: Where in Germany are you located? I live near Bremen.

0 Likes
Anonymous
Not applicable

Thanks for your help. I will try this soon.

   

I am from the Ruhr area.

   

 

   

Best Regards

   

Jeroen

0 Likes
JeSc_1479476
Level 1
Level 1

I just stumbled across this old forum entry.

To update my own question: I solved the problem and published the complete code open source. I'm leaving a link here if anyone searches for the VEML6040 for the PSOC 5LP and sees this post: https://github.com/J-Schaefer/veml6040

Best regard

Jeroen

0 Likes