-
Notifications
You must be signed in to change notification settings - Fork 113
Description
Please hear me out. I'd like to suggest reworking the hexbright library into separate concerns per file. Same class as before, but defined by function, such as:
- hexbright.h
- hexbright.cpp
- power.cpp
- accel.cpp
- leds.cpp
- lighting.cpp
- buttons.cpp
As far as I can see the only technical issue preventing this is the crazy BUILD_HACK stuff and the idea that .ino files should control how the library compiles (strobe, etc).
Here is what I have in mind to tweak: The library should be compiled as a library, and library configuration should be in hexbright/settings.h. This would hold settings such as which main library features to turn on or off, which light level code to use, etc... it would allow you to easily review and comment all the configuration options without mixing them up with the actual code. hexbright.h would require settings.h, so the settings are available everywhere. hexbright.h would contain the class declaration, the .cpp files would contain all the definitions.
It might mean a few libraries would ALSO require tweaking settings, but I don't think this is the end of the world. I could be documented... or in some of cases it could be avoiding by dealing with a few additional things at run-time. Strobes is currently the biggest example of this behavior I see right now (an optional feature changing the core library).
Dealing with strobes
All update_spin does really is burn CPU cycles for 8333 microseconds (well subtracting out your programs loop cost). Instead of replacing the function wholesale at compile time I suggest we have a function pointer to an idler configurable function. The default would be none and update_spin would look pretty much as it does now. Libraries that required super fine grained control of the hardware could provide their own idler function and it would be called inside the update_spin do/while loop. Of course this would be documented and explain the caveats of using this (timing is critical) - pretty much the same as writing your own update_spin now.
So update_spin would just be responsible for deciding when to start the next "cycle" (as the default does now) and the idler function provided by strobe.cpp would be responsible for cycling the strobe during the idle time of update_spin.
This would add a few bytes for the function pointer and calls, etc... but it shouldn't be significant since we're not really duplicating much (if any) code... idler isn't a full rewrite of update_spin, just the strobe timing/functionality.
Thoughts?