2
2
#define _CONTROL_ASSIST_H
3
3
4
4
#include < vector>
5
- #if defined(ESP32)
6
- #include < WebServer.h>
7
- #else
8
- #include < ESP8266WebServer.h>
9
- #include < LittleFS.h>
10
- #endif
11
5
#include < WebSocketsServer.h>
12
6
13
7
#ifndef LOGGER_LOG_LEVEL
14
8
#define LOGGER_LOG_LEVEL 4 // Set log level for this module
15
9
#endif
16
10
17
- #define CT_CLASS_VERSION " 1.1.2" // Class version
18
- #define STREAM_CHUNKSIZE 256 // Stream file buffer size
19
-
20
- // Define Platform objects
21
- #ifndef WEB_SERVER
22
- #if defined(ESP32)
23
- #define WEB_SERVER WebServer
24
- #else
25
- #define WEB_SERVER ESP8266WebServer
26
- #endif
27
- #endif
11
+ #define CT_CLASS_VERSION " 1.1.3" // Class version
12
+ #define CTRLASSIST_STREAM_CHUNKSIZE 2048 // Stream file buffer size
28
13
29
14
#ifndef STORAGE
30
15
#if defined(ESP32)
@@ -64,8 +49,6 @@ class ControlAssist{
64
49
public:
65
50
// Start web sockets server
66
51
void begin ();
67
- // Setup web server handlers
68
- void setup (WEB_SERVER &server, const char *uri = " /" );
69
52
// Set web sockets server listening port
70
53
void setPort (uint16_t port) {if (!_wsEnabled) _port = port; }
71
54
// Bind a html control with id = key to a control variable
@@ -99,47 +82,49 @@ class ControlAssist{
99
82
// Implement operator [] i.e. val = config[ndx]
100
83
ctrlPairs operator [] (uint8_t ndx) { return _ctrls[ndx]; }
101
84
// Return the val of a given key, Empty on not found
102
- String getVal (String key);
85
+ String getVal (const String & key);
103
86
// Return the position of given key
104
- int getKeyNdx (String key);
87
+ int getKeyNdx (const String & key);
105
88
// Return next key and value from configs on each call in key order
106
89
bool getNextPair (ctrlPairs &c);
107
90
// Add vectors by key (name in ctrlPairs)
108
- size_t add (String key, String val);
91
+ size_t add (const String & key, const String & val);
109
92
// Add vectors pairs
110
93
size_t add (ctrlPairs &c);
111
94
// Set the val at key index, (int)
112
95
bool set (int keyNdx, int val, bool forceSend = false );
113
96
// Set the val at key index, (string)
114
- bool set (int keyNdx, String val, bool forceSend = false );
97
+ bool set (int keyNdx, const String & val, bool forceSend = false );
115
98
// Put val (int) to Key. forcesend to false to send changes only, forceAdd to add it if not exists
116
- bool put (String key, int val, bool forceSend = false , bool forceAdd = false );
99
+ bool put (const String & key, int val, bool forceSend = false , bool forceAdd = false );
117
100
// Put val (string) to Key. forcesend to false to send changes only, forceAdd to add it if not exists
118
- bool put (String key, String val, bool forceSend = false , bool forceAdd = false );
101
+ bool put (const String & key, const String & val, bool forceSend = false , bool forceAdd = false );
119
102
// Display config items
120
- void dump (WEB_SERVER *server = NULL );
103
+ // void dump(WEB_SERVER *server);
104
+ bool dump (String &res);
105
+
121
106
public:
122
107
// Sort vectors by key (name in confPairs)
123
108
void sort ();
124
109
// Run websockets
125
110
void loop () { if (_socket) _socket->loop (); }
126
111
// Get the initialization java script
127
112
String getInitScript ();
113
+ // Get a chunk from a html file
114
+ bool getFileChunk (const char *fname, String &res);
115
+ // Get a chunk from a html buffer
116
+ bool getStringChunk (const char *src, String &res);
128
117
// Render html to client
129
- void sendHtml (WEB_SERVER &server);
130
- // Render html to client
131
- void sendHtml () {sendHtml (*_server); };
118
+ bool getHtmlChunk (String &res);
132
119
// Get number of connected clients
133
120
uint8_t getClientsNum () { return _clientsNum; }
134
121
// Set the auto send on ws connection flag on key
135
- bool setAutoSendOnCon (String key, bool send);
122
+ bool setAutoSendOnCon (const String & key, bool send);
136
123
// Set the auto send on ws connection flag on all keys
137
124
void setAutoSendOnCon (bool send);
138
125
private:
139
- // Send a file from spiffs to client
140
- void streamFile (WEB_SERVER &server, const char *htmlFile);
141
126
// Load a file into text
142
- bool loadText (String fPath , String &txt);
127
+ bool loadText (const String & fPath , String &txt);
143
128
// Start websockets
144
129
void startWebSockets ();
145
130
// Stop websockets
@@ -160,7 +145,6 @@ class ControlAssist{
160
145
const char * _html_footer_file;
161
146
uint16_t _port;
162
147
bool _wsEnabled;
163
- WEB_SERVER *_server;
164
148
WebSocketsServer *_socket;
165
149
WebSocketServerEventG _ev;
166
150
};
0 commit comments