Skip to content

Commit 027a298

Browse files
committed
events inpection example
1 parent 456743f commit 027a298

File tree

6 files changed

+253
-4
lines changed

6 files changed

+253
-4
lines changed
+211
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,211 @@
1+
/********************
2+
Arduino generic menu system
3+
printing events and navigation info
4+
5+
Rui Azevedo - ruihfazevedo(@rrob@)gmail.com
6+
7+
output: Serial
8+
input: Serial
9+
*/
10+
11+
#include <menu.h>
12+
#include <menuIO/serialOut.h>
13+
#include <menuIO/serialIn.h>
14+
15+
using namespace Menu;
16+
17+
#define LEDPIN LED_BUILTIN
18+
19+
void showPath(navRoot& root) {
20+
Serial.print("nav level:");
21+
Serial.print(root.level);
22+
Serial.print(" path:[");
23+
for(int n=0;n<=root.level;n++) {
24+
Serial.print(n?",":"");
25+
Serial.print(root.path[n].sel);
26+
}
27+
Serial.println("]");
28+
}
29+
30+
result showEvent(eventMask e,navNode& nav,prompt& item) {
31+
Serial.println();
32+
Serial.println("========");
33+
Serial.print("Event for target: 0x");
34+
Serial.println((long)nav.target,HEX);
35+
showPath(*nav.root);
36+
Serial.print(e);
37+
switch(e) {
38+
case noEvent://just ignore all stuff
39+
Serial.println(" noEvent");break;
40+
case activateEvent://this item is about to be active (system event)
41+
Serial.println(" activateEvent");break;
42+
case enterEvent://entering navigation level (this menu is now active)
43+
Serial.println(" enterEvent");break;
44+
case exitEvent://leaving navigation level
45+
Serial.println(" exitEvent");break;
46+
case returnEvent://TODO:entering previous level (return)
47+
Serial.println(" returnEvent");break;
48+
case focusEvent://element just gained focus
49+
Serial.println(" focusEvent");break;
50+
case blurEvent://element about to lose focus
51+
Serial.println(" blurEvent");break;
52+
case selFocusEvent://TODO:child just gained focus
53+
Serial.println(" selFocusEvent");break;
54+
case selBlurEvent://TODO:child about to lose focus
55+
Serial.println(" selBlurEvent");break;
56+
case updateEvent://Field value has been updated
57+
Serial.println(" updateEvent");break;
58+
case anyEvent:
59+
Serial.println(" anyEvent");break;
60+
}
61+
return proceed;
62+
}
63+
64+
float test=55;
65+
66+
int ledCtrl=LOW;
67+
68+
result myLedOn() {
69+
ledCtrl=HIGH;
70+
return proceed;
71+
}
72+
result myLedOff() {
73+
ledCtrl=LOW;
74+
return proceed;
75+
}
76+
77+
TOGGLE(ledCtrl,setLed,"Led: ",showEvent,anyEvent,noStyle//,doExit,enterEvent,noStyle
78+
,VALUE("On",HIGH,showEvent,anyEvent)
79+
,VALUE("Off",LOW,showEvent,anyEvent)
80+
);
81+
82+
int selTest=0;
83+
SELECT(selTest,selMenu,"Select",showEvent,anyEvent,noStyle
84+
,VALUE("Zero",0,showEvent,anyEvent)
85+
,VALUE("One",1,showEvent,anyEvent)
86+
,VALUE("Two",2,showEvent,anyEvent)
87+
);
88+
89+
int chooseTest=-1;
90+
CHOOSE(chooseTest,chooseMenu,"Choose",showEvent,anyEvent,noStyle
91+
,VALUE("First",1,showEvent,anyEvent)
92+
,VALUE("Second",2,showEvent,anyEvent)
93+
,VALUE("Third",3,showEvent,anyEvent)
94+
,VALUE("Last",-1,showEvent,anyEvent)
95+
);
96+
97+
//customizing a prompt look!
98+
//by extending the prompt class
99+
class altPrompt:public prompt {
100+
public:
101+
// altPrompt(constMEM promptShadow& p):prompt(p) {}
102+
using prompt::prompt;
103+
Used printTo(navRoot &root,bool sel,menuOut& out, idx_t idx,idx_t len,idx_t) override {
104+
return out.printRaw(F("special prompt!"),len);
105+
}
106+
};
107+
108+
MENU(subMenu,"Sub-Menu",showEvent,anyEvent,noStyle
109+
,OP("Sub1",showEvent,anyEvent)
110+
,OP("Sub2",showEvent,anyEvent)
111+
,OP("Sub3",showEvent,anyEvent)
112+
,altOP(altPrompt,"",showEvent,anyEvent)
113+
,EXIT("<Back")
114+
);
115+
116+
uint16_t year=2017;
117+
uint16_t month=10;
118+
uint16_t day=7;
119+
120+
//define a pad style menu (single line menu)
121+
//here with a set of fields to enter a date in YYYY/MM/DD format
122+
//altMENU(menu,birthDate,"Birth",showEvent,anyEvent,noStyle,(systemStyles)(_asPad|Menu::_menuData|Menu::_canNav|_parentDraw)
123+
PADMENU(birthDate,"Birth",showEvent,anyEvent,noStyle
124+
,FIELD(year,"","/",1900,3000,20,1,showEvent,anyEvent,noStyle)
125+
,FIELD(month,"","/",1,12,1,0,showEvent,anyEvent,wrapStyle)
126+
,FIELD(day,"","",1,31,1,0,showEvent,anyEvent,wrapStyle)
127+
);
128+
129+
char* constMEM hexDigit MEMMODE="0123456789ABCDEF";
130+
char* constMEM hexNr[] MEMMODE={"0","x",hexDigit,hexDigit};
131+
char buf1[]="0x11";
132+
133+
char* constMEM alphaNum MEMMODE=" 0123456789.ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz,\\|!\"#$%&/()=?~*^+-{}[]€";
134+
char* constMEM alphaNumMask[] MEMMODE={alphaNum};
135+
char name[]=" ";
136+
137+
MENU(mainMenu,"Main menu",showEvent,anyEvent,wrapStyle
138+
,OP("Op1",showEvent,anyEvent)
139+
,OP("Op2",showEvent,anyEvent)
140+
,FIELD(test,"Test","%",0,100,10,1,showEvent,anyEvent,wrapStyle)
141+
,SUBMENU(subMenu)
142+
,SUBMENU(setLed)
143+
,OP("LED On",myLedOn,enterEvent)
144+
,OP("LED Off",myLedOff,enterEvent)
145+
,SUBMENU(selMenu)
146+
,SUBMENU(chooseMenu)
147+
,OP("Alert test",doAlert,enterEvent)
148+
,EDIT("Name",name,alphaNumMask,showEvent,anyEvent,noStyle)
149+
,EDIT("Hex",buf1,hexNr,showEvent,anyEvent,noStyle)
150+
,SUBMENU(birthDate)
151+
,EXIT("<Back")
152+
);
153+
154+
#define MAX_DEPTH 2
155+
156+
MENU_OUTPUTS(out,MAX_DEPTH
157+
,SERIAL_OUT(Serial)
158+
,NONE//must have 2 items at least
159+
);
160+
161+
serialIn serial(Serial);
162+
NAVROOT(nav,mainMenu,MAX_DEPTH,serial,out);
163+
164+
result alert(menuOut& o,idleEvent e) {
165+
if (e==idling) {
166+
o.setCursor(0,0);
167+
o.print("alert test");
168+
o.setCursor(0,1);
169+
o.print("press [select]");
170+
o.setCursor(0,2);
171+
o.print("to continue...");
172+
}
173+
return proceed;
174+
}
175+
176+
result doAlert(eventMask e, prompt &item) {
177+
nav.idleOn(alert);
178+
return proceed;
179+
}
180+
181+
result idle(menuOut &o, idleEvent e) {
182+
// o.clear();
183+
switch(e) {
184+
case idleStart:o.println("suspending menu!");break;
185+
case idling:o.println("suspended...");break;
186+
case idleEnd:o.println("resuming menu.");
187+
nav.reset();
188+
break;
189+
}
190+
return proceed;
191+
}
192+
193+
void setup() {
194+
pinMode(LEDPIN,OUTPUT);
195+
digitalWrite(LEDPIN,ledCtrl);
196+
delay(500);
197+
Serial.begin(115200);
198+
while(!Serial);
199+
Serial.println("menu 4.x test");Serial.flush();
200+
nav.timeOut=120;
201+
nav.idleTask=idle;//point a function to be used when menu is suspended
202+
// nav.idleOn();//this menu will start on idle state, press select to enter menu
203+
//nav.doInput("323");
204+
// nav.useAccel=false;
205+
}
206+
207+
void loop() {
208+
nav.poll();
209+
digitalWrite(LEDPIN, ledCtrl);
210+
delay(100);//simulate a delay when other tasks are done
211+
}

