Skip to content

Commit 258395d

Browse files
author
gemi254
committed
Removed setup web server handlers
1 parent 593e6e3 commit 258395d

File tree

1 file changed

+18
-34
lines changed

1 file changed

+18
-34
lines changed

src/ControlAssist.h

Lines changed: 18 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,14 @@
22
#define _CONTROL_ASSIST_H
33

44
#include <vector>
5-
#if defined(ESP32)
6-
#include <WebServer.h>
7-
#else
8-
#include <ESP8266WebServer.h>
9-
#include <LittleFS.h>
10-
#endif
115
#include <WebSocketsServer.h>
126

137
#ifndef LOGGER_LOG_LEVEL
148
#define LOGGER_LOG_LEVEL 4 // Set log level for this module
159
#endif
1610

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
2813

2914
#ifndef STORAGE
3015
#if defined(ESP32)
@@ -64,8 +49,6 @@ class ControlAssist{
6449
public:
6550
// Start web sockets server
6651
void begin();
67-
// Setup web server handlers
68-
void setup(WEB_SERVER &server, const char *uri = "/");
6952
// Set web sockets server listening port
7053
void setPort(uint16_t port) {if(!_wsEnabled) _port = port; }
7154
// Bind a html control with id = key to a control variable
@@ -99,47 +82,49 @@ class ControlAssist{
9982
// Implement operator [] i.e. val = config[ndx]
10083
ctrlPairs operator [] (uint8_t ndx) { return _ctrls[ndx]; }
10184
// Return the val of a given key, Empty on not found
102-
String getVal(String key);
85+
String getVal(const String &key);
10386
// Return the position of given key
104-
int getKeyNdx(String key);
87+
int getKeyNdx(const String &key);
10588
// Return next key and value from configs on each call in key order
10689
bool getNextPair(ctrlPairs &c);
10790
// 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);
10992
// Add vectors pairs
11093
size_t add(ctrlPairs &c);
11194
// Set the val at key index, (int)
11295
bool set(int keyNdx, int val, bool forceSend = false);
11396
// 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);
11598
// 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);
117100
// 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);
119102
// Display config items
120-
void dump(WEB_SERVER *server = NULL);
103+
//void dump(WEB_SERVER *server);
104+
bool dump(String &res);
105+
121106
public:
122107
// Sort vectors by key (name in confPairs)
123108
void sort();
124109
// Run websockets
125110
void loop() { if(_socket) _socket->loop(); }
126111
// Get the initialization java script
127112
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);
128117
// 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);
132119
// Get number of connected clients
133120
uint8_t getClientsNum() { return _clientsNum; }
134121
// 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);
136123
// Set the auto send on ws connection flag on all keys
137124
void setAutoSendOnCon(bool send);
138125
private:
139-
// Send a file from spiffs to client
140-
void streamFile(WEB_SERVER &server, const char *htmlFile);
141126
// Load a file into text
142-
bool loadText(String fPath, String &txt);
127+
bool loadText(const String &fPath, String &txt);
143128
// Start websockets
144129
void startWebSockets();
145130
// Stop websockets
@@ -160,7 +145,6 @@ class ControlAssist{
160145
const char* _html_footer_file;
161146
uint16_t _port;
162147
bool _wsEnabled;
163-
WEB_SERVER *_server;
164148
WebSocketsServer *_socket;
165149
WebSocketServerEventG _ev;
166150
};

0 commit comments

Comments
 (0)