Skip to content

Commit 56882fa

Browse files
committed
Deriving menuOut from Arduino Print, reducing the library footprint
1 parent 405a555 commit 56882fa

File tree

4 files changed

+17
-20
lines changed

4 files changed

+17
-20
lines changed

menu.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,11 @@ int menu::menuKeys(menuOut &p,Stream& c,bool canExit) {
3636
if (sel>0) {
3737
sel--;
3838
if (sel+1>=p.maxY) p.top=sel-p.maxY;
39-
//p.drawn=0;
40-
//printMenu(p,canExit);
4139
}
4240
} else if (ch==menu::upCode) {
4341
if (sel<(sz-(canExit?0:1))) {
4442
sel++;
4543
if ((sz-sel+(canExit?1:0))>=p.maxY) p.top=sel-(canExit?1:0);
46-
//p.drawn=0;
47-
//printMenu(p,canExit);
4844
}
4945
} else if (ch==menu::escCode) {
5046
op=-1;
@@ -54,6 +50,7 @@ int menu::menuKeys(menuOut &p,Stream& c,bool canExit) {
5450
if (!((op>=0&&op<sz)||(canExit&&op==-1))) op=-2;//validate the option
5551
//add some delays to be sure we do not have more characters NL or CR on the way
5652
//delay might be adjusted to cope with stream speed
53+
//TODO: guess we dont need this.. check it out
5754
delay(50);while (c.peek()==menu::enterCode/*||c.peek()==10*/) {c.read();delay(50);}//discard ENTER and CR
5855
return op;
5956
}

menu.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ www.r-site.net
138138
/////////////////////////////////////////////////////////
139139
// menu pure virtual output device, use derived
140140
// this base class represents the output device either derived to serial, LCD or other
141-
class menuOut {
141+
class menuOut:public Print {
142142
public:
143143

144144
menu* drawn;//last drawn menu, avoiding clear/redraw on each nav. change
@@ -159,18 +159,19 @@ www.r-site.net
159159
enum drawStyle {NORMAL=0,SELECTED,EDITING,TUNNING,DISABLED};
160160

161161
//member functions
162+
virtual size_t write(uint8_t) = 0;
162163
bool needRedraw(menu& m,int i);
163164
virtual void clearLine(int ln)=0;
164165
virtual void clear()=0;
165166
virtual void setCursor(int x,int y)=0;
166-
virtual void print(char ch)=0;
167+
/*virtual void print(char ch)=0;
167168
virtual void print(const char *text)=0;
168169
virtual void println(const char *text="")=0;
169170
virtual void print(unsigned long)=0;
170171
virtual void println(unsigned long)=0;
171172
virtual void print(double)=0;
172-
virtual void println(double)=0;
173-
virtual void print(prompt &o,bool selected,int idx,int posY,int width);
173+
virtual void println(double)=0;*/
174+
virtual void printPrompt(prompt &o,bool selected,int idx,int posY,int width);
174175
virtual void printMenu(menu&,bool drawExit)=0;
175176
};
176177

menuFields.h

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
/********************
2+
www.r-site.net
23
Nov. 2014 Rui Azevedo - ruihfazevedo(@rrob@)gmail.com
3-
creative commons license 3.0: Attribution-ShareAlike CC BY-SA
4-
This software is furnished "as is", without technical support, and with no
5-
warranty, express or implied, as to its usefulness for any purpose.
6-
7-
Thread Safe: No
8-
Extensible: Yes
9-
104
implementing menu fields as options that show a value
115
value (variable reference) can be changed by either using:
126
menuField - for numeric varibles between range and optinally with a tune speed
@@ -16,7 +10,14 @@ value (variable reference) can be changed by either using:
1610
class menuValue is used as a menu prompt with an associated value for menuChoose and menuToggle
1711
1812
this classes are implemented as templates to accomodate virtually any value type
19-
www.r-site.net
13+
14+
creative commons license 3.0: Attribution-ShareAlike CC BY-SA
15+
This software is furnished "as is", without technical support, and with no
16+
warranty, express or implied, as to its usefulness for any purpose.
17+
18+
Thread Safe: No
19+
Extensible: Yes
20+
2021
***/
2122

2223
#ifndef RSITE_ARDUINOP_MENU_FIELDS
@@ -55,10 +56,8 @@ www.r-site.net
5556
virtual void printTo(menuOut& p) {
5657
p.print(text);
5758
p.print(activeNode==this?(tunning?'>':':'):' ');
58-
p.print((unsigned long)value);
59-
p.print(" ");
59+
p.print(value);
6060
p.print(units);
61-
p.print(" ");
6261
}
6362
void clamp() {
6463
if (value<low) value=low;

menuGFX.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ www.r-site.net
7373
gfx.setTextColor(o.enabled?enabledColor:disabledColor);
7474
setCursor(0,posY);
7575
o.printTo(*this);
76-
println();
76+
//println();
7777
}
7878
virtual void printMenu(menu& m,bool drawExit) {
7979
if (drawn!=&m) clear();//clear all screen when changing menu

0 commit comments

Comments
 (0)