Welcome, Guest. Please Login or Register
Arduino IDE for Visual Studio
 
 
When Logging a Support Issue in the Forum, please ensure you have also:-
  • Enabled vMicro > Compiler > Show Build Properties and Verbose
  • Re-Compile your program with these settings enabled
 
Save the new Output to a Text File and....
Support requests without the output above may be impossible to answer, so please help us to help you
 
  HomeSearch Tutorials & Wiki visualmicro.com LoginHelpRegister  
 
Page Index Toggle Pages: 1
Send Topic Print
Share class files between Arduino project and Win32 project (Read 189 times)
Pascal Roobrouck
Junior Member
**
Offline



Posts: 16
Share class files between Arduino project and Win32 project
May 8th, 2020 at 2:34pm
 
I am developing a 'larger' application, and in order to UnitTest the different components, I created additional unit-testing projects (within the Visual Studio Solution), added a reference to my home project, and included the .h and .cpp files from the main project (Add | existing...).
This all works very well, as long as all projects (main project and uni-ttesting projects) are all Arduino-type projects.

Now I want to set a step further, and add some Win32 console projects, so I can do some testing of my components in the Windows environment, for those things that do not touch the MCU hardware. I can only make this work when copying all the .h and .cpp files from the main Arduino project, to the Win32 project folder. I cannot make it work through a reference..

Has anyone done this with success ?
Thanks.

Back to top
 
 
IP Logged
 
Simon Hopkinson
Administrator
*****
Offline



Posts: 246
Re: Share class files between Arduino project and Win32 project
Reply #1 - May 8th, 2020 at 2:58pm
 
In the below Instructable and Video we use standard desktop Unit Testing tools, and Shared projects to test the generic MCU code on your Desktop PC, without having to clone the CPP and H files for the different purposes.

Instructable
YouTube Video

Does this help?
Back to top
 
 
IP Logged
 
Pascal Roobrouck
Junior Member
**
Offline



Posts: 16
Re: Share class files between Arduino project and Win32 project
Reply #2 - May 8th, 2020 at 3:04pm
 
This is certainly useful. Let me digest the tutorials and I will give you feedback on how it went.
Thanks VisualMicro team, great product and fast support!
Back to top
 
 
IP Logged
 
Pascal Roobrouck
Junior Member
**
Offline



Posts: 16
Re: Share class files between Arduino project and Win32 project
Reply #3 - May 8th, 2020 at 3:32pm
 
Your tutorial is for sure an answer to my needs.
I've learned I need to have the 'shared' code in a special 'Arduino Shared Code' type of project. That was new to me.

Further I am still stuck on the following : I use mostly the uint32_t kind of data types, as they have a clearly defined width. They are defined in Arduino.h (for Arduino projects) and in <stdint.h> (for Windows projects).
I tried to solve this with some preprocessor trick, but it is not working.. It looks as if the shared code, when compiled for Win32 does not get the WIN32 token, so stdint.h does not get included..

#ifndef  WIN32
#include <Arduino.h>
#else
#include <stdint.h>
#endif
Back to top
 
 
IP Logged
 
Simon Hopkinson
Administrator
*****
Offline



Posts: 246
Re: Share class files between Arduino project and Win32 project
Reply #4 - May 8th, 2020 at 4:15pm
 
I have tried this in the "SharedCodeProject" from the instructable, and it worked fine for me, though it can depend on a variety of settings.

_WIN32 is defined by VS, so it may be safer to check for that instead / aswell.

Code:
#if defined(_WIN32) && !defined(WIN32)
	#define WIN32
#endif

#ifndef WIN32
#include <Arduino.h>
#else
#include <stdint.h>
#endif 




If it still doesn't work, check the top of the output when building the console project (SharedProjectUnitTests project in example) to ensure its Configuration is set to Win32
(if not check the Properties to ensure  the platform set to "Win32" for the "SharedCode" project when building the console project)

Back to top
 
 
IP Logged
 
Pascal Roobrouck
Junior Member
**
Offline



Posts: 16
Re: Share class files between Arduino project and Win32 project
Reply #5 - May 8th, 2020 at 4:21pm
 
ok, thanks.
Just out of curiosity : why do you put the shared code in a '\src\ subfolder ?
Back to top
 
 
IP Logged
 
Simon Hopkinson
Administrator
*****
Offline



Posts: 246
Re: Share class files between Arduino project and Win32 project
Reply #6 - May 8th, 2020 at 4:42pm
 
This is just to begin to build the improved structures also allowed by the Arduino system, which help avoid conflicts as project complexity grows.

The projects are combined as part of the Arduino build process, so not having a structured merged result can easily create issues when all projects come together.

By putting them in \src\, and sub-folders below this to avoid conflicts when building for all platforms (see https://www.visualmicro.com/page/Understanding-Project-File-Structure.aspx). There is also an "\src\arduino folders read me.txt" with details on this when you create a new Arduino Project with Visual Micro.

You do not have to put shared code in an src folder but remember that arduino only supports cpp/c code in project root, \src or any level of sub folder of the src folder. Shared code has to be copied and merged with the project code during build. This happens in a temp folder but needs to be kept in mind.

Back to top
« Last Edit: May 8th, 2020 at 9:44pm by Visual Micro »  
 
IP Logged
 
Pascal Roobrouck
Junior Member
**
Offline



Posts: 16
Re: Share class files between Arduino project and Win32 project
Reply #7 - May 25th, 2020 at 10:12am
 
Hello,

I just wanted to reach out and say thank you because the proposed solution is really working very well.
I have now separated my source code into generic and platformSpecific modules.
All generic code can be easily unitTested using Visual Studio's built in Unit Testing.
You can even debug such a unit test with all of Visual Studio's debugging features.

This has significantly improved my development setup and code quality, and from now on I am using this setup as a template for all my developments. So : thank you!

Pascal
Back to top
 
 
IP Logged
 
Page Index Toggle Pages: 1
Send Topic Print