peterhinch / micropython-micro-gui

A lightweight MicroPython GUI library for display drivers based on framebuf, allows input via pushbuttons. See also micropython-touch.
MIT License
247 stars 37 forks source link

encoder with switch as input? #36

Closed eudoxos closed 12 months ago

eudoxos commented 1 year ago

Hello, currently there is the option to use 3 buttons for navigation. Could I get some idea on how to enhance the code to use +/-/click functionalities of the encoder as next/prev/sel in the Input class? Thanks!

beyonlo commented 1 year ago

Hello @eudoxos

In the hardware_setup.py you need configure how many buttons do you want, minimum is two buttons (sel and next)

nxt = Pin(19, Pin.IN, Pin.PULL_UP)  # Move to next control
sel = Pin(16, Pin.IN, Pin.PULL_UP)  # Operate current control
prev = Pin(18, Pin.IN, Pin.PULL_UP)  # Move to previous control

In your case, you need to comment lines:

increase = Pin(20, Pin.IN, Pin.PULL_UP)  # Increase control's value
decrease = Pin(17, Pin.IN, Pin.PULL_UP)  # Decrease control's value

And in the next line (display) use only 3 buttons:

display = Display(ssd, nxt, sel, prev)  # 3-button mode

You need also configure the correct driver for your display and after that you can just run the many demos (that are very good) to test the 3 -buttons Screens

peterhinch commented 1 year ago

@eudoxos If I understand correctly you want to use an encoder as the only control, rotating it for next/prev and pressing it for sel. This is an interesting idea for projects that don't need increase/decrese. Currently this is not supported: the encoder is used only for adjusting numeric controls although pressing it can be assigned to sel.

It would need some rejigging of the interface and I'm afraid I don't have time to study this further.

eudoxos commented 1 year ago

OK, I understand this might be disruptive, so I will just put the idea here in more detail and then close the issue:

peterhinch commented 1 year ago

Thanks for that.

It's a mode of operation that I hadn't considered, but it does look promising. On screens with a lot of controls pressing next/prev does get rather tedious. I'll leave the issue open for when I can find time to study it properly.

peterhinch commented 12 months ago

@eudoxos I have pushed an update which offers this. Documentation to follow.

If you'd like to test it please update gui/core/ugui.py. The "encoder only" mode is invoked by changing your hardware_setup.py as follows:

sel = Pin(16, Pin.IN, Pin.PULL_UP)  # Encoder button
x = Pin(20, Pin.IN, Pin.PULL_UP)  # Encoder X
y = Pin(17, Pin.IN, Pin.PULL_UP)  # Encoder Y
display = Display(ssd, x, sel, y, False, None, 4)  # Encoder-only mode

incr=False sets encoder only mode encoder=4 defines the encoder division ratio.

When you click on a variable control it goes into adjustment mode. A long press puts it into precision mode.

peterhinch commented 12 months ago

Thank you very much for this suggestion which works well, and is a great improvement.

I find the interface fast and intuitive. It is especially effective when there are a lot of widgets on a screen. Closing this as complete, but comments are of course welcome.