Skip to content

Commit ca1422e

Browse files
committed
Added support for Francisco Malpartida LCD's
Added Creative commons msg
1 parent 8fed71c commit ca1422e

File tree

10 files changed

+198
-31
lines changed

10 files changed

+198
-31
lines changed

Examples/menu_test/menu_test.ino

Lines changed: 90 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
1+
/******************
2+
This is my development file... not a good example
3+
Rui Azevedo 2014
4+
ruihfazevedo@[email protected]
5+
********/
6+
17
#include <VPinsI2C.h>
28
#include <virtual_pins.h>
39
#include <HardwareSerial.h>
410
#include <LiquidCrystal.h>
5-
#include "pcint.h"//this is incompatible with software serial (arduino needs an handler!)
611
#include "menu.h"//menu macros and objects
12+
#include "pcint.h"//this is incompatible with software serial (arduino needs an handler!)
713
#include "quadEncoder.h"//quadrature encoder driver and fake stream
814
#include "keyStream.h"//keyboard driver and fake stream (for the encoder button)
915
#include "chainStream.h"// concatenate multiple input streams (this allows adding a button to the encoder)
@@ -16,13 +22,14 @@
1622
#define LCDWIRE_DIRECT 4
1723

1824
//how the LCD is wired
19-
#define LCD_WIRE LCDWIRE_NONE
25+
//#define LCD_WIRE LCDWIRE_NONE
2026
//#define LCD_WIRE LCDWIRE_VPINS_I2C
21-
//#define LCD_WIRE LCDWIRE_VPINS_SPI//on shift registers thru vpins (same library)
27+
#define LCD_WIRE LCDWIRE_VPINS_SPI//on shift registers thru vpins (same library)
2228
//#define LCD_WIRE LCDWIRE_I2C//not tested
2329
//#define LCD_WIRE LCDWIRE_DIRECT//not tested
2430

25-
#define USE_TFT 0//0|1
31+
#define USE_TFT 1//0|1
32+
#define tftCS 5
2633

2734
#if (USE_TFT == 1)
2835
#include <Adafruit_GFX.h> // Co1re graphics library
@@ -32,7 +39,6 @@
3239
///////////////////////////////////////////////////////////////////////////
3340
//TFT + SD
3441
//#define sdCS 4
35-
#define tftCS 5
3642
#define dc 6
3743
#define rst 7 // you can also connect this to the Arduino reset
3844

@@ -70,22 +76,34 @@
7076
LiquidCrystal lcd1(srv_vpa.pin(6), srv_vpa.pin(4), srv_vpa.pin(0), srv_vpa.pin(1), srv_vpa.pin(2), srv_vpa.pin(3));
7177
#endif
7278

79+
///////////////////////////////////////////////////////////////////////////////
80+
//set CS pins for LCD or TFT
81+
void selectLCD() {
82+
digitalWrite(vpinsSPI_CS,LOW);
83+
digitalWrite(tftCS,LOW);
84+
}
85+
86+
void selectTFT() {
87+
digitalWrite(vpinsSPI_CS,HIGH);
88+
digitalWrite(tftCS,HIGH);
89+
}
90+
7391
////////////////////////////////////////////
7492
// ENCODER (aka rotary switch) PINS
7593
// rotary
7694
#define encA 2
7795
#define encB 4
7896
//this encoder has a button here
7997
#define encBtn A0
80-
#define LEDPIN 13//on uno use pin 13
98+
#define LEDPIN A3//on uno use pin 13
8199

82100
///////////////////////////////////////////////////////////////////////////
83101
//functions to wire as menu actions
84102

85103
//aux function
86104
void nothing() {}
87105

88-
void setValue(prompt &p,menuOut &o, Stream &i,int &value,const char* text,const char* units="",int sensivity=5,int low=0,int hi=100,int steps=0,void (*func)()=nothing);
106+
void setValue(int &value,prompt &p,menuOut &o, Stream &i,const char* text,const char* units="",int sensivity=5,int low=0,int hi=100,int steps=0,void (*func)()=nothing);
89107

90108
void ledOn() {digitalWrite(LEDPIN,1);}
91109
void ledOff() {digitalWrite(LEDPIN,0);}
@@ -97,10 +115,10 @@ void disabledTest(prompt &p,menuOut &o,Stream &i) {
97115
}
98116

