feat: 全量同步 254 个常用的 Arduino 扩展库文件

This commit is contained in:
yczpf2019
2026-01-24 16:05:38 +08:00
parent c665ba662b
commit 397b9a23a3
6878 changed files with 2732224 additions and 1 deletions

View File

@@ -0,0 +1,162 @@
#ifndef WebSerial_h
#define WebSerial_h
#include "Arduino.h"
#include "stdlib_noniso.h"
#include <functional>
#if defined(ESP8266)
#define HARDWARE "ESP8266"
#include "ESP8266WiFi.h"
#include "ESPAsyncTCP.h"
#include "ESPAsyncWebServer.h"
#elif defined(ESP32)
#define HARDWARE "ESP32"
#include "WiFi.h"
#include "AsyncTCP.h"
#include "ESPAsyncWebServer.h"
#endif
#define BUFFER_SIZE 500
#include "webserial_webpage.h"
typedef std::function<void(uint8_t *data, size_t len)> RecvMsgHandler;
class WebSerialClass{
public:
void begin(AsyncWebServer *server, const char* url = "/webserial"){
_server = server;
_ws = new AsyncWebSocket("/webserialws");
_server->on(url, HTTP_GET, [](AsyncWebServerRequest *request){
// Send Webpage
AsyncWebServerResponse *response = request->beginResponse_P(200, "text/html", WEBSERIAL_HTML, WEBSERIAL_HTML_SIZE);
response->addHeader("Content-Encoding","gzip");
request->send(response);
});
_ws->onEvent([&](AsyncWebSocket * server, AsyncWebSocketClient * client, AwsEventType type, void * arg, uint8_t *data, size_t len) -> void {
if(type == WS_EVT_CONNECT){
#if defined(DEBUG)
DEBUG_WEB_SERIAL("Client connection received");
#endif
} else if(type == WS_EVT_DISCONNECT){
#if defined(DEBUG)
DEBUG_WEB_SERIAL("Client disconnected");
#endif
} else if(type == WS_EVT_DATA){
#if defined(DEBUG)
DEBUG_WEB_SERIAL("Received Websocket Data");
#endif
if(_RecvFunc != NULL){
_RecvFunc(data, len);
}
}
});
_server->addHandler(_ws);
#if defined(DEBUG)
DEBUG_WEB_SERIAL("Attached AsyncWebServer along with Websockets");
#endif
}
void msgCallback(RecvMsgHandler _recv){
_RecvFunc = _recv;
}
// Print
void print(String m = ""){
_ws->textAll(m);
}
void print(const char *m){
_ws->textAll(m);
}
void print(char *m){
_ws->textAll(m);
}
void print(int m){
_ws->textAll(String(m));
}
void print(uint8_t m){
_ws->textAll(String(m));
}
void print(uint16_t m){
_ws->textAll(String(m));
}
void print(uint32_t m){
_ws->textAll(String(m));
}
void print(double m){
_ws->textAll(String(m));
}
void print(float m){
_ws->textAll(String(m));
}
// Print with New Line
void println(String m = ""){
_ws->textAll(m+"\n");
}
void println(const char *m){
_ws->textAll(String(m)+"\n");
}
void println(char *m){
_ws->textAll(String(m)+"\n");
}
void println(int m){
_ws->textAll(String(m)+"\n");
}
void println(uint8_t m){
_ws->textAll(String(m)+"\n");
}
void println(uint16_t m){
_ws->textAll(String(m)+"\n");
}
void println(uint32_t m){
_ws->textAll(String(m)+"\n");
}
void println(float m){
_ws->textAll(String(m)+"\n");
}
void println(double m){
_ws->textAll(String(m)+"\n");
}
private:
AsyncWebServer *_server;
AsyncWebSocket *_ws;
RecvMsgHandler _RecvFunc = NULL;
#if defined(DEBUG)
void DEBUG_WEB_SERIAL(const char* message){
Serial.println("[WebSerial] "+message);
}
#endif
};
WebSerialClass WebSerial;
#endif

File diff suppressed because one or more lines are too long