27 #define EMBAJAX_MAX_ID_LEN 16
53 #if !defined USE_PROGMEM_STRINGS
54 #if defined(memcpy_P) && (memcpy_P == memcpy)
55 #define USE_PROGMEM_STRINGS 0
57 #define USE_PROGMEM_STRINGS 1
65 class EmbAJAXContainerBase;
74 virtual void print()
const = 0;
98 setBasicProperty(Visibility, visible);
103 setBasicProperty(Enabledness, enabled);
109 FirstElementSpecificProperty=3,
119 virtual void setBasicProperty(uint8_t num,
bool status) {};
122 static char itoa_buf[8];
123 constexpr
static const char null_string[1] =
"";
132 void printPage(
EmbAJAXBase** children,
size_t num,
const char* _title,
const char* _header, uint16_t _min_interval)
const;
151 next_revision = _revision;
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;
165 uint16_t revision()
const {
168 uint16_t setChanged() {
169 next_revision = _revision+1;
170 return (next_revision);
172 void nextRevision() {
173 _revision = next_revision;
191 _printFiltered(value, quoted, HTMLescaped);
221 #if USE_PROGMEM_STRINGS
225 void _printFiltered(
const char* value,
QuoteMode quoted,
bool HTMLescaped);
226 void _printContent(
const char* content);
227 void _printChar(
const char content);
229 const int _bufsize = 64;
233 uint16_t next_revision;
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);
254 void print()
const override {
255 _driver->printContent(_content);
258 const char* _content;
275 _content_ok = content_ok;
276 _content_fail = content_fail;
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>"};
282 const char* _content_ok;
283 const char* _content_fail;
301 const char* id()
const {
304 bool sendUpdates(uint16_t since,
bool first)
override;
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");
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");
340 void setBasicProperty(uint8_t num,
bool status)
override;
341 bool basicProperty(uint8_t num)
const {
342 return (_flags & (1 << num));
349 bool changed(uint16_t since);
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;
391 void print()
const override {
394 const char*
value(uint8_t which = EmbAJAXBase::Value)
const override {
395 if (which == EmbAJAXBase::Value)
return _value;
398 const char*
valueProperty(uint8_t which = EmbAJAXBase::Value)
const override {
399 if (which == EmbAJAXBase::Value)
return "value";
405 strncpy(_value,
value, SIZE);
409 _driver->getArg(argname, _value, SIZE);
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 {
428 int16_t _min, _max, _value;
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);
444 uint8_t green()
const;
445 uint8_t blue()
const;
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;
494 void print()
const override;
500 Status status()
const;
503 uint32_t latest_ping;
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 {
545 _children = children;
547 void print()
const override {
558 void setBasicProperty(uint8_t num,
bool status)
override {
559 for (uint8_t i = 0; i < NUM; ++i) {
560 _children[i]->setBasicProperty(num, status);
586 void print()
const override {
589 _driver->printContent(
"</div>");
592 return _childlist.findChild(
id);
596 bool sent2 = _childlist.sendUpdates(since, first && !sent);
597 return sent || sent2;
600 void setBasicProperty(uint8_t num,
bool status)
override {
601 EmbAJAXElement::setBasicProperty(num, status);
602 _childlist.setBasicProperty(num, status);
620 for (uint8_t i = 0; i < NUM; ++i) {
621 char* childid = childids[i];
623 itoa(i, &(childid[strlen(childid)]), 10);
625 buttons[i].radiogroup =
this;
626 buttonpointers[i] = &buttons[i];
628 _current_option = selected_option;
634 for (uint8_t i = 0; i < NUM; ++i) {
635 buttons[i].setChecked(i == num);
637 _current_option = num;
641 return _current_option;
646 if (num < NUM)
return (&buttons[num]);
653 int8_t _current_option;
655 _current_option = -1;
656 for (uint8_t i = 0; i < NUM; ++i) {
657 if (which == buttonpointers[i]) {
660 buttons[i].setChecked(
false);
673 const char*
value(uint8_t which = EmbAJAXBase::Value)
const override;
674 const char*
valueProperty(uint8_t which = EmbAJAXBase::Value)
const override;
678 _current_option = current_option;
680 void print(
const char*
const* _labels, uint8_t NUM)
const;
681 uint8_t _current_option;
695 for (uint8_t i = 0; i < NUM; ++i) {
696 _labels[i] = labels[i];
699 void print()
const override {
700 EmbAJAXOptionSelectBase::print(_labels, NUM);
703 const char* _labels[NUM];
711 virtual void handleRequest(
void (*change_callback)()=0) = 0;
712 virtual void printPage() = 0;
729 _title(title ? title :
EmbAJAXBase::null_string), _header_add(header_add ? header_add :
EmbAJAXBase::null_string), _min_interval(min_interval) {}
748 _latest_ping = millis();
755 return(_latest_ping && (_latest_ping + latency_ms > millis()));
759 const char* _header_add;
760 uint16_t _min_interval;
761 uint64_t _latest_ping = 0;
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"
773 #include <WebServer.h>
774 #define EmbAJAXOutputDriverWebServerClass WebServer
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.
#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 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
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
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