Skip to content

Commit 01901b7

Browse files
committed
made webmenu compile on arduino-ide
1 parent d24252e commit 01901b7

File tree

12 files changed

+97
-10
lines changed

12 files changed

+97
-10
lines changed

examples/esp8266/WebMenu/WebMenu/WebMenu.ino

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ menuOut& operator<<(menuOut& o,endlObj) {
5959
return o;
6060
}
6161

62-
#define CUR_VERSION "1.0"
62+
#define CUR_VERSION "1.1"
6363
#define APName "WebMenu"
6464
#define ANALOG_PIN 4
6565

@@ -133,19 +133,61 @@ CHOOSE(chooseTest,chooseMenu,"Choose",doNothing,noEvent,noStyle
133133
,VALUE("Last",-1,doNothing,noEvent)
134134
);
135135

136-
int timeOn=50;
136+
int dutty=50;//%
137+
int timeOn=50;//ms
137138
void updAnalog() {
138139
// analogWrite(ANALOG_PIN,map(timeOn,0,100,0,255/*PWMRANGE*/));
139140
}
140141

142+
char* constMEM alphaNum MEMMODE=" 0123456789.ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz,\\|!\"#$%&/()=?~*^+-{}[]€";
143+
char* constMEM alphaNumMask[] MEMMODE={alphaNum};
144+
char name[]=" ";
145+
146+
uint16_t year=2017;
147+
uint16_t month=10;
148+
uint16_t day=7;
149+
150+
//define a pad style menu (single line menu)
151+
//here with a set of fields to enter a date in YYYY/MM/DD format
152+
//altMENU(menu,birthDate,"Birth",doNothing,noEvent,noStyle,(systemStyles)(_asPad|Menu::_menuData|Menu::_canNav|_parentDraw)
153+
PADMENU(birthDate,"Birth",doNothing,noEvent,noStyle
154+
,FIELD(year,"","/",1900,3000,20,1,doNothing,noEvent,noStyle)
155+
,FIELD(month,"","/",1,12,1,0,doNothing,noEvent,wrapStyle)
156+
,FIELD(day,"","",1,31,1,0,doNothing,noEvent,wrapStyle)
157+
);
158+
159+
//customizing a prompt look!
160+
//by extending the prompt class
161+
class altPrompt:public prompt {
162+
public:
163+
// altPrompt(constMEM promptShadow& p):prompt(p) {}
164+
using prompt::prompt;
165+
Used printTo(navRoot &root,bool sel,menuOut& out, idx_t idx,idx_t len,idx_t) override {
166+
return out.printRaw(F("special prompt!"),len);
167+
}
168+
};
169+
170+
MENU(subMenu,"Sub-Menu",doNothing,noEvent,noStyle
171+
,OP("Sub1",doNothing,noEvent)
172+
,OP("Sub2",doNothing,noEvent)
173+
,OP("Sub3",doNothing,noEvent)
174+
// ,altOP(altPrompt,"",doNothing,noEvent)
175+
,EXIT("<Back")
176+
);
177+
141178
//the menu
142179
MENU(mainMenu,"Main menu",doNothing,noEvent,wrapStyle
143180
,SUBMENU(setLed)
144181
,OP("Action A",action1,enterEvent)
145182
,OP("Action B",action2,enterEvent)
183+
,FIELD(dutty,"Dutty","%",0,100,10,1, updAnalog, anyEvent, noStyle)
146184
,FIELD(timeOn,"On","ms",0,100,10,1, updAnalog, anyEvent, noStyle)
185+
,EDIT("Name",name,alphaNumMask,doNothing,noEvent,noStyle)
186+
,SUBMENU(birthDate)
147187
,SUBMENU(selMenu)
148188
,SUBMENU(chooseMenu)
189+
,SUBMENU(subMenu)
190+
,EXIT("Exit!")
149191
);
150192

