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).
EmbAJAX.h
Go to the documentation of this file.
1 /*
2  *
3  * EmbAJAX - Simplistic framework for creating and handling displays and controls on a WebPage served by an Arduino (or other small device).
4  *
5  * Copyright (C) 2018-2023 Thomas Friedrichsmeier
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU Lesser General Public License as published
9  * by the Free Software Foundation, either version 3 of the License, or (at
10  * your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  *
20 **/
21 #ifndef EMBAJAX_H
22 #define EMBAJAX_H
23 
24 #include <Arduino.h>
25 
27 #define EMBAJAX_MAX_ID_LEN 16
28 
29 // Set to a value above 0 for diagnostics on Serial and browser console
30 // #define EMBAJAX_DEBUG 3
31 
51 //#define USE_PROGMEM_STRINGS 0
52 
53 #if !defined USE_PROGMEM_STRINGS
54  #if defined(memcpy_P) && (memcpy_P == memcpy)
55  #define USE_PROGMEM_STRINGS 0
56  #else
57  #define USE_PROGMEM_STRINGS 1
58  #endif
59 #endif
60 
61 #include "macro_definitions.h"
62 
64 class EmbAJAXElement;
65 class EmbAJAXContainerBase;
66 class EmbAJAXPageBase;
67 
72 class EmbAJAXBase {
73 public:
74  virtual void print() const = 0;
77  static void setDriver(EmbAJAXOutputDriverBase *driver) {
78  _driver = driver;
79  }
87  virtual bool sendUpdates(uint16_t since, bool first) {
88  return false;
89  }
93  return 0;
94  }
97  void setVisible(bool visible) {
98  setBasicProperty(Visibility, visible);
99  }
102  void setEnabled(bool enabled) {
103  setBasicProperty(Enabledness, enabled);
104  }
105  enum Property {
106  Visibility=0,
107  Enabledness=1,
108  Value=2,
109  FirstElementSpecificProperty=3,
110  HTMLAllowed=7
111  };
114  virtual EmbAJAXElement* findChild(const char*id) const {
115  return 0;
116  }
117 protected:
118 template<size_t NUM> friend class EmbAJAXContainer;
119  virtual void setBasicProperty(uint8_t num, bool status) {};
120 
121  static EmbAJAXOutputDriverBase *_driver;
122  static char itoa_buf[8];
123  constexpr static const char null_string[1] = "";
124 
126  void printChildren(EmbAJAXBase** children, size_t num) const;
128  bool sendUpdates(EmbAJAXBase** children, size_t num, uint16_t since, bool first);
130  EmbAJAXElement* findChild(EmbAJAXBase** children, size_t num, const char*id) const;
132  void printPage(EmbAJAXBase** children, size_t num, const char* _title, const char* _header, uint16_t _min_interval) const;
134  void handleRequest(EmbAJAXBase** children, size_t num, void (*change_callback)());
135 };
136 
148 public:
150  _revision = 1;
151  next_revision = _revision;
152  }
153 
154  virtual void printHeader(bool html) = 0;
155  virtual void printContent(const char *content) = 0;
156  virtual const char* getArg(const char* name, char* buf, int buflen) = 0;
161  virtual void installPage(EmbAJAXPageBase *page, const char *path, void (*change_callback)()=0) = 0;
163  virtual void loopHook() = 0;
164 
165  uint16_t revision() const {
166  return _revision;
167  }
168  uint16_t setChanged() {
169  next_revision = _revision+1;
170  return (next_revision);
171  }
172  void nextRevision() {
173  _revision = next_revision;
174  }
176  enum QuoteMode {
179  HTMLQuoted
180  };
190  void printFiltered(const char* value, QuoteMode quoted, bool HTMLescaped) {
191  _printFiltered(value, quoted, HTMLescaped);
192  commitBuffer();
193  }
195  inline void printJSQuoted (const char* value) { printFiltered (value, JSQuoted, false); }
197  inline void printHTMLQuoted (const char* value) { printFiltered (value, HTMLQuoted, false); }
205  void printAttribute(const char* name, const char* value);
213  void printAttribute(const char* name, const int32_t value);
220  void _printContentF(const char* fmt, ...);
221 #if USE_PROGMEM_STRINGS
222  void _printContentF(const __FlashStringHelper*, ...);
223 #endif
224 private:
225  void _printFiltered(const char* value, QuoteMode quoted, bool HTMLescaped);
226  void _printContent(const char* content);
227  void _printChar(const char content);
228  void commitBuffer();
229  const int _bufsize = 64;
230  char _buf[64];
231  int _bufpos = 0;
232  uint16_t _revision;
233  uint16_t next_revision;
234 };
235 
240 #define MAKE_EmbAJAXPage(name, title, header_add, ...) \
241  EmbAJAXBase* name##_elements[] = {__VA_ARGS__}; \
242  EmbAJAXPage<sizeof(name##_elements)/sizeof(EmbAJAXBase*)> name(name##_elements, title, header_add);
243 
248 class EmbAJAXStatic : public EmbAJAXBase {
249 public:
251  EmbAJAXStatic(const char* content) {
252  _content = content;
253  }
254  void print() const override {
255  _driver->printContent(_content);
256  }
257 protected:
258  const char* _content;
259 };
260 
269 public:
274  EmbAJAXConnectionIndicator(const char* content_ok = default_ok, const char* content_fail = default_fail) {
275  _content_ok = content_ok;
276  _content_fail = content_fail;
277  }
278  void print() const override;
279  static constexpr const char* default_ok = {"<span style=\"background-color:green;\">OK</span>"};
280  static constexpr const char* default_fail = {"<span style=\"background-color:red;\">FAIL</span>"};
281 private:
282  const char* _content_ok;
283  const char* _content_fail;
284 };
285 
296 class EmbAJAXElement : public EmbAJAXBase {
297 public:
299  EmbAJAXElement(const char* id);
300 
301  const char* id() const {
302  return _id;
303  }
304  bool sendUpdates(uint16_t since, bool first) override;
305 
309  virtual const char* value(uint8_t which = EmbAJAXBase::Value) const {
310  if (which == EmbAJAXBase::Visibility) return (basicProperty (EmbAJAXBase::Visibility) ? "" : "none");
311  if (which == EmbAJAXBase::Enabledness) return (basicProperty (EmbAJAXBase::Enabledness) ? "" : "disabled");
312  return 0;
313  }
314 
317  virtual bool valueNeedsEscaping(uint8_t which = EmbAJAXBase::Value) const {
318  return false;
319  }
320 
324  virtual const char* valueProperty(uint8_t which = EmbAJAXBase::Value) const {
325  if (which == EmbAJAXBase::Visibility) return ("style.display");
326  if (which == EmbAJAXBase::Enabledness) return ("disabled");
327  return 0;
328  }
329 
332  virtual void updateFromDriverArg(const char* argname) {
333  return;
334  }
335 
336  EmbAJAXElement *toElement() override final {
337  return this;
338  }
339 protected:
340  void setBasicProperty(uint8_t num, bool status) override;
341  bool basicProperty(uint8_t num) const {
342  return (_flags & (1 << num));
343  }
344  byte _flags;
345 template<size_t NUM> friend class EmbAJAXPage;
346 friend class EmbAJAXBase;
347  const char* _id;
348  void setChanged();
349  bool changed(uint16_t since);
351  void printTextInput(size_t size, const char* value) const;
352 private:
353  uint16_t revision;
354 };
355 
358 public:
359  EmbAJAXMutableSpan(const char* id) : EmbAJAXElement(id) {
360  _value = 0;
361  }
362  void print() const override;
363  const char* value(uint8_t which = EmbAJAXBase::Value) const override;
364  const char* valueProperty(uint8_t which = EmbAJAXBase::Value) const override;
373  void setValue(const char* value, bool allowHTML = false);
374  bool valueNeedsEscaping(uint8_t which=EmbAJAXBase::Value) const override;
375 private:
376  const char* _value;
377 };
378 
386 template<size_t SIZE> class EmbAJAXTextInput : public EmbAJAXElement {
387 public:
388  EmbAJAXTextInput(const char* id) : EmbAJAXElement(id) {
389  _value[0] = '\0';
390  }
391  void print() const override {
392  EmbAJAXElement::printTextInput(SIZE, _value);
393  }
394  const char* value(uint8_t which = EmbAJAXBase::Value) const override {
395  if (which == EmbAJAXBase::Value) return _value;
396  return EmbAJAXElement::value(which);
397  }
398  const char* valueProperty(uint8_t which = EmbAJAXBase::Value) const override {
399  if (which == EmbAJAXBase::Value) return "value";
400  return EmbAJAXElement::valueProperty(which);
401  }
404  void setValue(const char* value) {
405  strncpy(_value, value, SIZE);
406  setChanged();
407  }
408  void updateFromDriverArg(const char* argname) override {
409  _driver->getArg(argname, _value, SIZE);
410  }
411 protected:
412  char _value[SIZE];
413 };
414 
417 public:
418  EmbAJAXSlider(const char* id, int16_t min, int16_t max, int16_t initial);
419  void print() const override;
420  const char* value(uint8_t which = EmbAJAXBase::Value) const override;
421  const char* valueProperty(uint8_t which = EmbAJAXBase::Value) const override;
422  void setValue(int16_t value);
423  int16_t intValue() const {
424  return _value;
425  }
426  void updateFromDriverArg(const char* argname) override;
427 private:
428  int16_t _min, _max, _value;
429 };
430 
433 public:
438  EmbAJAXColorPicker(const char* id, uint8_t r, uint8_t g, uint8_t b);
439  void print() const override;
440  const char* value(uint8_t which = EmbAJAXBase::Value) const override;
441  const char* valueProperty(uint8_t which = EmbAJAXBase::Value) const override;
442  void setColor(uint8_t r, uint8_t g, uint8_t b);
443  uint8_t red() const;
444  uint8_t green() const;
445  uint8_t blue() const;
446  void updateFromDriverArg(const char* argname) override;
447 private:
448  uint8_t _r, _g, _b;
449 };
450 
455 public:
458  EmbAJAXPushButton(const char* id, const char* label, void (*callback)(EmbAJAXPushButton*));
459  void print() const override;
468  void setText(const char* label, bool allowHTML = false);
469  const char* value(uint8_t which = EmbAJAXBase::Value) const override;
470  const char* valueProperty(uint8_t which = EmbAJAXBase::Value) const override;
471  bool valueNeedsEscaping(uint8_t which=EmbAJAXBase::Value) const override;
472  void updateFromDriverArg(const char* argname) override;
473 protected:
474  void (*_callback)(EmbAJAXPushButton*);
475  const char* _label;
476 };
477 
487 public:
493  EmbAJAXMomentaryButton(const char* id, const char* label, uint16_t timeout=600, void (*callback)(EmbAJAXPushButton*)=0);
494  void print() const override;
495  enum Status {
496  Pressed,
497  MaybePressed,
498  Released
499  };
500  Status status() const;
501  void updateFromDriverArg(const char* argname) override;
502 private:
503  uint32_t latest_ping;
504  uint16_t _timeout;
505 };
506 
508 
514 public:
515  EmbAJAXCheckButton(const char* id, const char* label, bool checked=false);
516  void print() const override;
517  const char* value(uint8_t which = EmbAJAXBase::Value) const override;
518  const char* valueProperty(uint8_t which = EmbAJAXBase::Value) const override;
519  void setChecked(bool checked);
520  bool isChecked() const {
521  return _checked;
522  }
523  void updateFromDriverArg(const char* argname) override;
524 private:
525  bool _checked;
526  const char* _label;
527 template<size_t NUM> friend class EmbAJAXRadioGroup;
529  EmbAJAXRadioGroupBase* radiogroup;
530 };
531 
534 protected:
536 friend class EmbAJAXCheckButton;
537  virtual void selectButton(EmbAJAXCheckButton* which) = 0;
538  const char* _name;
539 };
540 
542 template<size_t NUM> class EmbAJAXContainer : public EmbAJAXBase {
543 public:
544  EmbAJAXContainer(EmbAJAXBase *children[NUM]) : EmbAJAXBase() {
545  _children = children;
546  }
547  void print() const override {
548  EmbAJAXBase::printChildren(_children, NUM);
549  }
550  bool sendUpdates(uint16_t since, bool first) override {
551  return EmbAJAXBase::sendUpdates(_children, NUM, since, first);
552  }
554  EmbAJAXElement* findChild(const char*id) const override final {
555  return EmbAJAXBase::findChild(_children, NUM, id);
556  }
557 protected:
558  void setBasicProperty(uint8_t num, bool status) override {
559  for (uint8_t i = 0; i < NUM; ++i) {
560  _children[i]->setBasicProperty(num, status);
561  }
562  }
563 template<size_t> friend class EmbAJAXHideableContainer;
564  EmbAJAXContainer() {};
565  EmbAJAXBase** _children;
566 };
567 
581 template<size_t NUM> class EmbAJAXHideableContainer : public EmbAJAXElement {
582 public:
583  EmbAJAXHideableContainer(const char* id, EmbAJAXBase *children[NUM]) : EmbAJAXElement(id) {
584  _childlist = EmbAJAXContainer<NUM>(children);
585  }
586  void print() const override {
587  _driver->printFormatted("<div id=", HTML_QUOTED_STRING(_id), ">");
588  _childlist.print();
589  _driver->printContent("</div>");
590  }
591  EmbAJAXElement* findChild(const char* id) const override {
592  return _childlist.findChild(id);
593  }
594  bool sendUpdates(uint16_t since, bool first) override {
595  bool sent = EmbAJAXElement::sendUpdates(since, first);
596  bool sent2 = _childlist.sendUpdates(since, first && !sent);
597  return sent || sent2;
598  }
599 protected:
600  void setBasicProperty(uint8_t num, bool status) override {
601  EmbAJAXElement::setBasicProperty(num, status);
602  _childlist.setBasicProperty(num, status);
603  }
604  EmbAJAXContainer<NUM> _childlist;
605 };
606 
612 template<size_t NUM> class EmbAJAXRadioGroup : public EmbAJAXContainer<NUM>, public EmbAJAXRadioGroupBase {
613 public:
619  EmbAJAXRadioGroup(const char* id_base, const char* options[NUM], uint8_t selected_option = 0) : EmbAJAXContainer<NUM>(), EmbAJAXRadioGroupBase() {
620  for (uint8_t i = 0; i < NUM; ++i) {
621  char* childid = childids[i];
622  strncpy(childid, id_base, EMBAJAX_MAX_ID_LEN-4);
623  itoa(i, &(childid[strlen(childid)]), 10);
624  buttons[i] = EmbAJAXCheckButton(childid, options[i], i == selected_option);
625  buttons[i].radiogroup = this;
626  buttonpointers[i] = &buttons[i];
627  }
628  _current_option = selected_option;
629  EmbAJAXContainer<NUM>::_children = buttonpointers; // Hm, why do I need to specify EmbAJAXContainer<NUM>::, explicitly?
630  _name = id_base;
631  }
633  void selectOption(uint8_t num) {
634  for (uint8_t i = 0; i < NUM; ++i) {
635  buttons[i].setChecked(i == num);
636  }
637  _current_option = num; // NOTE: might be outside of range, but that's ok, signifies "none selected"
638  }
640  uint8_t selectedOption() const {
641  return _current_option;
642  }
645  EmbAJAXBase* button(uint8_t num) {
646  if (num < NUM) return (&buttons[num]);
647  return 0;
648  }
649 private:
650  EmbAJAXCheckButton buttons[NUM];
651  EmbAJAXBase* buttonpointers[NUM];
652  char childids[NUM][EMBAJAX_MAX_ID_LEN];
653  int8_t _current_option;
654  void selectButton(EmbAJAXCheckButton* which) override {
655  _current_option = -1;
656  for (uint8_t i = 0; i < NUM; ++i) {
657  if (which == buttonpointers[i]) {
658  _current_option = i;
659  } else {
660  buttons[i].setChecked(false);
661  }
662  }
663  }
664 };
665 
668 public:
670  void selectOption(uint8_t num);
672  uint8_t selectedOption() const;
673  const char* value(uint8_t which = EmbAJAXBase::Value) const override;
674  const char* valueProperty(uint8_t which = EmbAJAXBase::Value) const override;
675  void updateFromDriverArg(const char* argname) override;
676 protected:
677  EmbAJAXOptionSelectBase(const char*id, uint8_t current_option) : EmbAJAXElement(id) {
678  _current_option = current_option;
679  };
680  void print(const char* const* _labels, uint8_t NUM) const;
681  uint8_t _current_option;
682 };
683 
688 template<size_t NUM> class EmbAJAXOptionSelect : public EmbAJAXOptionSelectBase {
689 public:
694  EmbAJAXOptionSelect(const char* id, const char* labels[NUM], uint8_t selected_option = 0) : EmbAJAXOptionSelectBase(id, selected_option) {
695  for (uint8_t i = 0; i < NUM; ++i) {
696  _labels[i] = labels[i];
697  }
698  }
699  void print() const override {
700  EmbAJAXOptionSelectBase::print(_labels, NUM);
701  }
702 private:
703  const char* _labels[NUM];
704 };
705 
710 public:
711  virtual void handleRequest(void (*change_callback)()=0) = 0;
712  virtual void printPage() = 0;
713 };
714 
721 template<size_t NUM> class EmbAJAXPage : public EmbAJAXContainer<NUM>, public EmbAJAXPageBase {
722 public:
728  EmbAJAXPage(EmbAJAXBase* children[NUM], const char* title, const char* header_add = 0, uint16_t min_interval=100) : EmbAJAXContainer<NUM>(children),
729  _title(title ? title : EmbAJAXBase::null_string), _header_add(header_add ? header_add : EmbAJAXBase::null_string), _min_interval(min_interval) {}
731  void printPage() override {
732  print();
733  }
736  void print() const override {
737  EmbAJAXBase::printPage(EmbAJAXContainer<NUM>::_children, NUM, _title, _header_add, _min_interval);
738  }
747  void handleRequest(void (*change_callback)()=0) override {
748  _latest_ping = millis();
750  }
754  bool hasActiveClient(uint64_t latency_ms=5000) const {
755  return(_latest_ping && (_latest_ping + latency_ms > millis()));
756  }
757 protected:
758  const char* _title;
759  const char* _header_add;
760  uint16_t _min_interval;
761  uint64_t _latest_ping = 0;
762 };
763 
764 // If the user has not #includ'ed a specific output driver implementation, make a good guess, here
765 #if not defined (EMBAJAX_OUTUPUTDRIVER_IMPLEMENTATION)
766 #if defined (ESP8266)
767 #include "EmbAJAXOutputDriverESP8266.h"
768 #elif defined (ESP32)
769 #include "EmbAJAXOutputDriverESP32.h"
770 #elif defined (ARDUINO_ARCH_RP2040)
771 #include "EmbAJAXOutputDriverRP2040.h"
772 #else
773 #include <WebServer.h>
774 #define EmbAJAXOutputDriverWebServerClass WebServer
775 #include <WiFi.h>
776 #include "EmbAJAXOutputDriverGeneric.h"
777 #warning No output driver available for this hardware (yet). We try using the generic driver, but success is not guaranteed.
778 #warning In most cases, implementing a driver is as easy as picking the correct header file to include. Please consider submitting a patch.
779 #endif
780 #endif
781 
782 #endif
#define EMBAJAX_MAX_ID_LEN
Definition: EmbAJAX.h:27
Abstract base class for anything shown on an EmbAJAXPage.
Definition: EmbAJAX.h:72
virtual bool sendUpdates(uint16_t since, bool first)
Definition: EmbAJAX.h:87
void setEnabled(bool enabled)
Definition: EmbAJAX.h:102
static void setDriver(EmbAJAXOutputDriverBase *driver)
Definition: EmbAJAX.h:77
void printChildren(EmbAJAXBase **children, size_t num) const
Definition: EmbAJAX.cpp:212
void printPage(EmbAJAXBase **children, size_t num, const char *_title, const char *_header, uint16_t _min_interval) const
Definition: EmbAJAX.cpp:532
void handleRequest(EmbAJAXBase **children, size_t num, void(*change_callback)())
Definition: EmbAJAX.cpp:614
void setVisible(bool visible)
Definition: EmbAJAX.h:97
virtual EmbAJAXElement * toElement()
Definition: EmbAJAX.h:92
virtual EmbAJAXElement * findChild(const char *id) const
Definition: EmbAJAX.h:114
A checkable (option) button.
Definition: EmbAJAX.h:513
const char * value(uint8_t which=EmbAJAXBase::Value) const override
Definition: EmbAJAX.cpp:472
void updateFromDriverArg(const char *argname) override
Definition: EmbAJAX.cpp:477
const char * valueProperty(uint8_t which=EmbAJAXBase::Value) const override
Definition: EmbAJAX.cpp:484
A color picker element (<input type="color">)
Definition: EmbAJAX.h:432
const char * valueProperty(uint8_t which=EmbAJAXBase::Value) const override
Definition: EmbAJAX.cpp:333
void updateFromDriverArg(const char *argname) override
Definition: EmbAJAX.cpp:365
const char * value(uint8_t which=EmbAJAXBase::Value) const override
Definition: EmbAJAX.cpp:323
EmbAJAXColorPicker(const char *id, uint8_t r, uint8_t g, uint8_t b)
Definition: EmbAJAX.cpp:305
connection status indicator
Definition: EmbAJAX.h:268
EmbAJAXConnectionIndicator(const char *content_ok=default_ok, const char *content_fail=default_fail)
Definition: EmbAJAX.h:274
Base class for groups of objects.
Definition: EmbAJAX.h:542
EmbAJAXElement * findChild(const char *id) const override final
Definition: EmbAJAX.h:554
bool sendUpdates(uint16_t since, bool first) override
Definition: EmbAJAX.h:550
Abstract base class for modifiable elements.
Definition: EmbAJAX.h:296
virtual void updateFromDriverArg(const char *argname)
Definition: EmbAJAX.h:332
virtual bool valueNeedsEscaping(uint8_t which=EmbAJAXBase::Value) const
Definition: EmbAJAX.h:317
virtual const char * value(uint8_t which=EmbAJAXBase::Value) const
Definition: EmbAJAX.h:309
EmbAJAXElement * toElement() override final
Definition: EmbAJAX.h:336
void printTextInput(size_t size, const char *value) const
Definition: EmbAJAX.cpp:204
virtual const char * valueProperty(uint8_t which=EmbAJAXBase::Value) const
Definition: EmbAJAX.h:324
EmbAJAXElement(const char *id)
Definition: EmbAJAX.cpp:160
bool sendUpdates(uint16_t since, bool first) override
Definition: EmbAJAX.cpp:166
A list of objects that can be hidden, completely.
Definition: EmbAJAX.h:581
EmbAJAXElement * findChild(const char *id) const override
Definition: EmbAJAX.h:591
bool sendUpdates(uint16_t since, bool first) override
Definition: EmbAJAX.h:594
A momentary "press-and-hold" button.
Definition: EmbAJAX.h:486
EmbAJAXMomentaryButton(const char *id, const char *label, uint16_t timeout=600, void(*callback)(EmbAJAXPushButton *)=0)
Definition: EmbAJAX.cpp:418
void updateFromDriverArg(const char *argname) override
Definition: EmbAJAX.cpp:440
An HTML span element with content that can be updated from the server (not the client)
Definition: EmbAJAX.h:357
bool valueNeedsEscaping(uint8_t which=EmbAJAXBase::Value) const override
Definition: EmbAJAX.cpp:251
const char * valueProperty(uint8_t which=EmbAJAXBase::Value) const override
Definition: EmbAJAX.cpp:256
void setValue(const char *value, bool allowHTML=false)
Definition: EmbAJAX.cpp:261
const char * value(uint8_t which=EmbAJAXBase::Value) const override
Definition: EmbAJAX.cpp:246
Abstract base class for EmbAJAXOptionSelect.
Definition: EmbAJAX.h:667
void updateFromDriverArg(const char *argname) override
Definition: EmbAJAX.cpp:526
const char * valueProperty(uint8_t which=EmbAJAXBase::Value) const override
Definition: EmbAJAX.cpp:521
uint8_t selectedOption() const
Definition: EmbAJAX.cpp:512
const char * value(uint8_t which=EmbAJAXBase::Value) const override
Definition: EmbAJAX.cpp:516
void selectOption(uint8_t num)
Definition: EmbAJAX.cpp:507
Drop-down list of selectable options.
Definition: EmbAJAX.h:688
EmbAJAXOptionSelect(const char *id, const char *labels[NUM], uint8_t selected_option=0)
Definition: EmbAJAX.h:694
Abstract base class for output drivers/server implementations.
Definition: EmbAJAX.h:147
virtual void loopHook()=0
void printAttribute(const char *name, const char *value)
Definition: EmbAJAX.cpp:137
virtual void installPage(EmbAJAXPageBase *page, const char *path, void(*change_callback)()=0)=0
void _printContentF(const char *fmt,...)
Definition: EmbAJAX.cpp:97
void printJSQuoted(const char *value)
Definition: EmbAJAX.h:195
QuoteMode
Definition: EmbAJAX.h:176
@ JSQuoted
Will be quoted suitable for JavaScript.
Definition: EmbAJAX.h:178
@ HTMLQuoted
Will be quoted suitable for HTML attributes.
Definition: EmbAJAX.h:179
@ NotQuoted
Will not be quoted.
Definition: EmbAJAX.h:177
void printFiltered(const char *value, QuoteMode quoted, bool HTMLescaped)
Definition: EmbAJAX.h:190
void printHTMLQuoted(const char *value)
Definition: EmbAJAX.h:197
Absrract internal helper class.
Definition: EmbAJAX.h:709
The main interface class.
Definition: EmbAJAX.h:721
void printPage() override
Definition: EmbAJAX.h:731
EmbAJAXPage(EmbAJAXBase *children[NUM], const char *title, const char *header_add=0, uint16_t min_interval=100)
Definition: EmbAJAX.h:728
void handleRequest(void(*change_callback)()=0) override
Definition: EmbAJAX.h:747
void print() const override
Definition: EmbAJAX.h:736
bool hasActiveClient(uint64_t latency_ms=5000) const
Definition: EmbAJAX.h:754
A push-button.
Definition: EmbAJAX.h:454
void setText(const char *label, bool allowHTML=false)
Definition: EmbAJAX.cpp:391
void updateFromDriverArg(const char *argname) override
Definition: EmbAJAX.cpp:412
const char * valueProperty(uint8_t which=EmbAJAXBase::Value) const override
Definition: EmbAJAX.cpp:407
const char * value(uint8_t which=EmbAJAXBase::Value) const override
Definition: EmbAJAX.cpp:397
bool valueNeedsEscaping(uint8_t which=EmbAJAXBase::Value) const override
Definition: EmbAJAX.cpp:402
EmbAJAXPushButton(const char *id, const char *label, void(*callback)(EmbAJAXPushButton *))
Definition: EmbAJAX.cpp:378
abstract base for EmbAJAXRadioGroup, needed for internal reasons.
Definition: EmbAJAX.h:533
A set of radio buttons (mutally exclusive buttons), e.g. for on/off, or low/mid/high,...
Definition: EmbAJAX.h:612
uint8_t selectedOption() const
Definition: EmbAJAX.h:640
EmbAJAXBase * button(uint8_t num)
Definition: EmbAJAX.h:645
EmbAJAXRadioGroup(const char *id_base, const char *options[NUM], uint8_t selected_option=0)
Definition: EmbAJAX.h:619
void selectOption(uint8_t num)
Definition: EmbAJAX.h:633
An HTML span element with content that can be updated from the server (not the client)
Definition: EmbAJAX.h:416
void updateFromDriverArg(const char *argname) override
Definition: EmbAJAX.cpp:292
const char * value(uint8_t which=EmbAJAXBase::Value) const override
Definition: EmbAJAX.cpp:282
const char * valueProperty(uint8_t which=EmbAJAXBase::Value) const override
Definition: EmbAJAX.cpp:287
A static chunk of HTML.
Definition: EmbAJAX.h:248
EmbAJAXStatic(const char *content)
Definition: EmbAJAX.h:251
A text input field.
Definition: EmbAJAX.h:386
void setValue(const char *value)
Definition: EmbAJAX.h:404
void updateFromDriverArg(const char *argname) override
Definition: EmbAJAX.h:408
const char * valueProperty(uint8_t which=EmbAJAXBase::Value) const override
Definition: EmbAJAX.h:398
const char * value(uint8_t which=EmbAJAXBase::Value) const override
Definition: EmbAJAX.h:394
#define HTML_QUOTED_STRING(X)
Definition: macro_definitions.h:49