examples/handlers/include/README

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
2+
This directory is intended for project header files.
3+
4+
A header file is a file containing C declarations and macro definitions
5+
to be shared between several project source files. You request the use of a
6+
header file in your project source file (C, C++, etc) located in `src` folder
7+
by including it, with the C preprocessing directive `#include'.
8+
9+
```src/main.c
10+
11+
#include "header.h"
12+
13+
int main (void)
14+
{
15+
...
16+
}
17+
```
18+
19+
Including a header file produces the same results as copying the header file
20+
into each source file that needs it. Such copying would be time-consuming
21+
and error-prone. With a header file, the related declarations appear
22+
in only one place. If they need to be changed, they can be changed in one
23+
place, and programs that include the header file will automatically use the
24+
new version when next recompiled. The header file eliminates the labor of
25+
finding and changing all the copies as well as the risk that a failure to
26+
find one copy will result in inconsistencies within a program.
27+
28+
In C, the usual convention is to give header files names that end with `.h'.
29+
It is most portable to use only letters, digits, dashes, and underscores in
30+
header file names, and at most one dot.
31+
32+
Read more about using header files in official GCC documentation:
33+
34+
* Include Syntax
35+
* Include Operation
36+
* Once-Only Headers
37+
* Computed Includes
38+
39+
https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html
File renamed without changes.

