Skip to content
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

sys/progress_bar: add module for managing a progress bar in stdout #12550

Merged
merged 2 commits into from
Dec 5, 2019

Conversation

aabadie
Copy link
Contributor

@aabadie aabadie commented Oct 23, 2019

Contribution description

This PR add a module for managing a progress on the stdout of RIOT.
The feature makes use of ASCII escape codes to fully redraw the progress bar when the update function is called.

Note that the progress bar doesn't work well with pyterm as a redraw of the progress bar doesn't contain the \n character. It's possible to hack around this but the result is not nice.

The goal of the progress bar is to display the download status of a firmware during an update (PR will come soon)

Testing procedure

make BOARD=<board of your choice> -C tests/progress_bar flash test

Issues/PRs references

None

@aabadie aabadie added Type: new feature The issue requests / The PR implemements a new feature for RIOT Area: sys Area: System labels Oct 23, 2019
@aabadie aabadie requested a review from fjmolinas October 23, 2019 10:35
Copy link
Contributor

@kaspar030 kaspar030 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice one.

I'm not happy with the forced 68b per progress bar. See my suggestion on removing that for the simple use case.

sys/progress_bar/progress_bar.c Outdated Show resolved Hide resolved
sys/progress_bar/progress_bar.c Outdated Show resolved Hide resolved
sys/include/progress_bar.h Show resolved Hide resolved

/* Fully reprint the progress bar */
for (unsigned j = 0; j < PROGRESS_BAR_LENGTH; j++) {
if (100 * j < (uint16_t)(progress_bar->value * PROGRESS_BAR_LENGTH)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you change this to use 0-255 instead of 0-100, the two multiplications turn into shifts. Also, the assert on top of this function becomes obsolete. Similar at the call site.

Not sure that justifies not using percentages.

sys/progress_bar/progress_bar.c Show resolved Hide resolved
printf(PROGRESS_BAR_SUFFIX_CHARACTER);

/* Display progress bar suffix if any */
if (progress_bar->suffix[0]) {
Copy link
Contributor

@kaspar030 kaspar030 Oct 23, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this check is redundant, printf will printf will not print if the string is empty.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed it here but kept the check on the prefix as otherwise some garbage is printed if nothing is set in the buffer.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How is that possible? Is the structure allocated on the stack and not emptied?
Shouldn't printf("%s", { \0, ... }) print nothing?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Declaring the progress bar static works but not on the stack indeed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That might be because defined statically, it'll be zeroed. On the stack it has random contents unless cleared.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That might be because defined statically, it'll be zeroed. On the stack it has random contents unless cleared.

Makes sense. Maybe there should be a note about this in the documentation. Another possibility is to introduce a progress_bar_init function to ensure buffers are correctly cleared before using a progress bar allocated on the stack.

sys/progress_bar/progress_bar.c Outdated Show resolved Hide resolved
@aabadie
Copy link
Contributor Author

aabadie commented Oct 23, 2019

Thanks for your review @kaspar030!
I'll address your comments ASAP.

@aabadie aabadie force-pushed the pr/sys/progress_bar branch from 1f1b2bc to 9365826 Compare October 23, 2019 19:51
@aabadie aabadie changed the title sys/progress_bar: add module for managing a progress in stdout sys/progress_bar: add module for managing a progress bar in stdout Oct 24, 2019
@aabadie
Copy link
Contributor Author

aabadie commented Oct 24, 2019

I pushed a couple of commits that makes the progress bar usable even with pyterm. It's a bit hacky (use ascii escape codes to save and restore the cursor position) but it works. Is it worth though ?

@aabadie aabadie force-pushed the pr/sys/progress_bar branch from 24695a3 to ac9e65d Compare October 25, 2019 16:00
@aabadie aabadie force-pushed the pr/sys/progress_bar branch from ac9e65d to 66cd544 Compare November 15, 2019 09:17
@aabadie aabadie added CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR CI: run tests If set, CI server will run tests on hardware for the labeled PR labels Nov 15, 2019
@aabadie aabadie force-pushed the pr/sys/progress_bar branch from 66cd544 to 3f1ac65 Compare December 2, 2019 15:48
@fjmolinas
Copy link
Contributor

@kaspar030 seems like your comments have been addressed, except for some style comments, are you ok with the changes?

Copy link
Contributor

@kaspar030 kaspar030 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK. Tested on native and arduino-mega2560.

Personally I don't agree with in-memory buffers within progress_bar_t, and the need to handle multiple progress bars within the library. But with the change to an independent progress_bar_print(), that's now optional, so it won't hurt.

@kaspar030 kaspar030 merged commit 8ae7201 into RIOT-OS:master Dec 5, 2019
@aabadie aabadie deleted the pr/sys/progress_bar branch December 5, 2019 16:51
@fjmolinas fjmolinas added this to the Release 2020.01 milestone Dec 13, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: sys Area: System CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR CI: run tests If set, CI server will run tests on hardware for the labeled PR Type: new feature The issue requests / The PR implemements a new feature for RIOT
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants