Skip to content

Commit e9d1663

Browse files
committed
poll redraw fix on lcd
still implementing fields
1 parent d0ad7c8 commit e9d1663

File tree

6 files changed

+34
-9
lines changed

6 files changed

+34
-9
lines changed

menu.cpp

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,15 @@ int menu::menuKeys(menuOut &p,Stream& c,bool canExit) {
3232
if (sel>0) {
3333
sel--;
3434
if (sel+1>=p.maxY) p.top=sel-p.maxY;
35-
printMenu(p,canExit);
35+
p.drawn=0;
36+
//printMenu(p,canExit);
3637
}
3738
} else if (ch=='+') {
3839
if (sel<(sz-(canExit?0:1))) {
3940
sel++;
4041
if ((sz-sel+(canExit?1:0))>=p.maxY) p.top=sel-(canExit?1:0);
41-
printMenu(p,canExit);
42+
p.drawn=0;
43+
//printMenu(p,canExit);
4244
}
4345
} else if (ch==27) {
4446
op=-1;
@@ -65,6 +67,8 @@ void menu::activate(menuOut& p,Stream& c,bool canExit) {
6567
activeMenu=this;
6668
sel=0;
6769
p.top=0;
70+
//c.flush();//reset the encoder
71+
//p.drawn=0;//redraw menu
6872
}
6973
int op=-1;
7074
//do {
@@ -74,11 +78,14 @@ void menu::activate(menuOut& p,Stream& c,bool canExit) {
7478
sel=op;
7579
if (data[op]->enabled) {
7680
data[op]->activate(p,c,true);
77-
c.flush();//reset the encoder
78-
p.drawn=0;//redraw menu
81+
//c.flush();//reset the encoder
82+
//p.drawn=0;//redraw menu
7983
}
80-
} else if (op==-1) //then exit
84+
} else if (op==-1) {//then exit
8185
activeMenu=previousMenu;
86+
//c.flush();//reset the encoder
87+
//p.drawn=0;//redraw menu
88+
}
8289
//} while(op!=-1);
8390
}
8491

menu.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ for encoders, joysticks, keyboards or touch a stream must be made out of them
2626
class prompt;
2727
class menu;
2828
class menuOut;
29+
template <typename T> class menuField;
2930

3031
#define CONCATENATE(arg1, arg2) CONCATENATE1(arg1, arg2)
3132
#define CONCATENATE1(arg1, arg2) CONCATENATE2(arg1, arg2)
@@ -97,16 +98,17 @@ for encoders, joysticks, keyboards or touch a stream must be made out of them
9798
menu id (text,sizeof(id##_data)/sizeof(prompt*),id##_data);
9899

99100
#define OP(...) OP_(__COUNTER__,__VA_ARGS__)
100-
#define FIELD(...) FIELD_(__COUNTER__,__VA_ARGS__)
101+
#define FIELD_INT(...) FIELD_INT_(__COUNTER__,__VA_ARGS__)
101102

102103
#define DECL_OP_(cnt,...) prompt op##cnt(__VA_ARGS__);
103-
#define DECL_FIELD_(cnt,...) menuField _menuField##cnt(__VA_ARGS__);
104+
#define DECL_FIELD_INT_(cnt,...) menuField<int> _menuField_int##cnt(__VA_ARGS__);
104105
#define DECL_SUBMENU(id)
105106

106107
#define DEF_OP_(cnt,...) &op##cnt
107-
#define DEF_FIELD_(cnt,...) &_menuField##cnt
108+
#define DEF_FIELD_INT_(cnt,...) &_menuField_int##cnt
108109
#define DEF_SUBMENU(id) &id
109110

111+
110112
/////////////////////////////////////////////////////////
111113
// menu pure virtual output device, use derived
112114
// this base class represents the output device either derived to serial, LCD or other
@@ -132,6 +134,7 @@ for encoders, joysticks, keyboards or touch a stream must be made out of them
132134
virtual void print(double)=0;
133135
virtual void println(double)=0;
134136
virtual void print(prompt &o,bool selected,int idx,int posY,int width)=0;
137+
virtual void print(menuField<int> &o,bool selected,int idx,int posY,int width)=0;
135138
virtual void printMenu(menu&,bool drawExit)=0;
136139
};
137140

@@ -166,7 +169,7 @@ for encoders, joysticks, keyboards or touch a stream must be made out of them
166169
const char *text;
167170
promptAction action;
168171
bool enabled;
169-
prompt(const char * text):text(text),enabled(true) {}
172+
prompt(const char * text,bool enabled=true):text(text),enabled(enabled) {}
170173
prompt(const char * text,promptAction action)
171174
:text(text),action(action),enabled(true) {}
172175
virtual size_t printTo(Print& p) {p.print(text);return strlen(text);}

menuGFX.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ Use graphics screens (adafruit library based) as menu output
6868
//gfx.setTextColor(o.enabled?enabledColor:disabledColor,selected?hiliteColor:bgColor);
6969
gfx.print(o.text);
7070
}
71+
virtual void print(menuField<int> &o,bool selected,int idx,int posY,int width) {
72+
println("Ok, this is it");
73+
}
7174
virtual void printMenu(menu& m,bool drawExit) {
7275
if (drawn!=&m) clear();
7376
if (m.sel-top>=maxY) top=m.sel-maxY+1;//selected option outside device (bottom)

menuLCD.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ Use standard arduino LCD (LiquidCrystal library) as menu output
3434
print(selected?(o.enabled?menu::enabledCursor:menu::disabledCursor):' ');
3535
print(o.text);
3636
}
37+
virtual void print(menuField<int> &o,bool selected,int idx,int posY,int width) {
38+
println("Ok, this is it");
39+
}
3740
virtual void printMenu(menu& m,bool drawExit) {
3841
clear();
3942
if (m.sel-top>=maxY) top=m.sel-maxY+1;//selected option outside device (bottom)

menuLCDs.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,12 @@ as VirtualPins is not yet a standard I implemented this to support existing libr
3636
print(selected?(o.enabled?menu::enabledCursor:menu::disabledCursor):' ');
3737
print(o.text);
3838
}
39+
virtual void print(menuField<int> &o,bool selected,int idx,int posY,int width) {
40+
println("Ok, this is it");
41+
}
3942
virtual void printMenu(menu& m,bool drawExit) {
43+
if (drawn==&m) return;
44+
Serial.println("menuLCD clear");
4045
clear();
4146
if (m.sel-top>=maxY) top=m.sel-maxY+1;//selected option outside device (bottom)
4247
else if (m.sel<top) top=m.sel;//selected option outside device (top)
@@ -48,6 +53,7 @@ as VirtualPins is not yet a standard I implemented this to support existing libr
4853
}
4954
if (drawExit&&i-top<maxY)
5055
print(menu::exitOption,m.sel==m.sz,0,i-top,m.width);
56+
drawn=&m;
5157
}
5258
};
5359
#endif RSITE_ARDUINOP_MENU_LCD

menuPrint.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ menu output to Print device (ex: Serial)
3535
print(selected?(o.enabled?menu::enabledCursor:menu::disabledCursor):' ');
3636
println(o.text);
3737
}
38+
virtual void print(menuField<int> &o,bool selected,int idx,int posY,int width) {
39+
println("Ok, this is it");
40+
}
3841
virtual void printMenu(menu& m,bool drawExit) {
3942
clear();
4043
int i=0;for(;i<m.sz;i++)

0 commit comments

Comments
 (0)