Skip to content

Commit 2dd269b

Browse files
committed
bugfix: serial refresh on serial (reflexivity)
1 parent df00a79 commit 2dd269b

File tree

2 files changed

+54
-68
lines changed

2 files changed

+54
-68
lines changed

src/menuFields.h

Lines changed: 33 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -169,61 +169,45 @@ v2.0 - Calling action on every elements
169169
//this kind of information... till there we can not use paralle output devices! RA2016
170170
menuSelect(const char *text,unsigned int sz,menuValue<T>* const data[],T& target):
171171
menuVariant<T>(target,text,sz,data) {menuVariant<T>::sync();}
172-
virtual bool needRedraw(menuOut&p,bool selected) {
173-
if (selected) {
174-
bool nr=lastDrawnOp!=menu::sel;//||((menuValue<T>*)pgmPtrNear(menu::data[menu::sel]))->value==menuVariant<T>::target;
175-
//T v=((menuValue<T>*)pgmPtrNear(menu::data[menu::sel]))->value;
176-
//if (nr) Serial<<"Variant need redraw:"<<*this<<endl
177-
/*Serial
178-
<<" value:"<<v<<endl
179-
<<" target:"<<menuVariant<T>::target
180-
<<" sel:"<<menu::sel
181-
<<" lastSel:"<<p.lastSel
182-
<<" lastDrawnOp:"<<lastDrawnOp
183-
<<endl;;*/
184-
//p.lastSel=menu::sel;
185-
lastDrawnOp=menu::sel;
186-
return nr;
187-
}
188-
return ((menuValue<T>*)pgmPtrNear(menu::data[menu::sel]))->value!=menuVariant<T>::target;
189-
}
190172
virtual void printTo(menuOut& p) {
191-
//Serial<<"drawing menuSelect"<<endl;
192173
menuVariant<T>::sync();
193174
print_P(p,menu::text);
194175
p.print(menu::activeNode==this?':':' ');
195176
((prompt*)pgmPtrNear(menu::data[menu::sel]))->printTo(p);
196177
}
197-
promptFeedback activate(menuOut& p,Stream& c,bool) {
198-
if (menu::activeNode!=this) {
199-
//Serial<<"first select"<<endl;
200-
if (menuVariant<T>::action(*this,p,c)) return true;
201-
this->setPosition(menuNode::activeNode->ox,menuNode::activeNode->oy);
202-
this->menu::previousMenu=(menu*)menu::activeNode;
203-
menu::activeNode=this;
204-
this->canExit=false;
205-
if (p.top>menu::sel) p.top=menu::sel;
206-
else if (menu::sel+1>p.maxY) p.top=menu::sel-p.maxY+1;
207-
p.lastSel=-1;//redraw only affected option
208-
}
209-
int op=menu::menuKeys(p,c,false);
210-
menu::previousMenu->menu::printMenu(p,menu::previousMenu->canExit);
211-
if (op>=0&&op<this->menu::sz) {
212-
//Serial<<"Selecting op:"<<op<<endl;
213-
this->menu::sel=op;
214-
menuValue<T>* cp=(menuValue<T>*)pgmPtrNear(this->menu::data[op]);
215-
if (cp->enabled) {
216-
this->menuVariant<T>::target=cp->value;
217-
cp->activate(p,c,true);
218-
p.lastSel=-1;//redraw only affected option
219-
//and exit
220-
this->menu::activeNode=this->menu::previousMenu;
221-
c.flush();//reset the encoder
222-
}
223-
}
224-
//Serial<<"sel:"<<menu::sel<<" op:"<<op<<endl;
225-
return false;
226-
}
178+
promptFeedback activate(menuOut& p,Stream& c,bool) {
179+
if (menu::activeNode!=this) {
180+
if (menuVariant<T>::action(*this,p,c)) return true;
181+
this->setPosition(menuNode::activeNode->ox,menuNode::activeNode->oy);
182+
menu::previousMenu=(menu*)menu::activeNode;
183+
menu::activeNode=this;
184+
this->canExit=false;
185+
if (p.top>menu::sel) p.top=menu::sel;
186+
else if (menu::sel+1>p.maxY) p.top=menu::sel-p.maxY+1;
187+
p.lastSel=-1;//redraw only affected option
188+
}
189+
int lsel=menu::sel;
190+
int op=menu::menuKeys(p,c,false);
191+
if (op>=0&&op<this->menu::sz) {
192+
menu::sel=op;
193+
menuValue<T>* cp=(menuValue<T>*)pgmPtrNear(this->menu::data[op]);
194+
if (cp->enabled) {
195+
menuVariant<T>::target=cp->value;
196+
cp->activate(p,c,true);
197+
p.lastSel=-1;//redraw only affected option
198+
//and exit
199+
this->menu::activeNode=this->menu::previousMenu;
200+
c.flush();//reset the encoder
201+
}
202+
}
203+
if (menu::sel!=lsel) {
204+
menuVariant<T>::target=((menuValue<T>*)&menu::operator[](menu::sel))->value;
205+
p.lastSel=-1;//redraw only affected option
206+
}
207+
menu::previousMenu->menu::printMenu(p,menu::previousMenu->canExit);
208+
//Serial<<"sel:"<<menu::sel<<" op:"<<op<<endl;
209+
return false;
210+
}
227211
};
228212