151193
result idle(menuOut& o,idleEvent e) {
@@ -306,6 +348,14 @@ void setup(){
306348
Serial.println();
307349
Serial.println();
308350

351+
// #ifndef MENU_DEBUG
352+
//do not allow web heads to exit, they wont be able to return (for now)
353+
//we should resume this heads on async requests!
354+
webNav.canExit=false;
355+
jsonNav.canExit=false;
356+
wsNav.canExit=false;
357+
// #endif
358+
309359
for(uint8_t t = 4; t > 0; t--) {
310360
Serial.printf("[SETUP] BOOT WAIT %d...\n", t);
311361
Serial.flush();

examples/esp8266/WebMenu/WebMenu/data/1.0/bootstrap.xslt renamed to examples/esp8266/WebMenu/WebMenu/data/1.1/bootstrap.xslt

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,27 @@
138138
<xsl:template name="ignore" match="cur|fv"/>
139139
<xsl:template name="ignorePad" match="cur|fv" mode="pad"/>
140140

141-
<xsl:template match="fld[../p[@t='f']]">
141+
<!-- <xsl:template match="fld[../p[@t='f']]">
142+
<xsl:variable name="path">
143+
<xsl:value-of select="ancestor::*/@r"/>
144+
<xsl:for-each select="ancestor::*/@i">/<xsl:value-of select="."/></xsl:for-each>
145+
</xsl:variable>
146+
<xsl:element name="input">
147+
<xsl:attribute name="id">fld_<xsl:value-of select="/menuLib/panel/@id"/>_<xsl:value-of select="../../@i"/></xsl:attribute>
148+
<xsl:attribute name="data-slider-id">fld_<xsl:value-of select="/menuLib/panel/@id"/>_<xsl:value-of select="../../@i"/></xsl:attribute>
149+
<xsl:attribute name="type">text</xsl:attribute>
150+
<xsl:attribute name="class">slider ledField</xsl:attribute>
151+
<xsl:attribute name="data-slider-min"><xsl:value-of select="@l"/></xsl:attribute>
152+
<xsl:attribute name="data-slider-max"><xsl:value-of select="@h"/></xsl:attribute>
153+
<xsl:attribute name="data-slider-step"><xsl:value-of select="@t"/></xsl:attribute>
154+
<xsl:attribute name="data-slider-value"><xsl:apply-templates/></xsl:attribute>
155+
<xsl:attribute name="value"><xsl:apply-templates/></xsl:attribute>
156+
<xsl:attribute name="data-src"><xsl:value-of select="$path"/></xsl:attribute>
157+
<xsl:attribute name="onchange">window.location='/menu?at='+getAttribute("data-src")+'/'+value</xsl:attribute>
158+
</xsl:element>
159+
</xsl:template> -->
160+
161+
<xsl:template match="fld[../u='%']">
142162
<xsl:variable name="path">
143163
<xsl:value-of select="ancestor::*/@r"/>
144164
<xsl:for-each select="ancestor::*/@i">/<xsl:value-of select="."/></xsl:for-each>
@@ -198,7 +218,20 @@
198218
</xsl:choose>
199219
</xsl:variable>
200220
<xsl:choose>
201-
<xsl:when test="$ln>=100"><!-- disabled in pactice, with a large value -->
221+
<xsl:when test="$ln>=10000 and $ln&lt;=1000"><!-- disabled in pactice, with a large value -->
222+
<xsl:element name="input">
223+
<xsl:attribute name="id">fld_<xsl:value-of select="/menuLib/panel/@id"/>_<xsl:value-of select="../../@i"/></xsl:attribute>
224+
<xsl:attribute name="data-slider-id">fld_<xsl:value-of select="/menuLib/panel/@id"/>_<xsl:value-of select="../../@i"/></xsl:attribute>
225+
<xsl:attribute name="type">text</xsl:attribute>
226+
<xsl:attribute name="class">slider ledField</xsl:attribute>
227+
<xsl:attribute name="data-slider-min"><xsl:value-of select="@l"/></xsl:attribute>
228+
<xsl:attribute name="data-slider-max"><xsl:value-of select="@h"/></xsl:attribute>
229+
<xsl:attribute name="data-slider-step"><xsl:value-of select="@t"/></xsl:attribute>
230+
<xsl:attribute name="data-slider-value"><xsl:apply-templates/></xsl:attribute>
231+
<xsl:attribute name="value"><xsl:apply-templates/></xsl:attribute>
232+
<!-- <xsl:attribute name="data-src"><xsl:value-of select="$path"/></xsl:attribute> -->
233+
<xsl:attribute name="onchange">window.location='/menu?at='+getAttribute("data-src")+'/'+value</xsl:attribute>
234+
</xsl:element>
202235
<!-- some fancy slider.. not working yet -->
203236
<!-- <xsl:element name="input">
204237
<xsl:attribute name="id">fld_<xsl:value-of select="/menuLib/panel/@id"/>_<xsl:value-of select="../../@i"/></xsl:attribute>
@@ -210,15 +243,15 @@
210243
<xsl:attribute name="data-slider-value"><xsl:apply-templates/></xsl:attribute>
211244
</xsl:element> -->
212245
<!-- standard slider -->
213-
<xsl:element name="input">
246+
<!-- <xsl:element name="input">
214247
<xsl:copy-of select="node/@*"/>
215248
<xsl:copy-of select="../../p/@i"/>
216249
<xsl:attribute name="class">menu-range-fld</xsl:attribute>
217250
<xsl:attribute name="type">range</xsl:attribute>
218251
<xsl:attribute name="value"><xsl:apply-templates/></xsl:attribute>
219252
<xsl:attribute name="data-src"><xsl:value-of select="$at"/></xsl:attribute>
220253
<xsl:attribute name="onchange">window.location='/menu?at='+getAttribute("data-src")+'/'+value</xsl:attribute>
221-
</xsl:element>
254+
</xsl:element> -->
222255
</xsl:when>
223256
<xsl:otherwise>
224257
<xsl:element name="input">
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
5.72 KB
Loading

src/macros.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
#endif
1111
#if defined(ESP8266) | defined(CORE_TEENSY)
1212
#define typeof(x) __typeof__(x)
13+
#define MENU_ASYNC
14+
#define MENU_FMT_WRAPS
15+
#define MENU_IDLE_BKGND
1316
#endif
1417
#if defined(USE_PGM) || (defined(pgm_read_ptr_near) && !defined(MENU_USERAM))
1518
//storing some values into avr flash memory (saving ram space)
@@ -41,9 +44,9 @@
4144
#define memIdx(src) (src)
4245
#define memStrLen strlen
4346
#define memEnum(addr) (*addr)
44-
#ifndef F
47+
// #ifndef F
4548
#define F(x) (x)
46-
#endif
49+
// #endif
4750
#endif
4851

4952
/////////////////////////////////////////////////////////////////////////////

src/menuDefs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
// #define USE_RAM
99
// #define MENU_DEBUG
1010

11+
#include "macros.h"
1112
#include "menuBase.h"
1213
#include "shadows.h"
1314

0 commit comments

Comments
 (0)