I am somewhat a scatterbrain, and as such I begin a lot of different projects and I find I have to do the same tasks at the beginning of each new project.
For example, I have some libraries I must include using the build_flags in PlatformIO.ini, and I like to delete the big comment field in the PlatformIO.ini file. Also, I want a [platformio] section in all my new projects.
Also, the new project creates a main.cpp and the template is not for me. I’d like to have my own main.cpp file with my own starting format.
Does PlatformIO have come template files it uses to build these files during creation of a new project?, And if so, where are they?
So, you could create your own platformio.ini snippet, and your own main.cpp snippet (Ctrl+Shift+P → Configure Snippets). Then just delete the autogenerated file and then Ctrl+Shift+P → Insert snippet to fill it in.
The main.cpp snippet is hardcoded in the PlatformIO core, unless a specific platform (like platform-ststm32 etc.) overides it. As thus, it’s not really user-configurable.
I noted in the main.cpp program (that one PlatformIO created) a line I thought would be unique “put function declarations here” so I searched my hard drives looking within each file till I found it.
Among the 42 files found I saw one called “init.py” in the folder “/home/mark/.platformio/penv/lib/python3.12/site-packages/platformio/project/commands”
Looking in there, I found a bit of code that matched the contents of main.cpp, so I replaced that with my own version, and it seems to have worked.
Now, when I create a new project, I get my code, not what the designers of PlatformIO wanted.
Now to Continue to look for the part in PlatformIO.ini,
There will be no constant string for that, it’s constructed by the Python code dynamically based on the board (and thus platform) you’ve selected. Snippets are surely a better way to go there. Also, any local modifications to the PlatformIO core will be lost if a core update occurs.