Skip to content

Commit 5aafc42

Browse files
committed
missed menuLCDs.h
1 parent a0688da commit 5aafc42

File tree

4 files changed

+171
-1
lines changed

4 files changed

+171
-1
lines changed

Examples/I2C_menu/I2C_menu.ino

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#include <Wire.h>
2+
#include <LiquidCrystal_I2C.h>
3+
#include <menu.h>//menu macros and objects
4+
#include <menuLCDs.h>//F. Malpartida LCD's
5+
6+
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); // Set the LCD I2C address
7+
menuLCD menu_lcd(lcd,16,2);//menu output device
8+
9+
void nothing() {}
10+
11+
MENU(mainMenu,"Main",
12+
OP("Frequency",nothing),
13+
OP("Dutty",nothing),
14+
OP("Setup",nothing)
15+
);
16+
17+
void setup()
18+
{
19+
Serial.begin(9600);
20+
Wire.begin();
21+
lcd.begin(16,2);
22+
lcd.print("Ok");
23+
}
24+
25+
void loop()
26+
{
27+
//serial can use numbers or +/- and Enter to navigate
28+
mainMenu.activate(menu_lcd,Serial);
29+
}

keywords.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# Datatypes (KEYWORD1)
77
#####################################
88

9-
LiquidCrystal KEYWORD1
9+
#LiquidCrystal KEYWORD1
1010

1111
#####################################
1212
# Methods and Functions (KEYWORD2)
@@ -20,3 +20,4 @@ activate KEYWORD2
2020
# Constants (LITERAL1)
2121
#######################################
2222

23+

menuGFX.h

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
/********************
2+
Sept. 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+
Extendable: Yes
9+
10+
Use graphics screens (adafruit library based) as menu output
11+
***/
12+
#ifndef RSITE_ARDUINOP_MENU_GFX
13+
#define RSITE_ARDUINOP_MENU_GFX
14+
#include <Adafruit_GFX.h>
15+
#include "menu.h"
16+
17+
#define RGB565(r,g,b) ((((r>>3)<<11) | ((g>>2)<<5) | (b>>3)))
18+
19+
// Color definitions RGB565
20+
#define BLACK 0x0000
21+
#define BLUE 0x001F
22+
#define RED 0xF800
23+
#define GREEN 0x07E0
24+
#define GRAY RGB565(128,128,128)
25+
#define SILVER RGB565(200,200,200)
26+
#define CYAN 0x07FF
27+
#define MAGENTA 0xF81F
28+
#define YELLOW 0xFFE0
29+
#define WHITE 0xFFFF
30+
31+
class menuGFX:public menuOut {
32+
public:
33+
int lastTop;
34+
int lastSel;
35+
uint16_t bgColor;
36+
uint16_t enabledColor;
37+
uint16_t disabledColor;
38+
uint16_t hiliteColor;
39+
Adafruit_GFX& gfx;
40+
menuGFX(
41+
Adafruit_GFX& gfx,
42+
uint16_t hiliteColor=BLUE,
43+
uint16_t bgColor=BLACK,
44+
uint16_t enabledColor=WHITE,
45+
uint16_t disabledColor=SILVER,
46+
int resX=5,
47+
int resY=8
48+
)
49+
:gfx(gfx),
50+
bgColor(bgColor),
51+
enabledColor(enabledColor),
52+
disabledColor(disabledColor),
53+
hiliteColor(hiliteColor),
54+
menuOut(gfx.width()/resX,gfx.height()/resY,resX,resY) {}
55+
virtual void clear() {gfx.fillScreen(bgColor);gfx.setCursor(0,0);}
56+
virtual void setCursor(int x,int y) {gfx.setCursor(x*resX,y*resY);}
57+
virtual void print(char ch) {gfx.print(ch);}
58+
virtual void print(const char *text) {gfx.print(text);}
59+
virtual void println(const char *text) {gfx.println(text);};
60+
virtual void print(int i) {gfx.print(i);};
61+
virtual void println(int i) {gfx.println(i);};
62+
virtual void print(prompt &o,bool selected,int idx,int posY,int width) {
63+
gfx.fillRect(0,posY*resY,width*resX,resY,selected?hiliteColor:bgColor);
64+
gfx.setTextColor(o.enabled?enabledColor:disabledColor);
65+
gfx.setCursor(0,posY*resY);
66+
//gfx.setTextColor(o.enabled?enabledColor:disabledColor,selected?hiliteColor:bgColor);
67+
gfx.print(o.text);
68+
}
69+
virtual void printMenu(menu& m,bool drawExit) {
70+
if (drawn!=&m) clear();
71+
if (m.sel-top>=maxY) top=m.sel-maxY+1;//selected option outside device (bottom)
72+
else if (m.sel<top) top=m.sel;//selected option outside device (top)
73+
int i=0;for(;i<m.sz;i++) {
74+
if ((i>=top)&&((i-top)<maxY)) {
75+
if(i-top>=maxY) break;
76+
if ((top!=lastTop)||(i==m.sel)||(i==lastSel)||(drawn!=&m))
77+
print(*m.data[i],i==m.sel,i+1,i-top,m.width);
78+
}
79+
}
80+
if (drawExit&&i-top<maxY&&((top!=lastTop)||(i==m.sel)||(i==lastSel)||(drawn!=&m)))
81+
print(menu::exitOption,m.sel==m.sz,0,i-top,m.width);
82+
lastTop=top;
83+
lastSel=m.sel;
84+
drawn=&m;
85+
}
86+
};
87+
#endif RSITE_ARDUINOP_MENU_LCD
88+

