Skip to content

Commit 6490147

Browse files
committed
PCINT made compatible with arduino mega (Atmega2560)
and structured for wide compatibility by using arduino PCICR and PCMSKn map macros
1 parent 4dc42ce commit 6490147

File tree

8 files changed

+91
-187
lines changed

8 files changed

+91
-187
lines changed

menu.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Thread Safe: No
88
Extensible: Yes
99
1010
Arduino generic menu system
11+
www.r-site.net
1112
*/
1213
#include <Arduino.h>
1314
#include "menu.h"
@@ -18,6 +19,8 @@ char menu::disabledCursor='-';
1819
prompt menu::exitOption(menu::exit);
1920
menuNode* menuNode::activeNode=NULL;
2021

22+
bool menuOut::needRedraw(menu& m,int i) {return (drawn!=&m)||(top!=lastTop)||(m.sel!=lastSel&&((i==m.sel)||(i==lastSel)));}
23+
2124
//menu navigation engine
2225
//iteract with input until a selection is done, return the selection
2326
int menu::menuKeys(menuOut &p,Stream& c,bool canExit) {

menu.h

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ Arduino generic menu system
1717
1818
the menu system will read provided stream for input, it works for Serial,
1919
encoders, joysticks, keyboards (or touch?) a stream must be made out of them
20+
www.r-site.net
2021
*/
2122
#ifndef RSITE_ARDUINOP_MENU_SYSTEM
2223
#define RSITE_ARDUINOP_MENU_SYSTEM
@@ -113,6 +114,9 @@ encoders, joysticks, keyboards (or touch?) a stream must be made out of them
113114
};\
114115
menuToggle<typeof(target)> id (text,sizeof(id##_data)/sizeof(prompt*),id##_data,target);
115116

117+
/*#define GET_MACRO(_1,_2,NAME,...) NAME
118+
#define VALUE(...) GET_MACRO(__VA_ARGS__, EXPLICIT_VALUE, IMPLICIT_VALUE)(__VA_ARGS__)*/
119+
116120
#define OP(...) OP_(__COUNTER__,__VA_ARGS__)
117121
#define FIELD(...) FIELD_(__COUNTER__,__VA_ARGS__)
118122
#define VALUE(...) VALUE_(__COUNTER__,__VA_ARGS__)
@@ -136,17 +140,31 @@ encoders, joysticks, keyboards (or touch?) a stream must be made out of them
136140
public:
137141
menu* drawn;//last drawn menu, avoiding clear/redraw on each nav. change
138142
int top;//top for this device
139-
//device size
143+
//device size (in characters)
140144
int maxX;
141145
int maxY;
142-
//device resolution
146+
//device resolution (pixels per character)
143147
int resX;
144148
int resY;
145149
//preventing uneeded redraws
146-
int lastTop;
147-
int lastSel;
148-
menuOut(int x=0x7F,int y=0x7F,int resX=1,int resY=1)
150+
int lastTop=-1;
151+
int lastSel=-1;
152+
153+
inline menuOut(int x=0x7F,int y=0x7F,int resX=1,int resY=1)
149154
:maxX(x),maxY(y),top(0),resX(resX),resY(resY),drawn(0) {}
155+
156+
enum drawStyle {NORMAL=0,SELECTED,EDITING,TUNNING,DISABLED};
157+
//just access the vars, its all public!
158+
/*
159+
inline menuOut() {}
160+
inline menuOut& xmax(int x) {maxX=x;return *this;}
161+
inline menuOut& ymay(int y) {maxY=y;return *this;}
162+
163+
inline menuOut& xres(int x) {maxX=x;return *this;}
164+
inline menuOut& yres(int y) {maxY=y;return *this;}*/
165+
166+
//member functions
167+
bool needRedraw(menu& m,int i);
150168
virtual void clear()=0;
151169
virtual void setCursor(int x,int y)=0;
152170
virtual void print(char ch)=0;
@@ -156,7 +174,7 @@ encoders, joysticks, keyboards (or touch?) a stream must be made out of them
156174
virtual void println(int)=0;
157175
virtual void print(double)=0;
158176
virtual void println(double)=0;
159-
virtual void print(prompt &o,bool selected,int idx,int posY,int width)=0;
177+
virtual void print(prompt &o,bool selected,int idx,int posY,int width);
160178
virtual void printMenu(menu&,bool drawExit)=0;
161179
};
162180

@@ -205,7 +223,7 @@ encoders, joysticks, keyboards (or touch?) a stream must be made out of them
205223

206224
class menuNode:public prompt {//some basic information for menus and fields
207225
public:
208-
int width=16;//field or menu width
226+
int width=32;//field or menu width
209227
//navigation and focus control
210228
static menuNode* activeNode;
211229
menu* previousMenu=NULL;

menuGFX.h

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Thread Safe: No
88
Extensible: Yes
99
1010
Use graphics screens (adafruit library based) as menu output
11+
www.r-site.net
1112
***/
1213
#ifndef RSITE_ARDUINOP_MENU_GFX
1314
#define RSITE_ARDUINOP_MENU_GFX
@@ -30,10 +31,10 @@ Use graphics screens (adafruit library based) as menu output
3031

3132
class menuGFX:public menuOut {
3233
public:
33-
uint16_t bgColor;
34-
uint16_t enabledColor;
35-
uint16_t disabledColor;
36-
uint16_t hiliteColor;
34+
uint16_t hiliteColor=BLUE;
35+
uint16_t bgColor=SILVER;
36+
uint16_t enabledColor=WHITE;
37+
uint16_t disabledColor=RED;
3738
Adafruit_GFX& gfx;
3839
menuGFX(
3940
Adafruit_GFX& gfx,
@@ -50,7 +51,14 @@ Use graphics screens (adafruit library based) as menu output
5051
disabledColor(disabledColor),
5152
hiliteColor(hiliteColor),
5253
menuOut(gfx.width()/resX,gfx.height()/resY,resX,resY) {}
53-
virtual void clear() {gfx.fillScreen(bgColor);gfx.setCursor(0,0);}
54+
55+
virtual void clear() {
56+
//gfx.fillScreen(bgColor);
57+
Serial<<"max:"<<maxX<<","<<maxY<<endl
58+
<<"res:"<<resX<<","<<resY<<endl;
59+
gfx.fillRect(0,0,resX*maxX,resY*maxY,bgColor);
60+
gfx.setCursor(0,0);
61+
}
5462
virtual void setCursor(int x,int y) {gfx.setCursor(x*resX,y*resY);}
5563
virtual void print(char ch) {gfx.print(ch);}
5664
virtual void print(const char *text) {gfx.print(text);}
@@ -60,27 +68,37 @@ Use graphics screens (adafruit library based) as menu output
6068
virtual void print(double i) {gfx.print(i);};
6169
virtual void println(double i) {gfx.println(i);};
6270
virtual void print(prompt &o,bool selected,int idx,int posY,int width) {
71+
Serial<<"menuGFX printing prompt "<<o.text<<endl;
6372
gfx.fillRect(0,posY*resY,width*resX,resY,selected?hiliteColor:bgColor);
6473
gfx.setTextColor(o.enabled?enabledColor:disabledColor);
6574
gfx.setCursor(0,posY*resY);
6675
o.printTo(gfx);
67-
println();
76+
//println();
6877
}
69-
inline int needRedraw(menu& m,int i) {return (drawn!=&m)||(top!=lastTop)||(m.sel!=lastSel&&((i==m.sel)||(i==lastSel)));}
78+
/*virtual void print(menuField &o,bool selected,int idx,int posY,int width) {
79+
p.print(text);
80+
p.print(activeNode==this?(tunning?'>':':'):' ');
81+
p.print(value);
82+
p.print(" ");
83+
p.print(units);
84+
p.print(" ");
85+
}*/
86+
/*drawStyle getStyle(prompt& p,bool selected,bool editing=false) {
87+
if (p.enabled)
88+
return selected?SELECTED:NORMAL;
89+
else return DISABLED;
90+
}*/
7091
virtual void printMenu(menu& m,bool drawExit) {
7192
if (drawn!=&m) clear();//clear all screen when changing menu
7293
if (m.sel-top>=maxY) top=m.sel-maxY+1;//selected option outside device (bottom)
7394
else if (m.sel<top) top=m.sel;//selected option outside device (top)
74-
int i=0;for(;i<m.sz;i++) {
75-
if ((i>=top)&&((i-top)<maxY)) {
95+
int i=top;for(;i<m.sz;i++) {
96+
//if ((i>=top)&&((i-top)<maxY)) {
7697
if(i-top>=maxY) break;
7798
if (needRedraw(m,i)) {
78-
Serial<<hex((long)drawn)<<" <-> "<<hex((long)&m)
79-
<<(drawn!=&m)<<(top!=lastTop)<<(m.sel!=lastSel&&((i==m.sel)||(i==lastSel)))
80-
<<" drawing option:"<<m.data[i]->text<<endl;
8199
print(*m.data[i],i==m.sel,i+1,i-top,m.width);
82100
}
83-
}
101+
//}
84102
}
85103
if (drawExit&&i-top<maxY&&needRedraw(m,i))
86104
print(menu::exitOption,m.sel==m.sz,0,i-top,m.width);

menuLCD.h

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ Thread Safe: No
88
Extensible: Yes
99
1010
Use standard arduino LCD (LiquidCrystal library) as menu output
11+
12+
www.r-site.net
1113
***/
1214

1315
#ifndef RSITE_ARDUINOP_MENU_LCD
@@ -35,18 +37,22 @@ Use standard arduino LCD (LiquidCrystal library) as menu output
3537
println();
3638
}
3739
virtual void printMenu(menu& m,bool drawExit) {
38-
if (drawn==&m) return;
39-
clear();
40+
Serial<<"Printing menu "<<m.text<<endl;
41+
if (drawn!=&m) clear();//clear screen when changing menu
4042
if (m.sel-top>=maxY) top=m.sel-maxY+1;//selected option outside device (bottom)
4143
else if (m.sel<top) top=m.sel;//selected option outside device (top)
4244
int i=0;for(;i<m.sz;i++) {
4345
if ((i>=top)&&((i-top)<maxY)) {
44-
if(i-top>=maxY) break;
45-
print(*m.data[i],i==m.sel,i+1,i-top,m.width);
46+
//if(i-top>=maxY) break;
47+
if (needRedraw(m,i)) {
48+
print(*m.data[i],i==m.sel,i+1,i-top,m.width);
49+
}
4650
}
4751
}
48-
if (drawExit&&i-top<maxY)
52+
if (drawExit&&i-top<maxY&&needRedraw(m,i))
4953
print(menu::exitOption,m.sel==m.sz,0,i-top,m.width);
54+
lastTop=top;
55+
lastSel=m.sel;
5056
drawn=&m;
5157
}
5258
};

menuLCDs.h

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Extensible: Yes
1010
implement menu output for Francisco Malpartida arduino LCD's
1111
1212
as VirtualPins is not yet a standard I implemented this to support existing libraries
13+
www.r-site.net
1314
***/
1415

1516
#ifndef RSITE_ARDUINOP_MENU_LCD
@@ -39,18 +40,21 @@ as VirtualPins is not yet a standard I implemented this to support existing libr
3940
println();
4041
}
4142
virtual void printMenu(menu& m,bool drawExit) {
42-
if (drawn==&m) return;
43-
clear();
4443
if (m.sel-top>=maxY) top=m.sel-maxY+1;//selected option outside device (bottom)
4544
else if (m.sel<top) top=m.sel;//selected option outside device (top)
46-
int i=0;for(;i<m.sz;i++) {
47-
if ((i>=top)&&((i-top)<maxY)) {
45+
if (drawn!=&m||top!=lastTop) clear();
46+
Serial<<"Printing menu "<<m.text<<endl;
47+
int i=top;for(;i<m.sz;i++) {
48+
//if ((i>=top)&&((i-top)<maxY)) {
4849
if(i-top>=maxY) break;
49-
print(*m.data[i],i==m.sel,i+1,i-top,m.width);
50-
}
50+
if (needRedraw(m,i))
51+
print(*m.data[i],i==m.sel,i+1,i-top,m.width);
52+
//}
5153
}
52-
if (drawExit&&i-top<maxY)
54+
if (drawExit&&i-top<maxY&&needRedraw(m,i))
5355
print(menu::exitOption,m.sel==m.sz,0,i-top,m.width);
56+
lastTop=top;
57+
lastSel=m.sel;
5458
drawn=&m;
5559
}
5660
};

menuPrint.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Thread Safe: No
88
Extensible: Yes
99
1010
menu output to Print device (ex: Serial)
11+
www.r-site.net
1112
***/
1213

1314
#ifndef RSITE_ARDUINOP_MENU_PRINT

0 commit comments

Comments
 (0)