Welcome, Guest. Please Login or Register
Arduino IDE for Visual Studio
 
  HomeSearch Tutorials & Wiki visualmicro.com LoginHelpRegister  
 
Page Index Toggle Pages: 1
Send Topic Print
Automatic build version in built code (Read 288 times)
Acuario
Senior Member
****
Offline



Posts: 86
Automatic build version in built code
Dec 22nd, 2018 at 9:36am
 
Hi,

it would be a nice feature to be able to automatically include a build number in built bin files that can then be used in the Sketch.

For example:
A file 'BuildVersion.h' included in the project that contains:
#define VERSION 3.1

Each time the project is built this number gets automatically (if desired by a setting)  incremented

The version can then be used as desired in the sketch.

I guess this could be implemented using a pre or post build script.

Acuario
Back to top
 
 
IP Logged
 
Acuario
Senior Member
****
Offline



Posts: 86
RE: Automatic build version in built code (SOLUTION)
Reply #1 - Dec 23rd, 2018 at 7:42am
 
For anyone who wants this feature, here is a way to achieve at least a basic way of doing it.

1. Create a file in your project called version.h
2. Put the following in version.h
Code:
#define VERSION 1 


3. Create a version.bat file in your project and mark it as Exclude from project
4. Add the following to version.bat:
Code:
@echo off
setlocal EnableDelayedExpansion
set file=%1

for /F "tokens=1-3 delims=N " %%a in (%file%) do (
   for %%A in (%%a %%b %%c) do set "i=%%A"
)
set /a i=i+1
echo #define VERSION %i% > %file% 



5. Add the following to your Board.txt
Code:
# Increment version before build
recipe.hooks.sketch.prebuild.1.pattern=cmd.exe /c "{build.project_path}\version.bat {build.project_path}\version.h"
 



6. Add #Include "version.h" in your sketch

The version number will increment by 1 every time you do a build, irrespective if it succeeds or fails.

To use the version just use the defined VERSION in your code for example:
Code:
Serial.printf("Startup Version:%d\n", VERSION);
 



Acuario
Back to top
« Last Edit: Dec 24th, 2018 at 3:30pm by Visual Micro »  
 
IP Logged
 
Visual Micro
Administrator
*****
Offline



Posts: 9560
United Kingdom
Re: Automatic build version in built code
Reply #2 - Dec 24th, 2018 at 3:32pm
 
Excellent thank you!
Back to top
 
WWW  
IP Logged
 
Page Index Toggle Pages: 1
Send Topic Print