99117
int frequency=100;
100-
void setFreq(prompt &p,menuOut &o,Stream &i) {setValue(p,o,i,frequency,"Freq:","0 Hz",20,1,1000);}
118+
void setFreq(prompt &p,menuOut &o,Stream &i) {setValue(frequency,p,o,i,"Freq:","0 Hz",20,1,1000);}
101119

102120
int dutty=50;
103-
void setDutty(prompt &p,menuOut &o,Stream &i) {setValue(p,o,i,dutty,"Dutty:","%",1,0,100);}
121+
void setDutty(prompt &p,menuOut &o,Stream &i) {setValue(dutty,p,o,i,"Dutty:","%",1,0,100);}
104122

105123
void completeHandlerTest(prompt &p,menuOut &o,Stream &i) {
106124
o.clear();
@@ -109,6 +127,10 @@ void completeHandlerTest(prompt &p,menuOut &o,Stream &i) {
109127
while(i.read()!=13);
110128
}
111129

130+
int stv=8;
131+
void scrollUp_test(prompt &p,menuOut &o,Stream &i);
132+
void scrollDown_test(prompt &p,menuOut &o,Stream &i);
133+
112134
/////////////////////////////////////////////////////////////////////////
113135
// MENU DEFINITION
114136
// here we define the menu structure and wire actions functions to it
@@ -120,9 +142,10 @@ MENU(subMenu,"LED ON/OFF",
120142
MENU(mainMenu,"Sistema",
121143
OP("Frequency",setFreq),
122144
OP("Dutty",setDutty),
145+
OP("Scroll up", scrollUp_test),
146+
OP("scroll down", scrollDown_test),
123147
OP("Disabled",disabledTest),
124148
OP("Handler test",completeHandlerTest),
125-
/*OP("Handler test",completeHandlerTest),
126149
OP("Handler test",completeHandlerTest),
127150
OP("Handler test",completeHandlerTest),
128151
OP("Handler test",completeHandlerTest),
@@ -132,10 +155,52 @@ MENU(mainMenu,"Sistema",
132155
OP("Handler test",completeHandlerTest),
133156
OP("Handler test",completeHandlerTest),
134157
OP("Handler test",completeHandlerTest),
135-
OP("Handler test",completeHandlerTest),*/
136158
SUBMENU(subMenu)
137159
);
138160

161+
//more menu functions that need the menu defs
162+
/*int scrollY(menuOut& o,int pixels) {
163+
tft.print(pixels);tft.println(" px");
164+
int lines=pixels/o.resY;//convert pixels to lines
165+
tft.print(lines);tft.println(" lines");
166+
tft.print(o.top);tft.println(" top");
167+
o.top+=lines;
168+
mainMenu.clampY(o);
169+
tft.print(o.top);tft.println(" clamped top");
170+
if (mainMenu.sel<o.top) mainMenu.sel=o.top;
171+
else if (mainMenu.sel>=(o.top+o.maxY)) mainMenu.sel=o.top+o.maxY-1;
172+
//menu needs to be redrawn after this
173+
return pixels-lines*o.resY;
174+
}*/
175+
176+
void scrollUp_test(prompt &p,menuOut &o,Stream &i) {
177+
setValue(stv,p,o,i,"dist:"," Pixels",1,0,16);
178+
/*selectTFT();
179+
tft.fillScreen(BLACK);tft.setCursor(0,0);
180+
int ot=o.top;
181+
int os=mainMenu.sel;*/
182+
int remain=mainMenu.scrollY(o,-stv);//assuming its main menu
183+
/*tft.print("top: ");tft.print(ot);tft.print(" sel: ");tft.println(os);
184+
tft.print("scroll ");tft.print(stv);tft.print(" remain:");tft.println(remain);
185+
tft.print("top: ");tft.print(o.top);tft.print(" sel: ");tft.println(mainMenu.sel);
186+
selectLCD();*/
187+
mainMenu.printMenu(o, false);
188+
}
189+
190+
void scrollDown_test(prompt &p,menuOut &o,Stream &i) {
191+
setValue(stv,p,o,i,"dist:"," Pixels",1,0,16);
192+
//selectTFT();
193+
//tft.fillScreen(BLACK);tft.setCursor(0,0);
194+
//int ot=o.top;
195+
//int os=mainMenu.sel;
196+
int remain=mainMenu.scrollY(o,stv);//assuming its main menu
197+
/*tft.print("top: ");tft.print(ot);tft.print(" sel: ");tft.println(os);
198+
tft.print("scroll ");tft.print(stv);tft.print(" remain:");tft.println(remain);
199+
tft.print("top: ");tft.print(o.top);tft.print(" sel: ");tft.println(mainMenu.sel);
200+
selectLCD();*/
201+
mainMenu.printMenu(o, false);
202+
}
203+
139204
//the quadEncoder
140205
quadEncoder quadEncoder(encA,encB);//simple quad encoder driver
141206
quadEncoderStream enc(quadEncoder,5);// simple quad encoder fake Stream
@@ -163,10 +228,9 @@ menuPrint serial(Serial);
163228
#endif
164229
menuPrint menuSerialOut(Serial);//describe output device
165230

166-
///////////////////////////////////////////////////////////////////////////////
167-
231+
/////////////////////////////////////////////////////////////////////////
168232
void setup() {
169-
mainMenu.data[2]->enabled=false;//disabling option
233+
mainMenu.data[4]->enabled=false;//disabling option
170234

171235
Serial.begin(9600);
172236
Serial.println("menu system test");
@@ -198,7 +262,9 @@ void setup() {
198262
tft.setRotation(3);
199263
tft.setTextWrap(false);
200264
tft.setTextColor(ST7735_RED);
201-
tft.setTextSize(1);
265+
tft.setTextSize(2);
266+
gfx.resX*=2;//update resolution after font size change
267+
gfx.resY*=2;//update resolution after font size change
202268
tft.fillScreen(ST7735_BLACK);
203269
tft.print("Menu test on GFX");
204270
tft.setCursor(0,10);
@@ -211,14 +277,16 @@ void setup() {
211277
digitalWrite(encBtn,1);
212278

213279
pinMode(LEDPIN,OUTPUT);
280+
281+
delay(300);
214282
}
215283

216284
///////////////////////////////////////////////////////////////////////////////
217285
// testing the menu system
218286
void loop() {
219-
mainMenu.activate(menuSerialOut,Serial);//show menu to Serial and read keys from Serial
220-
Serial.println("");
221-
Serial.println("Restarting...");
287+
//mainMenu.activate(menuSerialOut,Serial);//show menu to Serial and read keys from Serial
288+
//Serial.println("");
289+
//Serial.println("Restarting...");
222290

223291
#if (LCD_WIRE != LCDWIRE_NONE)
224292
//digitalWrite(vpinsSPI_CS,LOW);
@@ -228,9 +296,9 @@ void loop() {
228296
#endif
229297

230298
#if (USE_TFT == 1)
231-
//digitalWrite(vpinsSPI_CS,HIGH);
232-
//digitalWrite(tftCS,HIGH);
233-
//mainMenu.activate(gfx,allIn);//show menu on LCD and use multiple inputs to navigate (defined encoder, encoder button, serial)
299+
digitalWrite(vpinsSPI_CS,HIGH);
300+
digitalWrite(tftCS,HIGH);
301+
mainMenu.activate(gfx,allIn);//show menu on LCD and use multiple inputs to navigate (defined encoder, encoder button, serial)
234302
#endif
235303

236304
}
@@ -242,7 +310,7 @@ void percentBar(menuOut &o,int percent) {
242310
}
243311

244312
//read a value from the input stream device (encoder or serial)
245-
void setValue(prompt &p,menuOut &o, Stream &i,int &value,const char* text,const char* units,int sensivity,int low,int hi,int steps,void (*func)()) {
313+
void setValue(int &value,prompt &p,menuOut &o, Stream &i,const char* text,const char* units,int sensivity,int low,int hi,int steps,void (*func)()) {
246314
o.clear();
247315
int at=strlen(text);//.length();
248316
o.setCursor(0,0);

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,5 @@ input is read from generic streams, included simple streams for encoders and key
2525
output to menuOut devices, included derivations to support serial, GFX and lcd
2626

2727
multiple stream packing for input allowing mixing encoder stream with encoder keyboard (usually 1 or 2 keys)
28+
29+
more info at http://r-site.net?lang=en&at=//op%5B@id=%273090%27%5D

chainStream.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
11
/***********
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+
210
scan a chain of several input streams to provide input
3-
Rui Azevedo - ruihfazevedo(@rrob@)gmail.com
4-
*/
11+
***/
12+
513

614
template <int N>
715
class chainStream:public Stream {

keyStream.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,19 @@
11
/**************
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+
210
quick and dirty keyboard driver
311
metaprog keyboard driver where N is the number of keys
412
all keys are expected to be a pin (buttons)
513
we can have reverse logic (pull-ups) by entering negative pin numbers
614
ex: -A0 means: pin A0 normally high, low when button pushed (reverse logic)
7-
Rui Azevedo - ruihfazevedo(@rrob@)gmail.com
8-
*/
15+
***/
16+
917
struct keyMap {
1018
int8_t pin;
1119
int8_t code;

menu.cpp

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
/********************
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+
210
Arduino generic menu system
3-
Rui Azevedo - ruihfazevedo(@rrob@)gmail.com
411
*/
512
#include <Arduino.h>
613
#include "menu.h"
@@ -60,3 +67,29 @@ void menu::activate(menuOut& p,Stream& c,bool canExit) {
6067
} while(op!=-1);
6168
}
6269

70+
void menu::clampY(menuOut& o) {//keep menu inside screen Y
71+
if (o.top+o.maxY>sz) o.top=sz-o.maxY;
72+
else if (o.top<0) o.top=0;
73+
}
74+
75+
//we scroll by lines, return remaining pixels
76+
int menu::scrollY(menuOut& o,int pixels) {
77+
if (o.top==0&&sz<=o.maxY) return pixels;//menu is inside screen, no need to scroll
78+
int lines=pixels/o.resY;//convert pixels to lines
79+
o.top+=lines;
80+
clampY(o);
81+
if (sel<o.top) sel=o.top;
82+
else if (sel>=(o.top+o.maxY)) sel=o.top+o.maxY-1;
83+
//menu needs to be redrawn after this
84+
return pixels-lines*o.resY;
85+
}
86+
87+
void menu::click(menuOut &p, Stream &c,int x,int y) {
88+
int row=y/p.resY;
89+
int col=x/p.resX;
90+
if (row<p.maxY&&row>=0&&col>=0&&col<p.maxX&&(p.top+row)<sz)
91+
data[p.top+row]->activate(p,c,true);
92+
}
93+
94+
95+

menu.h

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
/********************
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+
210
Arduino generic menu system
3-
Rui Azevedo - ruihfazevedo(@rrob@)gmail.com
411
512
prompt: class representing a text and an associated function pointer
613
menu: prompt derived holding a list of prompts (options and submenus)
@@ -169,13 +176,18 @@ for encoders, joysticks, keyboards or touch a stream must be made out of them
169176
static prompt exitOption;//option tro append to every menu allowing exit when no escape button/key is available
170177
const int sz;
171178
int sel;//selection
172-
prompt* const* data;
179+
prompt* const* data PROGMEM;
173180
menu(const char * text,int sz,prompt* const data[]):prompt(text),sz(sz),data(data),sel(0),width(16) {}
174181

175182
int menuKeys(menuOut &p,Stream& c,bool drawExit);
176183
inline void printMenu(menuOut& p,bool drawExit) {p.printMenu(*this,drawExit);}
177184

178185
void activate(menuOut& p,Stream& c,bool canExit=false);
186+
187+
//some funcs to support touch... TODO: test them
188+
void clampY(menuOut& o);//keep menu inside secreen
189+
int scrollY(menuOut& o,int pixels);//aux function for touch screen
190+
void click(menuOut &p, Stream &c,int x,int y);
179191
};
180192

181193
#endif

menuLCD.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
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 standard arduino LCD (LiquidCrystal library) as menu output
11+
***/
12+
113
#ifndef RSITE_ARDUINOP_MENU_LCD
214
#define RSITE_ARDUINOP_MENU_LCD
315
#include <LiquidCrystal.h>

menuPrint.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
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+
menu output to Print device (ex: Serial)
11+
***/
12+
113
#ifndef RSITE_ARDUINOP_MENU_PRINT
214
#define RSITE_ARDUINOP_MENU_PRINT
315
//#include <HardwareSerial.h>

0 commit comments

Comments
 (0)