Two things are done here: loop() hooks are introduced, and both loop and event handler hooks are pre-allocated for HOOK_MAX (64 by default) elements. Two helpers are introduced too, that make it easier to append a new hook to the end of these arrays. Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>pull/27/head
parent
79ddb15c3b
commit
5a677ce7f0
@ -0,0 +1,27 @@
|
|||||||
|
#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)
|
||||||
|
return;
|
||||||
|
|
||||||
|
eventHandlers[i] = hook;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
loop_hook_add (custom_loop_t hook) {
|
||||||
|
byte i;
|
||||||
|
|
||||||
|
for (i = 0; i < HOOK_MAX && loopHooks[i] != NULL; i++) {
|
||||||
|
}
|
||||||
|
|
||||||
|
if (i == HOOK_MAX)
|
||||||
|
return;
|
||||||
|
|
||||||
|
loopHooks[i] = hook;
|
||||||
|
}
|
@ -0,0 +1,15 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <Arduino.h>
|
||||||
|
|
||||||
|
#define HOOK_MAX 64
|
||||||
|
|
||||||
|
typedef bool (*custom_handler_t)(byte row, byte col, uint8_t currentState, uint8_t previousState);
|
||||||
|
extern custom_handler_t eventHandlers[HOOK_MAX];
|
||||||
|
|
||||||
|
void event_handler_hook_add (custom_handler_t hook);
|
||||||
|
|
||||||
|
typedef void (*custom_loop_t)(void);
|
||||||
|
extern custom_loop_t loopHooks[HOOK_MAX];
|
||||||
|
|
||||||
|
void loop_hook_add (custom_loop_t hook);
|
Loading…
Reference in new issue