Registers a handler function with a selected set of events.
For information on how to use this plugin, see 💎Everything is an event: Listeners, Emitters and Handlers
(H4P_SerialLogger
is simply an H4P_EventListener
with a predefined handler funstion that timply logs the event details to the Serial monitor)
H4P_EventListener is a multiple-use plugin: there can be many in one app. They will appears as 1, 2. 3 etc. They may be instantiated as any name.
H4P_EventListener myEL1(... // internal ref: ears1
H4P_EventListener myEL2(... // internal ref: ears2
H4P_EventListener anyNameYouChoose(... // internal ref: ears3
...
H4P_SerialLogger slog(... // defaults to Serial Monitoe
N/a
N/A
stop
/ start
have no effect
/*
`svc` is a unique identifier of the origin that sent or "emitted" this event see the docs linked above for the valid values)
`type` is the type of event.
`msg` is optional information associated with that event.
typename H4P_FN_EVENTHANDLER
*/
void evt_handler(const string& svc,H4PE_TYPE type,const string& msg);
/* filter is Name of the event (or combination of events) to be fowarded to the event handler function handleEvent is the callback function */
H4P_EventListener(uint32_t filter,H4P_FN_EVENTHANDLER handleEvent);
...
H4P_SerialLogger(uint32_t filter); // default handler does Seril.printf( ... etc)
Numerous examples sketches include the H4P_EventListener
, e.g.
#include<H4Plugins.h>
H4_USE_PLUGINS(115200,H4_Q_CAPACITY,false)
H4P_EventListener gpio(H4PE_GPIO,[](const string& pin,H4PE_TYPE t,const string& msg){
int p=atoi(pin.c_str());
int v=atoi(msg.c_str());
switch(p){
case D1:
Serial.printf("P%d V = %d\n",p,v);
break;
}
});
h4pEncoder rotary(D1,D2);
Example using more than 1 at a time
(c) 2021 Phil Bowles [email protected]