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

Menu, point and shoot help #133

Open
chuckv2014 opened this issue Oct 30, 2020 · 16 comments
Open

Menu, point and shoot help #133

chuckv2014 opened this issue Oct 30, 2020 · 16 comments

Comments

@chuckv2014
Copy link

I have a 128x128 SPI to a RPi Zero W under Raspbian with 5 button navigation (Left, Right, Up, Down, Enter functions). My screens look great (love LUMA.OLED) I want to create a Menu system that utilizes the NAV buttons to create a "point and shoot" menu...

Ideally, I'd like to only update a small region (the inverse video selected by the NAV buttons) but only know how to update the entire display.... is there a way to update only a portion of the display?

Currently, my Menu works too slow a clunky, when updating the entire display when the NAV button scrolls to the selection (in which I reverse the video).

Any help is appreciated.

Thank you,
Chuck

@rm-hull
Copy link
Owner

rm-hull commented Oct 30, 2020

Hi chuck, you dont say which device you have, but most implementations have a framebuffer which selectively picks only the changes since the last render, so as long as you just keep drawing the full image each time, the device will manage only sending the diffs to device.

As it happens, there is a new version of that diff algorithm coming out soon which should improve performance significantly. For some of the luma.examples demo's we have seen the frames/sec increase from about 10FPS before to about 85FPS afterwards.

@chuckv2014
Copy link
Author

chuckv2014 commented Oct 30, 2020 via email

@chuckv2014
Copy link
Author

chuckv2014 commented Oct 30, 2020 via email

@chuckv2014
Copy link
Author

chuckv2014 commented Nov 5, 2020 via email

@rm-hull
Copy link
Owner

rm-hull commented Nov 5, 2020

Since SH1106 is a monochrome device, then the image you supply when you call display() directly must be the same dimensions and colour depth, so you should either create an image with mode "1" (rather than "RGB"), or you can call im.convert(mode="1") (see https://pillow.readthedocs.io/en/stable/reference/Image.html#PIL.Image.Image.convert)

@rm-hull
Copy link
Owner

rm-hull commented Nov 5, 2020

In regard to your earlier question about not to have to refresh the entire display:

The luma.device.* classes are really just a wrapper around being able to send Pillow images to the display along with a bunch of helper classes to make it simple to draw text and primitives onto a canvas (which is really just a Pillow ImageDraw object).

You will find it easier to manage state in your application if it just does full renders every time. You shouldn't worry too much about performance - for such small screens there are not really too many pixels to update, and it is possible to get high frame rates rendering complex screens. For some of the higher resolution screens there are some mechanisms we use to only do partial/intelligent screen updates which hugely improve frame render time. This implies the time taken to send bytes to the device takes more time than it does for you to draw them onto an image canvas.

If you are wanting to have a menu system where you toggle things on and off and want to revert back to a previous display without having to redraw, possibly have a look at using the history class and an example of its usage: https://github.com/rm-hull/luma.examples/blob/master/examples/savepoint.py

@chuckv2014
Copy link
Author

chuckv2014 commented Nov 5, 2020 via email

@chuckv2014
Copy link
Author

chuckv2014 commented Nov 6, 2020 via email

@thijstriemstra
Copy link
Collaborator

this is more of a stackoverflow question, search for systemd + python

@rm-hull
Copy link
Owner

rm-hull commented Nov 15, 2020

@chuckv2014 when you said:

however, when I added this to the profile... I get an error: No Module named ‘luma’

Can you explain exactly what you did?

@chuckv2014
Copy link
Author

chuckv2014 commented Nov 16, 2020 via email

@rm-hull
Copy link
Owner

rm-hull commented Nov 16, 2020

Chuck - I would recommend adding your script to /etc/rc.local instead (be sure to use the & at the end of your command) or as Thijs mentioned, have a read around systemd.

These documents should be a good place to start:

/etc/profile is usually used to set PATH variable, user limits, and other settings: it may be that you are trying to start the python script before all the paths are correctly set up.

@chuckv2014
Copy link
Author

chuckv2014 commented Nov 16, 2020 via email

@chuckv2014
Copy link
Author

chuckv2014 commented Nov 18, 2020 via email

@rm-hull
Copy link
Owner

rm-hull commented Nov 19, 2020

In the example you gave, did you mean to do fill=black ?

If you want to do incremental updates like that, the only thing i can think is if you cleared out the rectangle before redrawing, e.g.

black = (0, 0, 0, 0)
white = (255,255,255,0)
self.draw.text((x,y), text=glyph1, font=font, fill=black) #wifi glyph 5 bars
device.display(self.im.convert(device.mode))
sleep(3)
w, h = self.draw.textsize(text=glyph1, font=font)
self.draw.rectangle((x, y, x+w, y+h), fill=background_color)
self.draw.text((x,y), text=glyph2, font=font, fill=black) #wifi glyph 0 bars
device.display(self.im.convert(device.mode))

However, I would really just recommend doing full screen updates every time using the canvas helper, as documented here: https://luma-oled.readthedocs.io/en/latest/python-usage.html#python-usage - look in the examples

@chuckv2014
Copy link
Author

chuckv2014 commented Nov 19, 2020 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants