Custom library with several classes

Hi,

How can I create a custom library repo that contains a set of libraries inside of it?
The template for custom libraries only allows me to create a single class per repo.
I need several classes inside the same repo. Possible?
I’d hate to have to create over 50 repos… :frowning:
I’m trying to port a project from Arduino to Spark.
Here is the repo I’m trying to port:

Thanks,
RI

1 Like

Hi @roberto_imai,

I think this should be possible, and would be largely structured in the same way as your current project. There’s an example library here that might help:

and just to be safe I’ll ping @jgoggins when he has a moment to weigh in, in case I’m wrong. :slight_smile:

Thanks,
David

It appears that none of my files that I place inside another folder gets imported.
Here is my repo:

This is what happens:
reefangel/SparkCoreLibraries/SparkCoreLibraries.h -> imported
reefangel/SparkCoreLibraries/SparkCoreLibraries.cpp -> imported
reefangel/SparkCoreLibraries/ReefAngel/ReefAngel.h -> not imported
reefangel/SparkCoreLibraries/ReefAngel/ReefAngel.cpp -> not imported

If I place all files into reefangel/SparkCoreLibraries folder, they get imported, but it may become a mess of files with over 100 files into a single folder. It would be nice to be able to separate them into their own subfolder if possible.

Good question @roberto_imai and thanks for the ping @Dave .

I verified that the the importer does not allow sub-directories for source or header files. I believe the reason for doing this was to ensure the include path to a library was simple and to not allow libraries that are so large that they require sub-directories. The idea was to encourage libraries to be relatively small and tightly focussed and therefore wouldn’t need this capability. After seeing your use case though, I now understand that this design might not be ideal. For libraries seeking to provide broad and complete encapsulation of other complimentary hardware like this, the idea is not appropriate. I’ve added a “You should be able to sub-directories for source and header files within a library” spec to our backlog–I’ll ping this thread when we ship it. I’m not sure when the ETA is on this.

If you want to get this library up and in a working state ASAP, I’d recommend the following:

  • Change the name of the library in the spark.json to “reef-angle-controller” instead of “SparkCoreLibraries” and change the main source and main header file to reef-angle-controller.h and reef-angle-controller.cpp. This provides something more descriptive for potential users of your library. (I’d also add a bit more to the readme to exhibit use cases, etc before publishing)

  • When porting, for each sub-directory in the Arduino repo, use it as a file name prefix, so ReefAngel/ReefAngel.h becomes firmware/ReefAngel_ReefAngle.h. This way file grouping will still be preserved when rendered via ls or in GitHub. Also, the convention will make clear where things are being ported from. You could probably write a little script to do the rename for you too if it will save you time.

So, @roberto_imai , thank you for bringing this up, the use case you’ve illustrated justifies a tweak to the library system to accommodate this kind of thing. In the meantime, I hope the approach I’ve described will work for you.

1 Like

Thanks, I’ll start working with the recommended suggestion to test a few things while the solution is being worked on.