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).
Public Member Functions | Protected Member Functions | Protected Attributes | Friends | List of all members
EmbAJAXElement Class Reference

Abstract base class for modifiable elements. More...

#include <EmbAJAX.h>

Inheritance diagram for EmbAJAXElement:
Inheritance graph
[legend]
Collaboration diagram for EmbAJAXElement:
Collaboration graph
[legend]

Public Member Functions

 EmbAJAXElement (const char *id)
 
const char * id () const
 
bool sendUpdates (uint16_t since, bool first) override
 
virtual const char * value (uint8_t which=EmbAJAXBase::Value) const
 
virtual bool valueNeedsEscaping (uint8_t which=EmbAJAXBase::Value) const
 
virtual const char * valueProperty (uint8_t which=EmbAJAXBase::Value) const
 
virtual void updateFromDriverArg (const char *argname)
 
EmbAJAXElementtoElement () override final
 
- Public Member Functions inherited from EmbAJAXBase
virtual void print () const =0
 
void setVisible (bool visible)
 
void setEnabled (bool enabled)
 
virtual EmbAJAXElementfindChild (const char *id) const
 

Protected Member Functions

void setBasicProperty (uint8_t num, bool status) override
 
bool basicProperty (uint8_t num) const
 
void setChanged ()
 
bool changed (uint16_t since)
 
void printTextInput (size_t size, const char *value) const
 
- Protected Member Functions inherited from EmbAJAXBase
void printChildren (EmbAJAXBase **children, size_t num) const
 
bool sendUpdates (EmbAJAXBase **children, size_t num, uint16_t since, bool first)
 
EmbAJAXElementfindChild (EmbAJAXBase **children, size_t num, const char *id) const
 
void printPage (EmbAJAXBase **children, size_t num, const char *_title, const char *_header, uint16_t _min_interval) const
 
void handleRequest (EmbAJAXBase **children, size_t num, void(*change_callback)())
 

Protected Attributes

byte _flags
 
const char * _id
 

Friends

template<size_t NUM>
class EmbAJAXPage
 
class EmbAJAXBase
 

Additional Inherited Members

- Public Types inherited from EmbAJAXBase
enum  Property {
  Visibility , Enabledness , Value , FirstElementSpecificProperty ,
  HTMLAllowed
}
 
- Static Public Member Functions inherited from EmbAJAXBase
static void setDriver (EmbAJAXOutputDriverBase *driver)
 
- Static Protected Attributes inherited from EmbAJAXBase
static EmbAJAXOutputDriverBase_driver
 
static char itoa_buf [8]
 
constexpr static const char null_string [1]
 

Detailed Description

Abstract base class for modifiable elements.

Abstract Base class for objects that can be changed, either from the server, or from both the client and the server. To create a derived class, you will need to provide appropriate implementations of print(), value(), and valueProperty(). Further, you will most likely want to add a function like setValue() for control from the server. If the element is to receive updates from the client side, you will a) have to include an appropriate onChange-call in print(), and b) provide a non-empty implementation of updateFromDriverArg().

Best look at a simple example such as EmbAJAXMutableSpan or EmbAJAXSlider for details.

Constructor & Destructor Documentation

◆ EmbAJAXElement()

EmbAJAXElement::EmbAJAXElement ( const char *  id)
Parameters
idThe id for the element. Note that the string is not copied. Do not use a temporary string in this place. Also, do keep it short.

Member Function Documentation

◆ printTextInput()

void EmbAJAXElement::printTextInput ( size_t  size,
const char *  value 
) const
protected

Filthy trick to keep (template) implementation out of the header. See EmbAJAXTextInput::print()

◆ sendUpdates()

bool EmbAJAXElement::sendUpdates ( uint16_t  since,
bool  first 
)
overridevirtual

serialize pending changes for the client. Virtual so you could customize it, completely, but instead you probably want to override EmbAJAXElement::valueProperty(), only, instead.

Parameters
sincerevision number last sent to the server. Send only changes that occured since this revision.
firstif false, and this object writes any update, it should write a ',', first.
Returns
true if anything has been written, false otherwise.

Reimplemented from EmbAJAXBase.

Reimplemented in EmbAJAXHideableContainer< NUM >.

◆ toElement()

EmbAJAXElement* EmbAJAXElement::toElement ( )
inlinefinaloverridevirtual

Cast this object to EmbAJAXElement if it is a controllable element.

Returns
0, if this is not a controllable element.

Reimplemented from EmbAJAXBase.

◆ updateFromDriverArg()

virtual void EmbAJAXElement::updateFromDriverArg ( const char *  argname)
inlinevirtual

override this in your derived class to allow updates to be propagated from client to server (if wanted). The implementation need not call setChanged().

Reimplemented in EmbAJAXScriptedSpan, EmbAJAXOptionSelectBase, EmbAJAXCheckButton, EmbAJAXMomentaryButton, EmbAJAXPushButton, EmbAJAXColorPicker, EmbAJAXSlider, EmbAJAXTextInput< SIZE >, and EmbAJAXJoystick.

◆ value()

virtual const char* EmbAJAXElement::value ( uint8_t  which = EmbAJAXBase::Value) const
inlinevirtual

const char representation of the current server side value. Must be implemented in derived class. This base class handles visibility and enabledness, only. Do call the base implementation for any "which" that is not handled in your derived class.

Reimplemented in EmbAJAXScriptedSpan, EmbAJAXJoystick, EmbAJAXOptionSelectBase, EmbAJAXCheckButton, EmbAJAXPushButton, EmbAJAXColorPicker, EmbAJAXSlider, EmbAJAXTextInput< SIZE >, and EmbAJAXMutableSpan.

◆ valueNeedsEscaping()

virtual bool EmbAJAXElement::valueNeedsEscaping ( uint8_t  which = EmbAJAXBase::Value) const
inlinevirtual

Returns true, if the value may contain HTML, and needs HTML escaping when passed to the client. Base implementation simply returns false.

Reimplemented in EmbAJAXPushButton, and EmbAJAXMutableSpan.

◆ valueProperty()

virtual const char* EmbAJAXElement::valueProperty ( uint8_t  which = EmbAJAXBase::Value) const
inlinevirtual

The JS property that will have to be set on the client. Must be implemented in derived class. This base class handles visibility and enabledness, only. Do call the base implementation for any "which" that is not handled in your derived class.

Reimplemented in EmbAJAXScriptedSpan, EmbAJAXJoystick, EmbAJAXOptionSelectBase, EmbAJAXCheckButton, EmbAJAXPushButton, EmbAJAXColorPicker, EmbAJAXSlider, EmbAJAXTextInput< SIZE >, and EmbAJAXMutableSpan.


The documentation for this class was generated from the following files: