-
Notifications
You must be signed in to change notification settings - Fork 0
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
Refactor SerialController to be easier to use #25
base: master
Are you sure you want to change the base?
Conversation
…rialController class definition
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I might be wrong, but I recall reading in lots of forums that it is highly recommended to not rely on the String class in Arduino too much, as it uses a lot of RAM, and can lead to heap fragmentation and eventual crashes. May be worth looking more into this a bit more to see what the issues really are.
The rest of this could certainly still work with char arrays rather than Strings. I'll look into whether or not the String class could be a problem in the long run. |
@sanine-a I've had a chance today to review this and I think it looks great! It feels more intuitive to break up the callbacks into the For instance, I had a callback that doesn't return anything, but executes the
I was getting errors until I switched the lambda from Regarding @twsdbailey's comment about memory usage, I'm not totally familiar with how every board is setup, but the |
I've updated this to use |
The version of SerialController we've been using has a somewhat complex and fiddly setup required to use it. You have to write a single callback function that handles every correctly formatted serial message and manually distinguish the strings using arcane string.h functions like
strcmp
oratof
, rather than more readable and natural things like the==
operator orstring.toFloat()
.I've rewritten the SerialController class to instead
String
type instead of char arrays, so that operations like concatenation,==
, and data type conversion are significantly easier.String
, anint
, or afloat
as its single argument. SerialController automatically detects the type of the argument required and handles the necessary type conversions behind the scenes.I think that this setup is much easier to work with than the current version, so I hope that we can use it moving forward! You can take a peek at it in action in the example sketch.