Many of these are used internally and included here only for completeness. Once you become more expert, you may find some of them useful.
- Global Callbacks
- Global "lifecycle" functions
- h4p Utilities
- h4p Internal (not recommended)
- Logging Macros
These may be provided by the user if required
Function | Source | Purpose |
---|---|---|
const char* giveTaskName(uint32_t n); |
h4vm | Translate user's task ID to meaningful name see Example Sketch |
void h4UserLoop(void); |
H4 | 1x per loop - use with caution, requires H4 option setting. see Example Sketch |
h4pGlobalEventHandler(const string& svc,H4PE_TYPE t,const string& msg);` | various | Catch-all event handler. See Event Listeners, Event Emitters and logging |
h4pFactoryReset(); // Emits `H4PE_FACTORY` "Catch-all" handler in H4P_SerialCmd erases any stored configuration data (N.B. **NOT** the FS webserver files) then reboots the devicr
// Equivalent command: h4/factory
h4reboot(); // Emits `H4PE_REBOOT` "Catch-all" handler in H4P_SerialCmd reboots the device
// Equivalent command: h4/reboot
Other functions starting h4p
fall into two classes:
- Recommended for calling by user in the appropriate circumstances
- Used mostly internally and not recommended for general use unless you are an "expert"
The latter category are included only for the sake of completeness and should never be required by the user. They will be required by advanced users wishing to write their own plugins.
To save space and improve performance, H4P identifies all internal entities with numeric codes. Normally the user will never need to come across these, but if they do, they will mean very little. When debugging and testing it is useful to see the human-readable equivalents - which may mean a little more.
If #define H4P_VERBOSE 1
is included at the very top of the sketch, then the following functions will return human-readable values
std::string h4pgetErrorMessage(uint32_t e); // command errors
std::string h4pgetEventName (H4PE_TYPE e);
Users can name their own tasks: see Example Sketch showing it in use
If you have any string containing %name%
then the following function will return a new string with all of the %whatever%
placeholders replaced by the current vale of the global variable of the name between the % signs.
string h4preplaceparams(const string& s);
void h4pOnEvent(H4PE_TYPE t,H4P_FN_USEREVENT f);
Names a function f
(or defines a lambda) to handle the specific event type t
. If more than one event type needs to be monitored, use H4P_EventListener
void h4pUserEvent(const char* format,...);
Emits an event of type H4PE_USER
with a message made up from printf
-style format string and optional list of parameters, e.g. h4pUserEvent("Something %s interesting happened","mildly");
template<typename T> T* depend(const string& svc); // dynamically load plugin and hook start/stop dependencies
template<typename T> T* require(const string& svc); // dynamically load plugin
void h4pregisterhandler(const string& svc,uint32_t t,H4P_FN_EVENTHANDLER f); // register an event handler svc
void h4punregisterhandler(const string& svc,uint32_t t); // unregister an event handler
void h4pevent(const string& svc,H4PE_TYPE t,const string& msg=""); // actual;y fire the handler chain
void h4pOnEvent(H4PE_TYPE t,H4P_FN_USEREVENT f); // simple one-type inline event handler function
void h4puiAdd(const string& n,H4P_UI_TYPE t,string h,const string& v,uint8_t c); // adds ui item w/o needing h4p ref
void h4puiSync(const string& n,const string& v); // force webUI sync of field n to value v
The following H4PE_MSG
emitters will be compiled out unless H4P_LOG_MESSAGES
is set to 1 in config_plugins.h
QLOG(f); // Emit simple message event from within code of H4Service with no parameters
SLOG(f,...); // Emit message event from global context, i.e. NOT within code of H4Service
XLOG(f,...); // Emit message event from within code of H4Service
(c) 2021 Phil Bowles [email protected]