library.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=ArduinoMenu library
2-
version=4.18.2
2+
version=4.18.3
33
author=Rui Azevedo, [email protected]
44
maintainer=neu-rah, [email protected]
55
sentence=Generic menu/interactivity system

src/menuIO/OzOledAsciiOut.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
OzOLED* device;
1818
inline OzOledAsciiOut(OzOLED* o,idx_t *t,panelsList &p,menuOut::styles s=menuOut::minimalRedraw)
1919
:menuOut(t,p,s),device(o) {}
20-
size_t write(uint8_t ch) override { device->printChar(ch); return 1;}
20+
size_t write(uint8_t ch) override { device->printChar(ch); return 1;}
2121
void clearLine(idx_t ln,idx_t panelNr=0,colorDefs color=bgColor,bool selected=false,status stat=enabledStatus,bool edit=false) override {
2222
setCursor(0,ln,panelNr);
2323
for(int n=0;n<maxX();n++) print(' ');

src/menuIo.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,7 @@
5050
public:
5151
idx_t* tops;
5252
panelsList& panels;
53-
idx_t lastSel=-1;
54-
//TODO: turn this bool's into bitfield flags
53+
// idx_t lastSel=-1;
5554
enum styles {
5655
none=0<<0, // default serialOut
5756
redraw=1<<0,// changing one part implies printing all visible (deprecated)

0 commit comments

Comments
 (0)