Skip to content

Commit d0e2c1e

Browse files
committed
ok
2 parents 81e0d23 + 35314a5 commit d0e2c1e

File tree

5 files changed

+304
-107
lines changed

5 files changed

+304
-107
lines changed

examples/gfx_menu/gfx_menu.ino

Lines changed: 53 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ ruihfazevedo@[email protected]
3333
#include <Adafruit_GFX.h> // Core graphics library
3434
#include <Adafruit_ST7735.h> // Hardware-specific library
3535
#include <menuGFX.h>
36+
#include <menuFields.h>
3637

3738

3839
#if defined(__AVR_ATmega2560__)
@@ -51,27 +52,40 @@ ruihfazevedo@[email protected]
5152
#define LEDPIN A3
5253
///////////////////////////////////////////////////////////////////////////
5354
//TFT + SD
54-
#define TFT_DC A0
55-
#define TFT_CS A1
56-
#define TFT_RST A2
55+
//TFT + SD
56+
//#define sdCS 9//not using SD card
57+
#define tftCS A1
58+
#define dc A0
59+
#define rst A2
5760
////////////////////////////////////////////
5861
// ENCODER (aka rotary switch) PINS
59-
#define encA 2
60-
#define encB 3
61-
#define encBtn 4
62+
#define encA 2
63+
#define encB 3
64+
#define encBtn 4
6265
#else
6366
#error "Uknown pinout"
6467
#endif
6568

66-
Adafruit_ST7735 tft(TFT_CS, TFT_DC, TFT_RST);
69+
Adafruit_ST7735 tft(tftCS, dc, rst);
70+
71+
//wire led here because default led is already used by hardware SPI
72+
#define LEDPIN A3
6773

6874
//aux vars
6975
int ledCtrl=0;
76+
bool runMenu=false;
77+
bool scrSaverEnter=true;
7078
int percent;//just testing changing this var
79+
double fps=0;
80+
unsigned long lastFpsChk=0;
7181
int counter=0;
7282

7383
///////////////////////////////////////////////////////////////////////////
7484
//functions to wire as menu actions
85+
bool pauseMenu() {
86+
runMenu=false;
87+
scrSaverEnter=true;
88+
}
7589
bool ledOn() {
7690
Serial.println("set led on!");
7791
digitalWrite(LEDPIN,ledCtrl=1);
@@ -136,9 +150,23 @@ MENU(mainMenu,"Main menu",
136150
SUBMENU(selMenu),
137151
SUBMENU(chooseMenu),
138152
SUBMENU(subMenu),
139-
FIELD(percent,"Percent","%",0,100,10,1)
153+
FIELD(percent,"Percent","%",0,100,10,1),
154+
FIELD(fps,"fps [","]",0,0,0,0),
155+
FIELD(counter,"counter [","]",0,0,0,0),
156+
OP("Exit",pauseMenu)
140157
);
141158

159+
void scrSaver() {
160+
if (scrSaverEnter) {
161+
tft.fillScreen(ST7735_BLACK);
162+
tft.print("|www.r-site.net|");
163+
tft.setCursor(0,1);
164+
tft.print("|click to enter|");
165+
scrSaverEnter=false;
166+
}
167+
}
168+
169+
142170
//the quadEncoder
143171
quadEncoder encoder(encA,encB);//simple quad encoder driver
144172
quadEncoderStream enc(encoder,5);// simple quad encoder fake Stream
@@ -152,7 +180,7 @@ Stream* in[]={&enc,&encButton};
152180
chainStream<2> quadEncoder_button(in);
153181

154182
//alternative to previous but now we can input from Serial too...
155-
Stream* in3[]={&enc,&encButton};
183+
Stream* in3[]={&enc,&encButton,&Serial};
156184
chainStream<3> allIn(in3);
157185

158186
//describing a menu output, alternatives so far are Serial or LiquidCrystal LCD
@@ -166,16 +194,16 @@ void setup() {
166194
tft.setRotation(3);
167195
tft.setTextWrap(false);
168196
tft.setTextColor(ST7735_RED,ST7735_BLACK);
169-
//tft.setTextSize(2);
170-
//gfx.resX*=2;//update resolution after font size change
171-
//gfx.resY*=2;//update resolution after font size change
197+
tft.setTextSize(1);
198+
gfx.resX*=1;//update resolution after font size change
199+
gfx.resY*=1;//update resolution after font size change
172200
tft.fillScreen(ST7735_BLACK);
173201
tft.print("Menu test on GFX");
174202
//testing menu limits (not using all the screen)
175203
//size is within screen limits even after rotation
176204
//this limits are not constrained, please ensure your text fits
177205
gfx.maxX=16;
178-
gfx.maxY=5;
206+
gfx.maxY=10;
179207
gfx.bgColor=SILVER;
180208
pinMode(encBtn, INPUT_PULLUP);
181209
encoder.begin();
@@ -184,6 +212,16 @@ void setup() {
184212
///////////////////////////////////////////////////////////////////////////////
185213
// testing the menu system
186214
void loop() {
187-
mainMenu.poll(gfx,allIn);
188-
digitalWrite(LEDPIN, ledCtrl);
215+
if (runMenu) mainMenu.poll(gfx,allIn);
216+
else if (allIn.read()==menu::enterCode) runMenu=true;
217+
else scrSaver();
218+
//simulate the delay of your program... if this number rises too much the menu will have bad navigation experience
219+
//if so, then the menu can be wired into a timmer... leaving the shorter end to your code while it is running
220+
counter=millis()/1000%60;
221+
int d=micros()-lastFpsChk;
222+
if (d>0) {
223+
fps=1000000.0/d;
224+
lastFpsChk+=d;
225+
}
226+
delay(50);
189227
}

src/menu.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,15 @@ v2.1 - Add full support of SetPosition(x,y) to move the menu inside the screen (
130130
virtual void printValue(menuOut& p) {}
131131
virtual void printUnit(menuOut& p) {}
132132
virtual void printTo(menuOut& p) {
133+
<<<<<<< HEAD
133134
printName(p);
134135
printValue(p);
135136
printUnit(p);
137+
=======
138+
printName(p);
139+
printValue(p);
140+
printUnit(p);
141+
>>>>>>> valuecolor
136142
}
137143
virtual bool needRedraw(menuOut&,bool) {return false;}
138144
virtual promptFeedback activate(menuOut& p,Stream&c,bool) {

0 commit comments

Comments
 (0)