Skip to content

Progress Bar slows down progressively #7

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

Closed
gfbarros opened this issue Jul 17, 2020 · 7 comments
Closed

Progress Bar slows down progressively #7

gfbarros opened this issue Jul 17, 2020 · 7 comments
Labels
bug Something isn't working

Comments

@gfbarros
Copy link

gfbarros commented Jul 17, 2020

With the example slightly modified to work with the Adafruit FeatherWing OLED screen, I see the progress bar progression across the screen slow down as the percentage increases. Any pointers on how to troubleshoot this?

Here is a video: https://youtu.be/B2AHjPbJh7c

And the code:

import time
import board
import displayio
import terminalio
from adafruit_bitmap_font import bitmap_font
from adafruit_display_text import label
import adafruit_displayio_ssd1306
from adafruit_progressbar import ProgressBar

displayio.release_displays()

i2c = board.I2C()
display_bus = displayio.I2CDisplay(i2c, device_address=0x3C)
display = adafruit_displayio_ssd1306.SSD1306(display_bus, width=128, height=32)

splash = displayio.Group(max_size=10)
display.show(splash)

color_bitmap = displayio.Bitmap(128, 32, 1)
color_palette = displayio.Palette(1)
color_palette[0] = 0x0
bg_sprite = displayio.TileGrid(color_bitmap, x=0, y=0, pixel_shader=color_palette)
splash.append(bg_sprite)

progress_bar = ProgressBar(0, 0, 128, 32, 1.0)

splash.append(progress_bar)

textbox_bitmap = displayio.Bitmap(80,20,1)
textbox_palette = displayio.Palette(1)
textbox_palette[0] = 0x000000 #Black
textbox_sprite = displayio.TileGrid(textbox_bitmap, pixel_shader=textbox_palette,x=25, y=5)
splash.append(textbox_sprite)

text = "Fuel Pumping!"
text_area = label.Label(terminalio.FONT, text=text, color=0xFFFFFF, x=27, y=14)
splash.append(text_area)

current_progress = 0.0
while True:
    while current_progress <= 1.0:
        print("Progress: {}%".format(current_progress * 100))
        progress_bar.progress = current_progress
        current_progress += 0.01
        if current_progress >= 1.0:
            current_progress = 0.0
        time.sleep(0.01)
@FoamyGuy
Copy link
Contributor

FoamyGuy commented Jul 17, 2020

The youtube link is having a problem, it points to a github page instead of youtube. Copy pasting the youtube URL worked though. I think I see what you mean about it slowing down toward the end.

The fact that the decimals in your print outs change from .00 to .9999 seems odd to me I wonder if that is related to the slowed performance.

Another thing I've noticed is that printing takes a relatively long time compared to many other operations. You might try removing (or commenting) the print statement and see if it has an impact on the performance.

I can test this out later tonight on some other devices to see if I can replicate the issue and try to understand what could be causing it.

Edit: I took a quick peek at the code. At first glance I think this for loop might be responsible for the slowed performance:

for _w in range(2, self._width * value - 2):

If I am understanding that section of the code correctly I think it means that it is filling in the entire progress bar each time you update, even the section to the left of the new value that was already filled in gets filled in again. Since larger progresses require more pixels to be filled during this progress it takes longer.

@evaherrada evaherrada added the bug Something isn't working label Jul 17, 2020
@gfbarros
Copy link
Author

Quick update, tried it without the print with the same outcome.

@tannewt
Copy link
Member

tannewt commented Jul 17, 2020

I think @FoamyGuy is right on the money. The code could only modify the new pixels. If it had refresh control it could also pause refreshes.

It could also not use a bitmap and save memory.

@FoamyGuy
Copy link
Contributor

I have created PR #8 that attempts to resolve this issue. @gfbarros if you have a spare moment it would be great if you can try out the code from that PR and see if it is increasing the performance in your project.

@gfbarros
Copy link
Author

Happy to. I haven't built mpy's before so I'll look into how to do that this weekend. Thanks!

@gfbarros
Copy link
Author

I tested it and it no longer has the slowdown, thanks! I'm a bit confused by 100% now being 21, could you explain? This print output is a bit wonky as well, I added a *100 which fixed it.

@gfbarros
Copy link
Author

This is resolved my merged PR #8

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants