EmbAJAX
Simplistic framework for creating and handling displays and controls on a web page served by an embeddable device (Arduino or other microcontroller with Arduino support).
EmbAJAXOutputDriverGeneric.h
1 
22 #ifndef EMBAJAXOUTPUTDRIVERGENERIC_H
23 #define EMBAJAXOUTPUTDRIVERGENERIC_H
24 
25 #if defined (EMBAJAX_OUTUPUTDRIVER_IMPLEMENTATION)
26 #error Duplicate definition of output driver. Fix your include-directives.
27 #endif
28 #define EMBAJAX_OUTUPUTDRIVER_IMPLEMENTATION
29 
30 #if not defined EmbAJAXOutputDriverWebServerClass
31 #error Please define EmbAJAXOutputDriverWebServerClass or #include appropriate hardware specific driver
32 #endif
33 
34 // For EmbAJAXPage. Important to include after defining EMBAJAX_OUTUPUTDRIVER_IMPLEMENTATION
35 #include "EmbAJAX.h"
36 
39 public:
42  EmbAJAXOutputDriverGeneric(EmbAJAXOutputDriverWebServerClass *server) {
44  _server = server;
45  }
46  void printHeader(bool html) override {
47  _server->setContentLength(CONTENT_LENGTH_UNKNOWN);
48  if (html) {
49  _server->send(200, "text/html", "");
50  } else {
51  _server->send(200, "text/json", "");
52  }
53  }
54  void printContent(const char *content) override {
55  if (content[0] != '\0') _server->sendContent(content); // NOTE: There seems to be a bug in the ESP8266 server when sending empty string.
56  }
57  const char* getArg(const char* name, char* buf, int buflen) override {
58  _server->arg(name).toCharArray (buf, buflen);
59  return buf;
60  }
61  void installPage(EmbAJAXPageBase *page, const char *path, void (*change_callback)()=0) override {
62  _server->on(path, [=]() {
63  if (_server->method() == HTTP_POST) { // AJAX request
64  page->handleRequest(change_callback);
65  } else { // Page load
66  page->printPage();
67  }
68  });
69  }
70  void loopHook() override {
71  _server->handleClient();
72  };
73 private:
74  EmbAJAXOutputDriverWebServerClass *_server;
75 };
76 
78 
79 #endif
static void setDriver(EmbAJAXOutputDriverBase *driver)
Definition: EmbAJAX.h:77
Abstract base class for output drivers/server implementations.
Definition: EmbAJAX.h:147
Output driver implementation. This implementation works with ESPAsyncWebServer (https://github....
Definition: EmbAJAXOutputDriverESPAsync.h:40
Output driver implementation. This implementation should work for most arduino web servers with minim...
Definition: EmbAJAXOutputDriverGeneric.h:38
EmbAJAXOutputDriverGeneric(EmbAJAXOutputDriverWebServerClass *server)
Definition: EmbAJAXOutputDriverGeneric.h:42
void installPage(EmbAJAXPageBase *page, const char *path, void(*change_callback)()=0) override
Definition: EmbAJAXOutputDriverGeneric.h:61
void loopHook() override
Definition: EmbAJAXOutputDriverGeneric.h:70
Absrract internal helper class.
Definition: EmbAJAX.h:709