1+ /* *****************
2+ This is my development file... not a good example
3+ Rui Azevedo 2014
4+ 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)
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
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
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
86104void 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
90108void ledOn () {digitalWrite (LEDPIN,1 );}
91109void ledOff () {digitalWrite (LEDPIN,0 );}
@@ -97,10 +115,10 @@ void disabledTest(prompt &p,menuOut &o,Stream &i) {
97115}
98116
99117int 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
102120int 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
105123void 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",
120142MENU (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
140205quadEncoder quadEncoder (encA,encB);// simple quad encoder driver
141206quadEncoderStream enc (quadEncoder,5 );// simple quad encoder fake Stream
@@ -163,10 +228,9 @@ menuPrint serial(Serial);
163228#endif
164229menuPrint menuSerialOut (Serial);// describe output device
165230
166- // /////////////////////////////////////////////////////////////////////////////
167-
231+ // ///////////////////////////////////////////////////////////////////////
168232void 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
218286void 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 );
0 commit comments