77#include " quadEncoder.h" // quadrature encoder driver and fake stream
88#include " keyStream.h" // keyboard driver and fake stream (for the encoder button)
99#include " chainStream.h" // concatenate multiple input streams (this allows adding a button to the encoder)
10- #include " menuLCD.h"
11- #include " menuPrint.h"
12- #include < Adafruit_GFX.h> // Co1re graphics library
13- #include < Adafruit_ST7735.h> // Hardware-specific library
14- #include < menuGFX.h>
15-
16- // /////////////////////////////////////////////////////////////////////////
17- // TFT + SD
18- // #define sdCS 4
19- #define tftCS 5
20- #define dc 6
21- #define rst 7 // you can also connect this to the Arduino reset
22-
23- Adafruit_ST7735 tft (tftCS, dc, rst);
24-
25- // #define LCD_SZ_X 16
26- // #define LCD_SZ_Y 2
10+ #include " menuPrint.h" // Print (Serial) menu
2711
2812#define LCDWIRE_NONE 0
2913#define LCDWIRE_VPINS_I2C 1
3014#define LCDWIRE_VPINS_SPI 2
3115#define LCDWIRE_I2C 3
3216#define LCDWIRE_DIRECT 4
3317
34- // how the LCS was wired
18+ // how the LCD is wired
3519// #define LCD_WIRE LCDWIRE_NONE
3620// #define LCD_WIRE LCDWIRE_VPINS_I2C
37- #define LCD_WIRE LCDWIRE_VPINS_SPI// not implemented
38- // #define LCD_WIRE LCDWIRE_I2C//not implemented
39- // #define LCD_WIRE LCDWIRE_DIRECT//not implemented
21+ #define LCD_WIRE LCDWIRE_VPINS_SPI// on shift registers thru vpins (same library)
22+ // #define LCD_WIRE LCDWIRE_I2C//not tested
23+ // #define LCD_WIRE LCDWIRE_DIRECT//not tested
24+
25+ #define USE_TFT YES// YES|NO
26+
27+ #if (USE_TFT == YES)
28+ #include < Adafruit_GFX.h> // Co1re graphics library
29+ #include < Adafruit_ST7735.h> // Hardware-specific library
30+ #include < menuGFX.h>
31+
32+ // /////////////////////////////////////////////////////////////////////////
33+ // TFT + SD
34+ // #define sdCS 4
35+ #define tftCS 5
36+ #define dc 6
37+ #define rst 7 // you can also connect this to the Arduino reset
38+
39+ Adafruit_ST7735 tft (tftCS, dc, rst);
40+ #endif
4041
42+ #define vpinsSPI_CS 9 // vpins SPI CS
4143#if (LCD_WIRE == LCDWIRE_VPINS_SPI)// LCD wired on shift registers using vpins
4244 #include < SPI.h>
4345 #include < VPinsSPI.h>
44- #define vpinsSPI_CS 9 // vpins SPI CS
46+ #include " menuLCD.h "
4547 #define STCP 9 // stcp or latch pin
4648
4749 #define RS 26
@@ -53,6 +55,7 @@ Adafruit_ST7735 tft(tftCS, dc, rst);
5355
5456#if (LCD_WIRE == LCDWIRE_VPINS_I2C)// LCD is wired over i2c to another AVR that uses virtual pins and shift registers to control it and virtual port server to share it
5557 #include < Wire.h>
58+ #include " menuLCD.h"
5659 // remote pins over I2C to VPort server
5760 #define vpinsSPI_CS srv_pb.pin(1 )// vpins SPI CS
5861 #define STCP srv_pb.pin(1 )// stcp or latch pin
@@ -117,6 +120,7 @@ MENU(mainMenu,"Sistema",
117120 OP(" Dutty" ,setDutty),
118121 OP(" Disabled" ,disabledTest),
119122 OP(" Handler test" ,completeHandlerTest),
123+ /* OP("Handler test",completeHandlerTest),
120124 OP("Handler test",completeHandlerTest),
121125 OP("Handler test",completeHandlerTest),
122126 OP("Handler test",completeHandlerTest),
@@ -126,8 +130,7 @@ MENU(mainMenu,"Sistema",
126130 OP("Handler test",completeHandlerTest),
127131 OP("Handler test",completeHandlerTest),
128132 OP("Handler test",completeHandlerTest),
129- OP(" Handler test" ,completeHandlerTest),
130- OP(" Handler test" ,completeHandlerTest),
133+ OP("Handler test",completeHandlerTest),*/
131134 SUBMENU(subMenu)
132135);
133136
@@ -137,7 +140,7 @@ quadEncoderStream enc(quadEncoder,5);// simple quad encoder fake Stream
137140
138141// a keyboard with only one key :D, this is the encoder button
139142keyMap encBtn_map[]={{-encBtn,13 }};// negative pin numbers means we have a pull-up, this is on when low
140- keyLook<2 > encButton (encBtn_map);
143+ keyLook<1 > encButton (encBtn_map);
141144
142145// multiple inputs allow conjugation of the quadEncoder with a single key keyboard that is the quadEncoder button
143146Stream* in[]={&enc,&encButton};
@@ -149,11 +152,16 @@ chainStream<3> allIn(in3);
149152
150153// describing a menu output, alternatives so far are Serial or LiquidCrystal LCD
151154menuPrint serial (Serial);
152- menuLCD lcd (lcd1,16 ,2 );
153- menuGFX gfx (tft);
155+ #if (LCD_WIRE!=LCDWIRE_NONE)
156+ menuLCD lcd (lcd1,16 ,2 );
157+ #endif
158+ #if (USE_TFT == YES)
159+ menuGFX gfx (tft);
160+ #endif
161+ menuPrint menuSerialOut (Serial);// describe output device
154162
155163// menuOut* out[]={&lcd,&serial};
156- // chainOut<2> allOut(out);
164+ // chainOut<2> allOut(out);//not implemented multiple outputs... useless i think
157165
158166// /////////////////////////////////////////////////////////////////////////////
159167
@@ -163,11 +171,15 @@ void setup() {
163171 Serial.begin (9600 );
164172 Serial.println (" menu system test" );
165173
174+ #if ((LCD_WIRE != LCDWIRE_NONE) || (USE_TFT == YES))
166175 pinMode (vpinsSPI_CS,OUTPUT);
167176 digitalWrite (vpinsSPI_CS,LOW);
177+ #endif
168178
169179#if (LCD_WIRE == LCDWIRE_VPINS_SPI)
170180 SPI.begin ();
181+ lcd1.begin (16 ,2 );
182+ lcd1.print (" Menu test" );
171183#endif
172184
173185#if (LCD_WIRE == LCDWIRE_VPINS_I2C)
@@ -176,11 +188,10 @@ void setup() {
176188 srv_vpa.begin ();// wait for server ready (all on same server, so)
177189 // srv_vpb.begin();// wait for server ready
178190 Serial.println (" all servers ready!" );
179- #endif
180191
181- lcd1.begin (16 ,2 );
182- lcd1.print (" Menu test" );
192+ #endif
183193
194+ #if (USE_TFT == YES)
184195 digitalWrite (vpinsSPI_CS,HIGH);
185196 digitalWrite (tftCS,HIGH);
186197 tft.initR (INITR_BLACKTAB);
@@ -191,17 +202,10 @@ void setup() {
191202 tft.fillScreen (ST7735_BLACK);
192203 tft.print (" Menu test on GFX" );
193204 tft.setCursor (0 ,10 );
194-
195- digitalWrite (vpinsSPI_CS,LOW);
196- digitalWrite (tftCS,LOW);
197- lcd1.setCursor (0 ,1 );
198- lcd1.print (mainMenu.width );
199- digitalWrite (vpinsSPI_CS,HIGH);
200- digitalWrite (tftCS,HIGH);
201-
202205 // update limits after screen rotation
203206 gfx.maxX =tft.width ()/gfx.resX ;
204207 gfx.maxY =tft.height ()/gfx.resY ;
208+ #endif
205209
206210 pinMode (encBtn, INPUT);
207211 digitalWrite (encBtn,1 );
@@ -212,14 +216,25 @@ void setup() {
212216// /////////////////////////////////////////////////////////////////////////////
213217// testing the menu system
214218void loop () {
215- gfx.clear ();
216- tft.print (" DEBUG" );
217- // mainMenu.activate(Serial,Serial);//show menu to Serial and read keys from Serial
218- // mainMenu.activate(lcd,allIn);//show menu on LCD and use multiple inputs to navigate (defined encoder, encoder button, serial)
219- mainMenu.activate (gfx,allIn);// show menu on LCD and use multiple inputs to navigate (defined encoder, encoder button, serial)
220- // mainMenu.activate(lcd1,allIn);//show menu on LCD and multiple inputs to navigate, defaults to LCD 16x1
221- // mainMenu.activate(lcd,Serial);//very bad combination!
222- // mainMenu.activate(Serial,enc);//bad combination! shopw menu on serial and navigate using quadEncoder
219+ // mainMenu.activate(menuSerialOut,Serial);//show menu to Serial and read keys from Serial
220+ // Serial.println("");
221+ // Serial.println("Restarting...");
222+
223+ #if (LCD_WIRE != LCDWIRE_NONE)
224+ // digitalWrite(vpinsSPI_CS,LOW);
225+ // digitalWrite(tftCS,LOW);
226+ // mainMenu.activate(lcd,allIn);//show menu on LCD and use multiple inputs to navigate (defined encoder, encoder button, serial)
227+ // mainMenu.activate(lcd1,allIn);//show menu on LCD and multiple inputs to navigate, defaults to LCD 16x1
228+ // mainMenu.activate(lcd,Serial);//very bad combination!
229+ // mainMenu.activate(Serial,enc);//bad combination! shopw menu on serial and navigate using quadEncoder
230+ #endif
231+
232+ #if (USE_TFT == YES)
233+ digitalWrite (vpinsSPI_CS,HIGH);
234+ digitalWrite (tftCS,HIGH);
235+ mainMenu.activate (gfx,allIn);// show menu on LCD and use multiple inputs to navigate (defined encoder, encoder button, serial)
236+ #endif
237+
223238}
224239
225240void nothing () {}
@@ -268,9 +283,9 @@ void setValue(prompt &p,menuOut &o, Stream &i,int &value,const char* text,const
268283 last=pos;
269284 }
270285 // func();
271- // }
286+ }
272287 delay (100 );
273288 while (encButton.read ()==13 );
274- }
289+ // }
275290}
276291
0 commit comments