Skip to content

Commit 6d6b4b2

Browse files
committed
use preprocessor directive for ESP8266 mcu's
we need to format wraps for other boards
1 parent fe466bd commit 6d6b4b2

File tree

11 files changed

+162
-112
lines changed

11 files changed

+162
-112
lines changed

examples/Blink/Blink/Blink.ino

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,9 @@ void setup() {
4747
Serial.println("to control the menu navigation");
4848
}
4949

50-
bool blink(int timeOn,int timeOff) {return millis()%(unsigned long)(timeOn+timeOff)<(unsigned long)timeOn;}
50+
bool blink(int timeOn,int timeOff) {
51+
return millis()%(unsigned long)(timeOn+timeOff)<(unsigned long)timeOn;
52+
}
5153

5254
void loop() {
5355
nav.poll();

examples/adafruitGfx/tft/platformio.ini

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,3 @@
1-
; PlatformIO Project Configuration File
2-
;
3-
; Build options: build flags, source filter, extra scripting
4-
; Upload options: custom port, speed and extra flags
5-
; Library options: dependencies, extra library storages
6-
;
7-
; Please visit documentation for the other options and examples
8-
; http://docs.platformio.org/en/stable/projectconf.html
9-
101
[platformio]
112
src_dir=tft
123
; lib_dir=~/Arduino/Libraries
Lines changed: 39 additions & 0 deletions
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
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
2+
This directory is intended for PIO Unit Testing and project tests.
3+
4+
Unit Testing is a software testing method by which individual units of
5+
source code, sets of one or more MCU program modules together with associated
6+
control data, usage procedures, and operating procedures, are tested to
7+
determine whether they are fit for use. Unit testing finds problems early
8+
in the development cycle.
9+
10+
More information about PIO Unit Testing:
11+
- https://docs.platformio.org/page/plus/unit-testing.html

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=ArduinoMenu library
2-
version=4.17.23
2+
version=4.17.24
33
author=Rui Azevedo, [email protected]
44
maintainer=neu-rah, [email protected]
55
sentence=Generic menu/interactivity system

src/menuIO/esp8266Out.h

Lines changed: 99 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -2,110 +2,113 @@
22

33
#ifndef RSITE_ARDUINO_MENU_ESP8266OUT
44
#define RSITE_ARDUINO_MENU_ESP8266OUT
5-
#include "../menuDefs.h"
6-
#include <ESP8266WiFi.h>
7-
// based on WebServer:
8-
// https://github.com/esp8266/Arduino/tree/master/libraries/ESP8266WebServer
9-
// https://github.com/Links2004/arduinoWebSockets
10-
#include <WebSocketsServer.h>
11-
#include <ESP8266WebServer.h>
12-
#include <vector>
13-
#include "xmlFmt.h"
5+
#ifdef ESP8266
6+
#include "../menuDefs.h"
7+
#include <ESP8266WiFi.h>
8+
// based on WebServer:
9+
// https://github.com/esp8266/Arduino/tree/master/libraries/ESP8266WebServer
10+
// https://github.com/Links2004/arduinoWebSockets
11+
#include <WebSocketsServer.h>
12+
#include <ESP8266WebServer.h>
13+
#include <vector>
14+
#include "xmlFmt.h"
1415

15-
using namespace std;
16+
using namespace std;
1617

17-
namespace Menu {
18+
namespace Menu {
1819

19-
class esp8266Out:public webOut {
20-
public:
21-
esp8266Out(
22-
idx_t* t,
23-
panelsList& p,
24-
menuOut::styles styles=(menuOut::styles)(redraw|expandEnums)
25-
):webOut(t,p,styles) {}
26-
menuOut& fill(
27-
int x1, int y1, int x2, int y2,char ch=' ',
28-
colorDefs color=bgColor,
29-
bool selected=false,
30-
status stat=enabledStatus,
31-
bool edit=false) override {return *this;}
32-
void setCursor(idx_t x,idx_t y,idx_t panelNr=0) override {}
33-
void clear() override {panels.reset();}
34-
void clear(idx_t panelNr) override {
35-
setCursor(0,0,panelNr);
36-
panels.nodes[panelNr]=NULL;
37-
}
38-
void clearLine(
39-
idx_t ln,
40-
idx_t panelNr=0,
41-
colorDefs color=bgColor,
42-
bool selected=false,
43-
status stat=enabledStatus,
44-
bool edit=false
45-
) override {}
46-
void setColor(colorDefs c,bool selected=false,status s=enabledStatus,bool e=false) override {};
47-
//template<typename T> esp8266Out& operator<<(T t)=0;
48-
};
20+
class esp8266Out:public webOut {
21+
public:
22+
esp8266Out(
23+
idx_t* t,
24+
panelsList& p,
25+
menuOut::styles styles=(menuOut::styles)(redraw|expandEnums)
26+
):webOut(t,p,styles) {}
27+
menuOut& fill(
28+
int x1, int y1, int x2, int y2,char ch=' ',
29+
colorDefs color=bgColor,
30+
bool selected=false,
31+
status stat=enabledStatus,
32+
bool edit=false) override {return *this;}
33+
void setCursor(idx_t x,idx_t y,idx_t panelNr=0) override {}
34+
void clear() override {panels.reset();}
35+
void clear(idx_t panelNr) override {
36+
setCursor(0,0,panelNr);
37+
panels.nodes[panelNr]=NULL;
38+
}
39+
void clearLine(
40+
idx_t ln,
41+
idx_t panelNr=0,
42+
colorDefs color=bgColor,
43+
bool selected=false,
44+
status stat=enabledStatus,
45+
bool edit=false
46+
) override {}
47+
void setColor(colorDefs c,bool selected=false,status s=enabledStatus,bool e=false) override {};
48+
//template<typename T> esp8266Out& operator<<(T t)=0;
49+
};
4950

50-
class esp8266BufferedOut:public esp8266Out {
51-
public:
52-
String response;
53-
using esp8266Out::esp8266Out;
54-
template<typename T> inline esp8266BufferedOut& operator<<(T t) {response<<t;return *this;}
55-
size_t write(uint8_t ch) override {response+=(char)ch;return 1;}
56-
};
51+
class esp8266BufferedOut:public esp8266Out {
52+
public:
53+
String response;
54+
using esp8266Out::esp8266Out;
55+
template<typename T> inline esp8266BufferedOut& operator<<(T t) {response<<t;return *this;}
56+
size_t write(uint8_t ch) override {response+=(char)ch;return 1;}
57+
};
5758

58-
menuOut& operator<<(menuOut&o,classes c);
59-
template<typename T> inline String& operator<<(String& o,T t) {return o.operator+=(t);}
59+
menuOut& operator<<(menuOut&o,classes c);
60+
template<typename T> inline String& operator<<(String& o,T t) {return o.operator+=(t);}
6061

61-
class esp8266_WebServerOut:public esp8266BufferedOut {
62-
public:
63-
ESP8266WebServer &server;
64-
//using esp8266Out::esp8266Out;
65-
esp8266_WebServerOut(
66-
ESP8266WebServer &srv,
67-
/*const colorDef<esp8266Out::webColor> (&c)[nColors],*/
68-
idx_t* t,
69-
panelsList& p
70-
):esp8266BufferedOut(t,p),server(srv) {}
71-
size_t write(uint8_t ch) override {response<<(char)ch;return 1;}
72-
// template<typename T> inline esp8266_WebServerOut& operator<<(T t) {response<<t;return *this;}
73-
};
62+
class esp8266_WebServerOut:public esp8266BufferedOut {
63+
public:
64+
ESP8266WebServer &server;
65+
//using esp8266Out::esp8266Out;
66+
esp8266_WebServerOut(
67+
ESP8266WebServer &srv,
68+
/*const colorDef<esp8266Out::webColor> (&c)[nColors],*/
69+
idx_t* t,
70+
panelsList& p
71+
):esp8266BufferedOut(t,p),server(srv) {}
72+
size_t write(uint8_t ch) override {response<<(char)ch;return 1;}
73+
// template<typename T> inline esp8266_WebServerOut& operator<<(T t) {response<<t;return *this;}
74+
};
7475

75-
class esp8266_WebServerStreamOut:public esp8266Out {
76-
public:
77-
ESP8266WebServer &server;
78-
inline esp8266_WebServerStreamOut(
79-
ESP8266WebServer &srv,
80-
idx_t* t,
81-
panelsList& p
82-
):esp8266Out(t,p),server(srv) {}
83-
inline size_t write(uint8_t ch) override {
84-
char c[2]={ch,0};
85-
server.sendContent(c);
86-
return 1;
87-
}
88-
template<typename T> inline esp8266_WebServerStreamOut& operator<<(T t) {
89-
server.sendContent(String()+t);
90-
return *this;
91-
}
92-
};
76+
class esp8266_WebServerStreamOut:public esp8266Out {
77+
public:
78+
ESP8266WebServer &server;
79+
inline esp8266_WebServerStreamOut(
80+
ESP8266WebServer &srv,
81+
idx_t* t,
82+
panelsList& p
83+
):esp8266Out(t,p),server(srv) {}
84+
inline size_t write(uint8_t ch) override {
85+
char c[2]={ch,0};
86+
server.sendContent(c);
87+
return 1;
88+
}
89+
template<typename T> inline esp8266_WebServerStreamOut& operator<<(T t) {
90+
server.sendContent(String()+t);
91+
return *this;
92+
}
93+
};
9394

94-
// class esp8266_WebSocketOut:public esp8266BufferedOut {
95-
// public:
96-
// //client num... well we only serve a client at a time, so its safe to put t here
97-
// // of course this kind of code is not thead safe...but we dont have theads anyway
98-
// uint8_t num;
99-
// String response;
100-
// WebSocketsServer &webSocket;
101-
// esp8266_WebSocketOut(WebSocketsServer &socket,idx_t* tops,panelsList& panels)
102-
// :webSocket(socket),esp8266BufferedOut(tops,panels,(menuOut::styles)(minimalRedraw|expandEnums)) {}
103-
// size_t write(uint8_t ch) override {response<<(char)ch;return 1;}
104-
// };
95+
// class esp8266_WebSocketOut:public esp8266BufferedOut {
96+
// public:
97+
// //client num... well we only serve a client at a time, so its safe to put t here
98+
// // of course this kind of code is not thead safe...but we dont have theads anyway
99+
// uint8_t num;
100+
// String response;
101+
// WebSocketsServer &webSocket;
102+
// esp8266_WebSocketOut(WebSocketsServer &socket,idx_t* tops,panelsList& panels)
103+
// :webSocket(socket),esp8266BufferedOut(tops,panels,(menuOut::styles)(minimalRedraw|expandEnums)) {}
104+
// size_t write(uint8_t ch) override {response<<(char)ch;return 1;}
105+
// };
105106

106-
//template<typename T> inline esp8266_WebServerOut& operator<<(esp8266_WebServerOut&o , T t) {return o.operator<<(t);}
107-
//template<typename T> inline esp8266_WiFiClientOut& operator<<(esp8266_WiFiClientOut&o , T t) {return o.operator<<(t);}
108-
//template<typename T> inline esp8266Out& operator<<(esp8266Out&o , T t) {return o.operator<<(t);}
107+
//template<typename T> inline esp8266_WebServerOut& operator<<(esp8266_WebServerOut&o , T t) {return o.operator<<(t);}
108+
//template<typename T> inline esp8266_WiFiClientOut& operator<<(esp8266_WiFiClientOut&o , T t) {return o.operator<<(t);}
109+
//template<typename T> inline esp8266Out& operator<<(esp8266Out&o , T t) {return o.operator<<(t);}
109110

110-
}//namespace Menu
111+
}//namespace Menu
112+
#include "esp8266Out.hpp"
113+
#endif
111114
#endif
Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
#include "../menuDefs.h"
2-
#ifdef MENU_FMT_WRAPS
3-
#include "esp8266Out.h"
1+
#pragma once
2+
#ifdef ESP8266
3+
#include "../menuDefs.h"
4+
//MENU_FMT_WRAPS
5+
#include "esp8266Out.h"
46

57
menuOut& operator<<(menuOut&o,classes c) {
68
switch(c) {

src/menuIO/jsonFmt.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#ifdef MENU_FMT_WRAPS
77
#include "../menuDefs.h"
88
#include "../items.h"
9-
#include "esp8266Out.h"
9+
// #include "esp8266Out.h"
1010

1111
namespace Menu {
1212

@@ -165,5 +165,6 @@
165165
}
166166
};
167167
}//namespace
168+
#include "jsonFmt.hpp"
168169
#endif
169170
#endif

src/menuIO/xmlFmt.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#ifdef MENU_FMT_WRAPS
77
#include "../menuDefs.h"
88
#include "../items.h"
9-
#include "esp8266Out.h"
9+
// #include "esp8266Out.h"
1010

1111
namespace Menu {
1212

@@ -160,5 +160,6 @@
160160
result fmtEnd(prompt& target,menuOut::fmtParts part,navNode &nav,idx_t idx=-1) override {return fmt(false,target,part,nav,idx);}
161161
};
162162
}//namespace
163+
#include "xmlFmt.hpp"
163164
#endif
164165
#endif

0 commit comments

Comments
 (0)