229213
template<typename T>

src/menuPrint.h

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ www.r-site.net
1212
***/
1313

1414
#ifndef RSITE_ARDUINOP_MENU_PRINT
15-
#define RSITE_ARDUINOP_MENU_PRINT
16-
#include "menu.h"
15+
#define RSITE_ARDUINOP_MENU_PRINT
16+
#include "menu.h"
1717

1818
class menuPrint:public menuOut {
1919
public:
@@ -23,24 +23,26 @@ www.r-site.net
2323
virtual void clear() {device.println("");device.println("");}
2424
virtual void setCursor(int x,int y) {device.println("");}
2525
virtual size_t write(uint8_t ch) {return device.write(ch);}
26-
virtual void printPrompt(prompt &o,bool selected,int idx,int posX,int posY,int width) {
26+
virtual void printPrompt(prompt &o,bool selected,int idx,int posX,int posY,int width) {
2727
print(idx<10?" ":"");
2828
print((unsigned long)idx);
29-
print(selected?(o.enabled?menu::enabledCursor:menu::disabledCursor):' ');
30-
o.printTo(*this);
31-
println();
32-
}
33-
virtual void printMenu(menu& m,bool drawExit) {
34-
if (drawn==&m&&m.sel==lastSel) return;
35-
clear();
36-
int i=0;
37-
for(;i<m.sz;i++)
38-
printPrompt(*(prompt*)pgmPtrNear(m.data[i]),i==m.sel,i+1,i-top,0,m.width);
39-
if (drawExit) printPrompt(menu::exitOption,m.sel==m.sz,i,0,i-top,m.width);
40-
lastTop=top;
41-
lastSel=m.sel;
42-
drawn=&m;
43-
}
44-
};
29+
print(selected?(o.enabled?menu::enabledCursor:menu::disabledCursor):' ');
30+
o.printTo(*this);
31+
println();
32+
}
33+
virtual void printMenu(menu& m,bool drawExit) {
34+
bool any=false;
35+
for(int i=0;i<m.sz;i++) any|=m[i].needRedraw(*this,i==m.sel);
36+
if ((!any)&&drawn==&m&&m.sel==lastSel) return;
37+
clear();
38+
int i=0;
39+
for(;i<m.sz;i++)
40+
printPrompt(*(prompt*)pgmPtrNear(m.data[i]),i==m.sel,i+1,i-top,0,m.width);
41+
if (drawExit) printPrompt(menu::exitOption,m.sel==m.sz,i,0,i-top,m.width);
42+
lastTop=top;
43+
lastSel=m.sel;
44+
drawn=&m;
45+
}
46+
};
4547

4648
#endif RSITE_ARDUINOP_MENU_PRINT

0 commit comments

Comments
 (0)