From 62f8f70b963ea5a8bbfbe34ec06899fdaef12997 Mon Sep 17 00:00:00 2001 From: cskarai Date: Tue, 6 Sep 2016 20:24:30 +0200 Subject: [PATCH] Let WebServer handle other EspLink calls --- arduino/libraries/EspLink/WebServer.cpp | 11 +++++++++-- arduino/libraries/EspLink/WebServer.h | 6 ++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/arduino/libraries/EspLink/WebServer.cpp b/arduino/libraries/EspLink/WebServer.cpp index eea3ec6..cd0af2c 100644 --- a/arduino/libraries/EspLink/WebServer.cpp +++ b/arduino/libraries/EspLink/WebServer.cpp @@ -3,14 +3,14 @@ #define RESUBSCRIBE_LIMIT 1000 -WebServer * WebServer::instance = NULL; +WebServer * WebServer::instance = NULL; void webServerCallback(CmdRequest *req) { WebServer::getInstance()->handleRequest(req); } -WebServer::WebServer(Stream &streamIn, const WebMethod * PROGMEM methodsIn):espLink(streamIn, webServerCallback),methods(methodsIn),stream(streamIn) +WebServer::WebServer(Stream &streamIn, const WebMethod * PROGMEM methodsIn):espLink(streamIn, webServerCallback),methods(methodsIn),stream(streamIn),esplink_cb(NULL) { instance = this; } @@ -89,6 +89,13 @@ void WebServer::invokeMethod(RequestReason reason, WebMethod * method, CmdReques void WebServer::handleRequest(CmdRequest *req) { + if( req->cmd->cmd != CMD_WEB_REQ_CB ) + { + if( esplink_cb != NULL ) + esplink_cb(req); + return; + } + uint16_t shrt; espLink.cmdPopArg(req, &shrt, 2); RequestReason reason = (RequestReason)shrt; diff --git a/arduino/libraries/EspLink/WebServer.h b/arduino/libraries/EspLink/WebServer.h index a589f3d..59f1cb2 100644 --- a/arduino/libraries/EspLink/WebServer.h +++ b/arduino/libraries/EspLink/WebServer.h @@ -56,6 +56,8 @@ class WebServer uint32_t last_connect_ts; + CmdRequestCB esplink_cb; + protected: EspLink espLink; @@ -66,6 +68,8 @@ class WebServer void loop(); void registerCallback(); + + void setEspLinkCallback(CmdRequestCB cb) { esplink_cb = cb; } static WebServer * getInstance() { return instance; } uint8_t * getRemoteIp() { return remote_ip; } @@ -80,6 +84,8 @@ class WebServer int32_t getArgInt(); char * getArgString(); uint8_t getArgBoolean(); + + EspLink * getEspLink() { return &espLink; } }; #endif /* WEB_SERVER_H */