Comments (11)
@Spirik Thanks for a quick reply!
Ah ok I think i understand now. So the "control menu from sketch" literally lets you control a menu arbitrarily with whatever conditional or changes you want.
One followup: Is there a straight forward way to change the logic for how the menu item / selection process works?
For instance I specifically want to change the way the digit selection process works. Preferably in this way:
- Select a menu item
- Left or right key press will change the digit selection position.
- A push button will select for edit
- Left or right key press will change value up or down.
- Push button again will "set" digit and let you continue to move left or right from digits.
I would still have a dedicated back or cancel button. This would allow me with a rotary encoder + extra push button to control all menu settings.
from gem.
How an item would be saved in that scheme (apart from pressing cancel button, which results in exit without saving), since you're planning to use push button to select digit position while in edit mode? Or is your plan to save an item any time its digit is saved? That may lead to some unwanted results (unnecessary triggering validation callbacks, redrawing menu, etc.).
And I am afraid there is no way you can edit this logic without editing source code of library.
What you can do without modifying the source code, however, is to wait for menu to be ready to accept a key press and then fire up your own logic to determine which menu key press to trigger:
void loop() {
// If menu is ready to accept button press...
if (menu.readyForKey()) {
// ...detect key press using your own logic
byte keyCode = myRotaryEncoderKeyDetectionLogic();
// Pass pressed button to menu
menu.registerKeyPress(keyCode);
}
}
Edit:
On the second thought, It still may be possible to recreate the logic you described without editing the source code. Just track combination of short and long presses of the push button to determine how to interpret the rotation of the knob (whether to send GEM_KEY_LEFT/RIGHT
or GEM_KEY_UP/DOWN
codes).
from gem.
I implemented this as you suggested, Spirik, assigning the encoder to up/down keypresses, and a short press of the button to "ok" and a long press to "right". Works great. Thank you!
from gem.
Hi=)
Unfortunately there is no example for rotary encoders specifically, but theoretically as soon as input device can produce 6 basic operations that menu understands (up, right, down, left, ok, cancel) it should be completely possible. But it is up to you to figure out how to extract those readings from encoder (or any other input device for that matter).
See Control menu from your sketch section of wiki for a little more details. You may want to look into how KeyDetector
or U8g2
key detection organized in supplied examples (in their loop()
) as a starting point.
Hopefully this may help!
from gem.
Well the encoder has a push button built in. So I would have two push buttons total, and two left/right keys (encoder).
This sounds promising. I'll take a stab at this in the morning.
Another question: How does one constrain the values while editing?
For instance lets say I have a value of 3523 and I want to limit its settings from 3000 - 3800. Is there a way to handle constraining this value?
Also related, is there possibly a way to instead of editing digit by digit, you could simply +/- from the full value all together?
from gem.
Another question: How does one constrain the values while editing?
For instance lets say I have a value of 3523 and I want to limit its settings from 3000 - 3800. Is there a way to handle constraining this value?
You can not constrain user input during edit mode, however you can implement validation callback, that will be triggered upon saving the value: that way you can change value to, say, the closest one from the valid range, once user finished editing.
Also related, is there possibly a way to instead of editing digit by digit, you could simply +/- from the full value all together?
Nope, unfortunately there is no way to do that at the moment. However there is possibility it will be implemented in the future via dedicated menu item type.
from gem.
In case this is relevant, I'm after similar functionality and among other things #42 adds a callback upon entering the edit mode. You could use that to start scrolling over the desired range.
from gem.
@danieltwagner Does your implementation allow to scroll over an entire range of a number, or just a single digit of that number?
from gem.
Just the single digits as is the case in "vanilla" GEM. I was going to look at extending it to scroll over the entire range though. It just turned out to not be super straight-forward to figure out an intuitive interaction to cater to both long ranges as well as fine adjustments so I've punted that for now to implement the part that the controller/menu actually controls :)
from gem.
@zandernc Is it possible to rotate the knob while simultaneously being pressed on your encoder? If it is, then I would suggest to consider the following scheme:
- Rotation - Up, Down;
- Rotation + Press - Left, Right;
- Short press - Ok;
- Long press - Cancel.
That way we will cover all 6 interactions GEM is able to respond to.
from gem.
👋 FYI: just updated GEM with examples on how to control menu with rotary encoder using latest version of KeyDetector (implementing control scheme described above).
from gem.
Related Issues (20)
- "Increment" Item type HOT 4
- Replace/override sprites for menu decorations? HOT 11
- Menu controlling via serial port HOT 8
- Supports setting single one menu attributes HOT 2
- Simpler create layout way and chain operations HOT 3
- freezing on RP2040 HOT 10
- Encoder or/and 4x4_over_i2c_multiplexer HOT 9
- Setting conditional pages HOT 1
- Limiting float and integer variable HOT 1
- Control with keypad 4x4 HOT 1
- Floating point HOT 4
- Does GEM Library Support SSD1306 HOT 6
- core 1 panic'ed (loadprohibited) on registerKeyPress HOT 17
- Context Loop only triggers on input HOT 2
- Editing number value... HOT 2
- Не отображается значение в пункте меню на дисплее HX1230 HOT 7
- Switch button behavior for 3-buttons navigations HOT 3
- Add std::function callbacks feature HOT 8
- Compilation errors with LilyGo TTGO T-Display HOT 6
- Problem with ESP32 S3, When i updated arduino-esp32 and boards HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gem.