PiSupply / PaPiRus

Resources for PaPiRus ePaper eInk displays
https://www.pi-supply.com/product/papirus-epaper-eink-screen-hat-for-raspberry-pi/
Other
346 stars 88 forks source link

Removing multiple positioned text items and writing all new ones #129

Closed eat-sleep-code closed 7 years ago

eat-sleep-code commented 7 years ago

I have a program that alternates between three screens.

Each of these screens has multiple items that are positioned at various places on the screen.

How do I smoothly clear the screen, and then write the next one.

I tried display.Clear() and then (after a bunch of display.AddTexts) a display.WriteAll() but this causes the screen to blink twice between each screen.

I tried a bunch of display.RemoveText('ID') and then (after a bunch of display.AddTexts) a display.WriteAll() but this leaves large chunks of unwritten screen.

So, what is the cleanest and quickest way to accomplish a Write of all new positioned text?

shawaj commented 7 years ago

The only way to properly clear the screen is with it blinking twice as you say.

You could try and write the inverse colour of the original to the same space but I think that might cause some ghosting and wouldn't give a truly clear screen.

eat-sleep-code commented 7 years ago

Do you think the library could be improved, to possibly allow it to clear and replace the screen contents in one action?

I am just thinking on my Kindle, there isn't a big double flash like that when I switch pages.

shawaj commented 7 years ago

It's a hardware limitation not a software limitation so I don't think there is anything we can do.

Unless @repaper or @tvoverbeek or @francesco-vannini have any ideas?

eat-sleep-code commented 7 years ago

I notice that this code in textpos.py seems to write a new image and then clear the display?

        # Clear the image, clear the text items, do a full update to the screen
        self.image = Image.new('1', self.papirus.size, WHITE)
        self.allText = dict()
        self.papirus.clear()

Shouldn't just one of these be necessary?

shawaj commented 7 years ago

@eat-sleep-code are you seeing a specific error with part of this code?

eat-sleep-code commented 7 years ago

No error, just trying to track down why there are multiple flashes between each update. If I look at how my Kindle Paperwhite (understand that the hardware is different, but both are e-ink so should operate roughly the same) there is a single flash between updates, not multiple.

In the above code -- from my understanding -- a white image is being written to the screen (that write would cause one "flash" as that image is written) and then the core EPD clear is being called (that clear would cause a second "flash" as the screen is being cleared).

shawaj commented 7 years ago

What coffee are you running that is causing the behaviour you are seeing?

Need to be able to replicate it.

shawaj commented 7 years ago

*code

eat-sleep-code commented 7 years ago

Well it is a dark roast. ;-)

I will post the code into a repo tonight.

shawaj commented 7 years ago

Thanks very much that'll be great

eat-sleep-code commented 7 years ago

Here you go: https://github.com/eat-sleep-code/baseball-pi

Note: To see this in action, find a team that currently has a game in progress: https://www.mlb.com/

shawaj commented 7 years ago

@eat-sleep-code and which line in there is the issue?

eat-sleep-code commented 7 years ago

In baseball-pi/baseball/functions.py -- which I just cleaned up a bit...

Look at the displayBoxScore (line 135), displayPitch (line 161), or displayPlay (line 176).

You will see I perform a display.Clear() near the beginning and a display.WriteAll() at the end of each of these.

When a game for the selected team is in session, displayInGame (line 210) cycles through these methods every "5 seconds".

In between each screen being displayed the screen flashes multiple times before the content is written. I would think you should just see one flash of it being cleared, and then the content should be written.

tvoverbeek commented 7 years ago

To achieve what you want, use partial_update. Instead of display.Clear() only create an empty image and zero the dictionary.(only lines 170-171 of Clear() in textpos.py) When calling WriteAll use WriteAll(partial_update=True).

Look at the code for the clock or the game of life demo for a demo of partial update, Hope this helps

Ton van Overbeek (Currently no access to RPi/PaPiRus since holidaying down under)

On 30 June 2017 at 05:05, eat-sleep-code notifications@github.com wrote:

In baseball-pi/baseball/functions.py https://github.com/eat-sleep-code/baseball-pi/blob/master/baseball/baseball.py -- which I just cleaned up a bit...

Look at the displayBoxScore (line 135), displayPitch (line 161), or displayPlay (line 176).

You will see I perform a display.Clear() near the beginning and a display.WriteAll() at the end of each of these.

When a game for the selected team is in session, displayInGame (line 210) cycles through these methods every "5 seconds".

In between each screen being displayed the screen flashes multiple times before the content is written.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/PiSupply/PaPiRus/issues/129#issuecomment-312069437, or mute the thread https://github.com/notifications/unsubscribe-auth/ABJE7sQTYJuK65uB4W4UktSrfPq6t1K9ks5sI_WCgaJpZM4N8ESi .

eat-sleep-code commented 7 years ago

When I tried this I get the following error:

TypeError: WriteAll() got an unexpected keyword argument 'partial_update'

tvoverbeek commented 7 years ago

Try WriteAll(True) instead. Look at the definition of WriteAll in papirus/textpos.py.

On Jul 2, 2017 12:32, "eat-sleep-code" notifications@github.com wrote:

When I tried this I get the following error:

TypeError: WriteAll() got an unexpected keyword argument 'partial_update'

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/PiSupply/PaPiRus/issues/129#issuecomment-312466889, or mute the thread https://github.com/notifications/unsubscribe-auth/ABJE7jv6_dIPTWeduuURm8dj7rlq3VCMks5sJwFPgaJpZM4N8ESi .

eat-sleep-code commented 7 years ago

Actually, I discovered I had a slightly older version of the library. partial_update=True works with the most recent version. Now, if issue #130 was fixed, my app would be working pretty much perfectly.