-
-
Notifications
You must be signed in to change notification settings - Fork 39.8k
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
Add uint to char functions #15244
Add uint to char functions #15244
Conversation
quantum/quantum.c
Outdated
buf[3] = (curr_num /= 10) % 10 ? '0' + (curr_num) % 10 : (curr_num / 10) % 10 ? '0' : curr_pad; | ||
buf[2] = (curr_num /= 10) % 10 ? '0' + (curr_num) % 10 : (curr_num / 10) % 10 ? '0' : curr_pad; | ||
buf[1] = (curr_num /= 10) % 10 ? '0' + (curr_num) % 10 : (curr_num / 10) % 10 ? '0' : curr_pad; |
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.
buf[3] = (curr_num /= 10) % 10 ? '0' + (curr_num) % 10 : (curr_num / 10) % 10 ? '0' : curr_pad; | |
buf[2] = (curr_num /= 10) % 10 ? '0' + (curr_num) % 10 : (curr_num / 10) % 10 ? '0' : curr_pad; | |
buf[1] = (curr_num /= 10) % 10 ? '0' + (curr_num) % 10 : (curr_num / 10) % 10 ? '0' : curr_pad; | |
buf[3] = (curr_num /= 10) ? '0' + curr_num % 10 : curr_pad; | |
buf[2] = (curr_num /= 10) ? '0' + curr_num % 10 : curr_pad; | |
buf[1] = (curr_num /= 10) ? '0' + curr_num % 10 : curr_pad; |
The original code would not work properly for a number like 1001 (with at least two consecutive zeros); the whole remaining number needs to be tested when deciding whether the zero needs to be replaced with the padding character.
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.
yeah, went through a number of iterations, the current code should work properly, but please take a look at it.
d696fd8
to
901560e
Compare
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.
The static buffer note needed to be placed on the other APIs. My bad.
We should also put the function declarations into quantum.h
.
Co-authored-by: Nick Brassel <[email protected]>
* qmk/develop: (80 commits) Remove use of __flash due to LTO issues (qmk#15268) Revert "handwired/split89 Layout Macro Refactor (qmk#15210)" (qmk#15284) New Keyboard: TGR Jane CE (qmk#14713) Portal 66 Layout Macro Refactor (qmk#15255) Pluckey: Fix QMK Configurator Implementation (qmk#15254) [Tests] Increase QMK test coverage take 2 (qmk#15269) Ignore exit codes for formatters (qmk#15276) [Keyboard] Disable features on SplitKB boards to fit under size (qmk#15262) Ignore exit codes for formatters (qmk#15275) Ignore deleted files when formatting codebase (qmk#15274) qmk format-python - filter for Python files (qmk#15271) Revert "[Tests] Increase QMK test coverage (qmk#13789)" [Tests] Increase QMK test coverage (qmk#13789) [Docs] Squeezing space out of AVR (qmk#15243) Add uint to char functions (qmk#15244) [Keyboard] Disable console on Keebio foldkb and iris rev3 (qmk#15260) layer_combo → sd_combo (qmk#15266) [Keymap] Disable console on Sofle default keymap (qmk#15261) [Keyboard] Enable LTO on viktus/sp_mini via keymap (qmk#15263) Macros in JSON keymaps (qmk#14374) ...
* Add uint to char functions * appease the all mighty lint * Further appease Lint * Update functions * Add doxygen comment * Update quantum/quantum.c Co-authored-by: Nick Brassel <[email protected]> * Apply suggestions from code review Co-authored-by: Nick Brassel <[email protected]> * Add declaration for get_numeric_string * fix formatting and bug Co-authored-by: Nick Brassel <[email protected]> (Cherry-pick from: 32a87d3)
Description
Adds functions to convert an unsigned int to a char array. Useful for OLEDs and displays, especially on AVR, as things like sprintf take up ~1.5kB of firmware space.
And instead of continually adding the same block of code, add a function into core to do this.
Types of Changes
Checklist