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 | List of all members
EmbAJAXScriptedSpan Class Reference

A span element containing a custom javascript script, meant to creating custom dispays. More...

#include <EmbAJAXScriptedSpan.h>

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

Public Member Functions

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

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)
 
- Protected Member Functions inherited from EmbAJAXElement
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 inherited from EmbAJAXElement
byte _flags
 
const char * _id
 
- Static Protected Attributes inherited from EmbAJAXBase
static EmbAJAXOutputDriverBase_driver
 
static char itoa_buf [8]
 
constexpr static const char null_string [1]
 

Detailed Description

A span element containing a custom javascript script, meant to creating custom dispays.

This class creates a element containing a custom script. The script to use is passed in the constructor. The span element itself is accessible using "this", inside the script.

The script may contain "this.receiveValue = function(value) { [...] };". This function will then be called, when the value is changed from the server.

If the scripted object allows the user to make changes, the script should call "this.sendValue(value);", when the value has changed. You will also have to set a large enough receive buffer in the constructor in this case!

Warning
This class is new, and its API may not be quite stable at the time of this writing. Feedback welcome.

Constructor & Destructor Documentation

◆ EmbAJAXScriptedSpan()

EmbAJAXScriptedSpan::EmbAJAXScriptedSpan ( const char *  id,
const char *  script,
char *  rec_buffer = 0,
size_t  rec_buffer_size = 0 
)
inline

Constructor. See the class description for some detail on how to provide a script.

Parameters
idunique id of the span
scriptthe script code. See the class description for details.
rec_bufferif the script supplies values to the server (via
this.sendValue(x);
in the script), a receive buffer is needed hold that value. Pass a pointer to a suitably sized buffer.
rec_buffer_sizesize of the rec_buffer.

Member Function Documentation

◆ setValue()

void EmbAJAXScriptedSpan::setValue ( const char *  value)
inline

Send the given value to the client side script. Note that if you call this very often, the client will probably not see every value. It will only get to see the latest value that was set on each poll.

Further note that as of this writing, EmbAJAX does not check whether the value is actually changed, when you call this. You can avoid network overhead by making sure to call setValue(), only when something has actually changed. This may be changed in a future version of EmbAJAX.

For safety, the value string is always quoted when sending it to the client. This is not a problem as long as you are sending strings or plain numbers. To send more complex objects (such as an array, or even a function), your receiveValue() function should contain a call to eval().

Parameters
valueNote: The string is not copied, so don't make this a temporary.

◆ updateFromDriverArg()

void EmbAJAXScriptedSpan::updateFromDriverArg ( const char *  argname)
inlineoverridevirtual

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 from EmbAJAXElement.

◆ value()

const char* EmbAJAXScriptedSpan::value ( uint8_t  which = EmbAJAXBase::Value) const
inlineoverridevirtual

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 from EmbAJAXElement.

◆ valueProperty()

const char* EmbAJAXScriptedSpan::valueProperty ( uint8_t  which = EmbAJAXBase::Value) const
inlineoverridevirtual

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 from EmbAJAXElement.


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