-
-
Notifications
You must be signed in to change notification settings - Fork 7k
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
Added support for HEX leading zero in print #6750
base: master
Are you sure you want to change the base?
Conversation
if PRINT_LEADINGZERO is in the arg, add a leading zero to a HEX if the value is smaler than 0x10
@clivepengelly, @fake-name, @technikadonis, @cmaglie is this a solution for the problem? |
I still stand that the current implementation is broken, and the correct option is to have print Really, this seems overcomplicated. Why not just have an alternative to the |
@fake-name , BUT HEX, DEC, etc. are a bunch of predefined values indicating the base of the value (e.g. HEX = 16) adding a strange value for the base, like ACTUAL_HEX, will be a bit odd because it will be something like: 42 which is not a base value. I added a OPTIONAL input value which defaults to PRINT_NOARG when not assigned. With this solution, old scripts can still be used :) |
So change that to an enum? Also, gah, what terrible API design. |
That's what my initial plan was BUT there may be some users that did actual write the base number and so.. It won't be backward compatible. I know, it doesnt feel right for the HEX not printing the leading zero but this was once implemented and changing it would make a small group of arduino users unhappy ;) |
That's not documented, and the documentation makes no statements about what In fact the documentation explicitly states:
So passing anything but |
https://www.arduino.cc/en/Serial/Print It's kind of documented... |
Ah, it's kind of crappily documented on https://www.arduino.cc/en/Serial/Println, the contents of which actually contradict https://www.arduino.cc/en/Serial/Print (which I'm quoting literally above). Siiiiiiiigh, Arduino code in a nutshell. |
True 👍 |
Anyways, It's horrible, yeah, but not any more so then the implementation it's papering over top of. |
@facchinm any news on this? |
Some ideas/opinions/thoughts:
|
|
||
do { | ||
//the argument is only valid for HEX values smaler than 0x10 | ||
if(base != 8 || n>=16) arg = 0; |
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.
if(base != HEX || n>=16) arg = 0;
@retfie , if I remember correctly, HEX is defines as 16 (By default in the original arduino code) |
for issue #1097
Added the leading zero for the print funcionality
if the argument PRINT_LEADINGZERO is added after the base definition, a leading zero is added to the hex