Skip to content

Commit a0688da

Browse files
committed
fix: reset encoder position on user function return (menu resume)
1 parent edf1195 commit a0688da

File tree

3 files changed

+14
-6
lines changed

3 files changed

+14
-6
lines changed

Examples/menu_test/menu_test.ino

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ ruihfazevedo@[email protected]
88
#include <virtual_pins.h>
99
#include <HardwareSerial.h>
1010
#include <LiquidCrystal.h>
11-
#include "menu.h"//menu macros and objects
12-
#include "pcint.h"//this is incompatible with software serial (arduino needs an handler!)
13-
#include "quadEncoder.h"//quadrature encoder driver and fake stream
14-
#include "keyStream.h"//keyboard driver and fake stream (for the encoder button)
15-
#include "chainStream.h"// concatenate multiple input streams (this allows adding a button to the encoder)
16-
#include "menuPrint.h"//Print (Serial) menu
11+
#include <menu.h>//menu macros and objects
12+
#include <pcint.h>//this is incompatible with software serial (arduino needs an handler!)
13+
#include <quadEncoder.h>//quadrature encoder driver and fake stream
14+
#include <keyStream.h>//keyboard driver and fake stream (for the encoder button)
15+
#include <chainStream.h>// concatenate multiple input streams (this allows adding a button to the encoder)
16+
#include <menuPrint.h>//Print (Serial) menu
1717

1818
#define LCDWIRE_NONE 0
1919
#define LCDWIRE_VPINS_I2C 1

keywords.txt

100755100644
File mode changed.

menu.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ char menu::enabledCursor='>';
1717
char menu::disabledCursor='-';
1818
prompt menu::exitOption(menu::exit);
1919

20+
//menu navigation engine
21+
//iteract with input until a selection is done, return the selection
2022
int menu::menuKeys(menuOut &p,Stream& c,bool canExit) {
2123
int op=-2;
2224
do {
@@ -50,6 +52,11 @@ int menu::menuKeys(menuOut &p,Stream& c,bool canExit) {
5052
return op;
5153
}
5254

55+
//execute the menu
56+
//cycle:
57+
// ...->draw -> input scan -> iterations -> [activate submenu or user function] -> ...
58+
// draw: call target device object
59+
//input scan: call the navigation function (self)
5360
void menu::activate(menuOut& p,Stream& c,bool canExit) {
5461
sel=0;
5562
p.top=0;
@@ -61,6 +68,7 @@ void menu::activate(menuOut& p,Stream& c,bool canExit) {
6168
sel=op;
6269
if (data[op]->enabled) {
6370
data[op]->activate(p,c,true);
71+
c.flush();//reset the encoder
6472
p.drawn=0;//redraw menu
6573
}
6674
}

0 commit comments

Comments
 (0)