@@ -22,8 +22,8 @@ on this example only using
2222
2323#include < Arduino.h>
2424#include < menu.h>
25- #include < menuIO/serialIn .h>
26- #include < menuIO/serialOut .h>
25+ #include < menuIO/serialIO .h>
26+ #include < menuIO/stringIn .h>
2727#include < menuIO/chainStream.h>
2828
2929using namespace Menu ;
@@ -131,7 +131,12 @@ MENU_OUTPUTS(out,MAX_DEPTH
131131 ,NONE// must have 2 items at least
132132);
133133
134+ stringIn<0 > strIn;// buffer size: 2^5 = 32 bytes, eventually use 0 for a single byte
134135serialIn serial (Serial);
136+ // use this commented lines if you want your stringIn object to be used as part or normal menu input
137+ // menuIn* inputsList[]={&serial,&strIn};
138+ // chainStream<sizeof(inputsList)> in(inputsList);
139+ // NAVROOT(nav,mainMenu,MAX_DEPTH,in,out);
135140NAVROOT (nav,mainMenu,MAX_DEPTH,serial,out);
136141
137142result alert (menuOut& o,idleEvent e) {
@@ -155,6 +160,7 @@ void setup() {
155160 pinMode (LEDPIN, OUTPUT);
156161 pinMode (NAV_BTN,INPUT_PULLUP);
157162 pinMode (SEL_BTN,INPUT_PULLUP);
163+ Serial.println (" menu 4.x" );
158164}
159165
160166#define SOFT_DEBOUNCE_MS 100
@@ -172,9 +178,17 @@ void loop() {
172178 nav.doNav (upCmd);
173179 delay (SOFT_DEBOUNCE_MS);
174180 }
175- nav.poll ();// also do serial input
176- // or deal with charater input directly
177- // if (Serial.available()) nav.active().parseInput(nav.node(),Serial.read());
178- // nav.doOutput();
181+ // if stringIn is a regular input then we should write to it here, before poll
182+ // strIn.write(...);//just put the character you want to send
183+ // nav.poll();//also do serial or stringIn input
184+ // or deal with charater input directly... (if you have your own input driver)
185+ if (Serial.available ()) {
186+ // of course menu can read from Serial or even stringIn (se above how to use stringIn as a regular menu input)
187+ // but here we demonstrate the use of stringIn in direct call, by writing the data to stream and then call parseInput
188+ if (strIn.write (Serial.read ()))// so we just transfer data from serial to strIn
189+ // nav.active().parseInput(nav.node(),strIn);//and then let target parse input
190+ nav.doInput (strIn);
191+ }
192+ nav.doOutput ();// if not doing poll the we need to do output "manualy"
179193 digitalWrite (LEDPIN, ledCtrl);
180194}
0 commit comments