menuLCDs.h

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/********************
2+
Sept. 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+
Extendable: Yes
9+
10+
implement menu output for Francisco Malpartida arduino LCD's
11+
12+
as VirtualPins is not yet a standard I implemented this to support existing libraries
13+
***/
14+
15+
#ifndef RSITE_ARDUINOP_MENU_LCD
16+
#define RSITE_ARDUINOP_MENU_LCD
17+
#include <LCD.h>
18+
#include "menu.h"
19+
20+
class menuLCD:public menuOut {
21+
public:
22+
LCD& lcd;
23+
//menuLCD(LiquidCrystal& lcd,int x=16,int y=1):lcd(lcd),menuOut(menuOut::cursor,x,y) {}
24+
menuLCD(LCD& lcd,int x=16,int y=1):lcd(lcd),menuOut(x,y) {}
25+
virtual void clear() {lcd.clear();}
26+
virtual void setCursor(int x,int y) {lcd.setCursor(x*resX,y*resY);}
27+
virtual void print(char ch) {lcd.print(ch);}
28+
virtual void print(const char *text) {lcd.print(text);}
29+
virtual void println(const char *text) {lcd.print(text);};
30+
virtual void print(int i) {lcd.print(i);};
31+
virtual void println(int i) {lcd.println(i);};
32+
virtual void print(prompt &o,bool selected,int idx,int posY,int width) {
33+
lcd.setCursor(0,posY);
34+
print(selected?(o.enabled?menu::enabledCursor:menu::disabledCursor):' ');
35+
print(o.text);
36+
}
37+
virtual void printMenu(menu& m,bool drawExit) {
38+
clear();
39+
if (m.sel-top>=maxY) top=m.sel-maxY+1;//selected option outside device (bottom)
40+
else if (m.sel<top) top=m.sel;//selected option outside device (top)
41+
int i=0;for(;i<m.sz;i++) {
42+
if ((i>=top)&&((i-top)<maxY)) {
43+
if(i-top>=maxY) break;
44+
print(*m.data[i],i==m.sel,i+1,i-top,m.width);
45+
}
46+
}
47+
if (drawExit&&i-top<maxY)
48+
print(menu::exitOption,m.sel==m.sz,0,i-top,m.width);
49+
}
50+
};
51+
#endif RSITE_ARDUINOP_MENU_LCD
52+

0 commit comments

Comments
 (0)