adafruit / Adafruit_CircuitPython_EPD

e paper driver for circuit python
MIT License
40 stars 19 forks source link

Reduce the CPU load when waiting for the display #35

Closed mariovisic closed 4 years ago

mariovisic commented 4 years ago

In many places a pass instruction is used in loops to wait until we hear back back from the display. This causes the loop to execute continuously which uses all of the available CPU, if we instead sleep for 1ms, we don't lose much time (less than 1ms each wait) and we dramatically reduce the load on the CPU.

Before the change (updating a 3-color 2.13" display):

time python3 ./update_display

real    0m19.664s
user    0m17.622s
sys     0m1.046s

After the change:

time python3 ./update_display

real    0m19.730s
user    0m3.563s
sys     0m0.792s1

The total time to run the script is about the same, but the CPU time has reduced dramatically.

ladyada commented 4 years ago

@makermelissa maybe check it still works on a feather m4 + wing in the next week or two? :)

makermelissa commented 4 years ago

I tried this out with a Feather M4 and both the mono and tri-color and neither worked. So then I tried the original code before this change and it didn't work for either display again, so I'll have to look into it further.

makermelissa commented 4 years ago

Ok! I got it working. It tested fine on both the mono and tri-color displays.

mariovisic commented 4 years ago

🙌 thank you so much :)

makermelissa commented 4 years ago

Thank you!