Closed TwystNeko closed 1 year ago
Hi TwystNeko!
From the top of my head, try adding menu.registerKeyPress(GEM_KEY_NONE);
to your loop()
in the case when no useful interaction was performed during the iteration of the loop.
The thing is, context.loop()
function is called from within GEM, specifically from within ::dispatchKeyPress()
function which in turn is called from within ::registerKeyPress()
. So you need to call registerKeyPress()
in order to invoke user-defined loop. And when you press the button you are doing exactly that - calling ::registerKeyPress()
method. So even if are not going to interact with your sketch via pressing the button, you should explicitly call ::registerKeyPress()
method anyway, supplying it with dummy code GEM_KEY_NONE
.
So your loop may look something like this:
void loop() {
// do input checks! Separate function?
long newposition = dial.read();
automaton.run();
if(newposition != oldposition) {
if(abs(newposition - oldposition) > ENC_SLOWDOWN) {
if(newposition > oldposition) {
menu.registerKeyPress(GEM_KEY_DOWN);
} else if(newposition < oldposition) {
menu.registerKeyPress(GEM_KEY_UP);
}
}
oldposition = newposition;
playback_state = !digitalRead(2);
} else {
menu.registerKeyPress(GEM_KEY_NONE);
}
lcd.sendBuffer();
}
Alternatively, this probably can work as well:
void loop() {
// do input checks! Separate function?
long newposition = dial.read();
automaton.run();
if(newposition != oldposition) {
if((abs(newposition - oldposition) > ENC_SLOWDOWN) && menu.readyForKey()) {
if(newposition > oldposition) {
menu.registerKeyPress(GEM_KEY_DOWN);
} else if(newposition < oldposition) {
menu.registerKeyPress(GEM_KEY_UP);
}
}
oldposition = newposition;
playback_state = !digitalRead(2);
}
lcd.sendBuffer();
}
Note call to menu.readyForKey()
. That method checks if GEM is ready to accept an interaction and internally calls registerKeyPress(GEM_KEY_NONE);
if some conditions are met (yours seems to).
That did it! Thanks!
So, I'm working on an incredibly silly mp3 player, and things are going fairly smooth.
I've set up a menuContextLoop which displays a "now playing screen". It's a static screen for now, so I didn't notice, but the loop is only triggering when a button is pressed, or the rotary encoder turns. I'm working off the "Party Hard" sketch, and it looks like I've set it up the same way, but it's just not running continuously. I have a progress bar, for example, that should update every second, but it never fires unless I turn the dial. The rest of the program works, but without the loop triggering as expected, I can't check if playback has stopped.