Merge pull request #40 from algernon/f/hooks/additional-helpers
hooks: Add a way to replace hookspull/45/head
commit
4cc81b6c69
@ -1,27 +1,31 @@
|
||||
#include "hooks.h"
|
||||
|
||||
void
|
||||
event_handler_hook_add (custom_handler_t hook) {
|
||||
byte i;
|
||||
|
||||
for (i = 0; i < HOOK_MAX && eventHandlers[i] != NULL; i++) {
|
||||
}
|
||||
|
||||
if (i == HOOK_MAX)
|
||||
event_handler_hook_replace (custom_handler_t oldHook, custom_handler_t newHook) {
|
||||
for (byte i = 0; i < HOOK_MAX; i++) {
|
||||
if (eventHandlers[i] == oldHook) {
|
||||
eventHandlers[i] = newHook;
|
||||
return;
|
||||
|
||||
eventHandlers[i] = hook;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
loop_hook_add (custom_loop_t hook) {
|
||||
byte i;
|
||||
|
||||
for (i = 0; i < HOOK_MAX && loopHooks[i] != NULL; i++) {
|
||||
event_handler_hook_add (custom_handler_t hook) {
|
||||
event_handler_hook_replace ((custom_handler_t)NULL, hook);
|
||||
}
|
||||
|
||||
if (i == HOOK_MAX)
|
||||
void
|
||||
loop_hook_replace (custom_loop_t oldHook, custom_loop_t newHook) {
|
||||
for (byte i = 0; i < HOOK_MAX; i++) {
|
||||
if (loopHooks[i] == oldHook) {
|
||||
loopHooks[i] = newHook;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
loopHooks[i] = hook;
|
||||
void
|
||||
loop_hook_add (custom_loop_t hook) {
|
||||
loop_hook_replace ((custom_loop_t)NULL, hook);
|
||||
}
|
||||
|
Loading…
Reference in new issue