-
Notifications
You must be signed in to change notification settings - Fork 64
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Giving the library the final polish #35
Comments
This is how to implement the lookup table with constexpr: https://stackoverflow.com/a/34465458/1996022 |
I remember thinking about doing inheritance before the big update and decided against it, probably because I completely forgot about virtual functions. I think, however, I can implement inheritance for at least the UART portion of the lib - I'll have to do more looking into SPI/I2C to see if it'll work there too (I assume it'll work, but I want to make sure). As for the |
Absolutely, feel free to fork and PR - I'm interested to see how good this lib can get! |
I think you might have noticed by now that I really like your library.
And at this point I'd like to give something back to you.
Now I have some decent experience designing libraries and software in general and I have a few suggestions (that I'm all willing to implement myself):
This is a fun one! Now I like that you separated the package code into its own class. That's good design. However there is one (fairly) big flaw with how you're doing it right now: The classes don't have anything to do with eachother.
So my suggestion is to make use of inheritance. You have the abstract
Packet
class (maybe it should be renamed?) that has the pure virtual functionsreadAvailable
(how many bytes are available to read or maybe a plain boolean function is enough),readByte
(reads the next available byte),writeBytes
(writes the bytes) andprintDebug
(which prints the debug message (may be just virtual with a default implementation that does nothing)).This allows the library to be extended easily to any other hardware platform and the base class can be made without any external dependencies so it can be used for the Linux/Windows variant of the library.
That means making sure that the library doesn't need any RAM and that everything is written in the ROM (
constexpr
magic at play here ;) ). Now with a preprocessor flag I could toggle between a ROM lookup, RAM lookup or live calculation.And lastly let's abandon using class instances for this. My suggestion would be to use only static members in a class. If you really want the size and polynomial to be configurable that can be achieved with templates.
Now if you aprove of these suggestions I'll get on to implementing them.
The text was updated successfully, but these errors were encountered: