Merge pull request #334 from keyboardio/h/v1-api-ifdefs

Make the V1 plugin API ifdefs broader
pull/336/head
Jesse Vincent 7 years ago committed by GitHub
commit 00e5d54bf7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -3,8 +3,11 @@
namespace kaleidoscope { namespace kaleidoscope {
#if KALEIDOSCOPE_ENABLE_V1_PLUGIN_API
Kaleidoscope_::eventHandlerHook Kaleidoscope_::eventHandlers[HOOK_MAX]; Kaleidoscope_::eventHandlerHook Kaleidoscope_::eventHandlers[HOOK_MAX];
Kaleidoscope_::loopHook Kaleidoscope_::loopHooks[HOOK_MAX]; Kaleidoscope_::loopHook Kaleidoscope_::loopHooks[HOOK_MAX];
#endif
uint32_t Kaleidoscope_::millis_at_cycle_start_; uint32_t Kaleidoscope_::millis_at_cycle_start_;
Kaleidoscope_::Kaleidoscope_(void) { Kaleidoscope_::Kaleidoscope_(void) {
@ -115,67 +118,55 @@ Kaleidoscope_ Kaleidoscope;
#pragma GCC diagnostic push #pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations" #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#if KALEIDOSCOPE_ENABLE_V1_PLUGIN_API
void void
Kaleidoscope_::replaceEventHandlerHook(eventHandlerHook oldHook, eventHandlerHook newHook) { Kaleidoscope_::replaceEventHandlerHook(eventHandlerHook oldHook, eventHandlerHook newHook) {
#if KALEIDOSCOPE_ENABLE_V1_PLUGIN_API
for (byte i = 0; i < HOOK_MAX; i++) { for (byte i = 0; i < HOOK_MAX; i++) {
if (eventHandlers[i] == oldHook) { if (eventHandlers[i] == oldHook) {
eventHandlers[i] = newHook; eventHandlers[i] = newHook;
return; return;
} }
} }
#endif
} }
void void
Kaleidoscope_::appendEventHandlerHook(eventHandlerHook hook) { Kaleidoscope_::appendEventHandlerHook(eventHandlerHook hook) {
#if KALEIDOSCOPE_ENABLE_V1_PLUGIN_API
replaceEventHandlerHook((eventHandlerHook)NULL, hook); replaceEventHandlerHook((eventHandlerHook)NULL, hook);
#endif
} }
void void
Kaleidoscope_::useEventHandlerHook(eventHandlerHook hook) { Kaleidoscope_::useEventHandlerHook(eventHandlerHook hook) {
#if KALEIDOSCOPE_ENABLE_V1_PLUGIN_API
for (byte i = 0; i < HOOK_MAX; i++) { for (byte i = 0; i < HOOK_MAX; i++) {
if (eventHandlers[i] == hook) if (eventHandlers[i] == hook)
return; return;
} }
appendEventHandlerHook(hook); appendEventHandlerHook(hook);
#endif
} }
void void
Kaleidoscope_::replaceLoopHook(loopHook oldHook, loopHook newHook) { Kaleidoscope_::replaceLoopHook(loopHook oldHook, loopHook newHook) {
#if KALEIDOSCOPE_ENABLE_V1_PLUGIN_API
for (byte i = 0; i < HOOK_MAX; i++) { for (byte i = 0; i < HOOK_MAX; i++) {
if (loopHooks[i] == oldHook) { if (loopHooks[i] == oldHook) {
loopHooks[i] = newHook; loopHooks[i] = newHook;
return; return;
} }
} }
#endif
} }
void void
Kaleidoscope_::appendLoopHook(loopHook hook) { Kaleidoscope_::appendLoopHook(loopHook hook) {
#if KALEIDOSCOPE_ENABLE_V1_PLUGIN_API
replaceLoopHook((loopHook)NULL, hook); replaceLoopHook((loopHook)NULL, hook);
#endif
} }
void void
Kaleidoscope_::useLoopHook(loopHook hook) { Kaleidoscope_::useLoopHook(loopHook hook) {
#if KALEIDOSCOPE_ENABLE_V1_PLUGIN_API
for (byte i = 0; i < HOOK_MAX; i++) { for (byte i = 0; i < HOOK_MAX; i++) {
if (loopHooks[i] == hook) if (loopHooks[i] == hook)
return; return;
} }
appendLoopHook(hook); appendLoopHook(hook);
#endif
} }
#if KALEIDOSCOPE_ENABLE_V1_PLUGIN_API
void event_handler_hook_use(Kaleidoscope_::eventHandlerHook hook) { void event_handler_hook_use(Kaleidoscope_::eventHandlerHook hook) {
Kaleidoscope.useEventHandlerHook(hook); Kaleidoscope.useEventHandlerHook(hook);
} }

@ -162,8 +162,12 @@ class Kaleidoscope_ {
* functions will, on the other hand, just append the hooks, and not care about * functions will, on the other hand, just append the hooks, and not care about
* protection. * protection.
*/ */
#if KALEIDOSCOPE_ENABLE_V1_PLUGIN_API
typedef Key(*eventHandlerHook)(Key mappedKey, byte row, byte col, uint8_t keyState); typedef Key(*eventHandlerHook)(Key mappedKey, byte row, byte col, uint8_t keyState);
typedef void (*loopHook)(bool postClear);
static eventHandlerHook eventHandlers[HOOK_MAX]; static eventHandlerHook eventHandlers[HOOK_MAX];
static loopHook loopHooks[HOOK_MAX];
static void replaceEventHandlerHook(eventHandlerHook oldHook, eventHandlerHook newHook) static void replaceEventHandlerHook(eventHandlerHook oldHook, eventHandlerHook newHook)
DEPRECATED(EVENT_HANDLER_HOOK); DEPRECATED(EVENT_HANDLER_HOOK);
@ -172,15 +176,13 @@ class Kaleidoscope_ {
static void useEventHandlerHook(eventHandlerHook hook) static void useEventHandlerHook(eventHandlerHook hook)
DEPRECATED(EVENT_HANDLER_HOOK); DEPRECATED(EVENT_HANDLER_HOOK);
typedef void (*loopHook)(bool postClear);
static loopHook loopHooks[HOOK_MAX];
static void replaceLoopHook(loopHook oldHook, loopHook newHook) static void replaceLoopHook(loopHook oldHook, loopHook newHook)
DEPRECATED(LOOP_HOOK); DEPRECATED(LOOP_HOOK);
static void appendLoopHook(loopHook hook) static void appendLoopHook(loopHook hook)
DEPRECATED(LOOP_HOOK); DEPRECATED(LOOP_HOOK);
static void useLoopHook(loopHook hook) static void useLoopHook(loopHook hook)
DEPRECATED(LOOP_HOOK); DEPRECATED(LOOP_HOOK);
#endif
static bool focusHook(const char *command); static bool focusHook(const char *command);
@ -208,6 +210,7 @@ using kaleidoscope::Kaleidoscope;
"layer.getState") "layer.getState")
/* -- DEPRECATED aliases; remove them when there are no more users. -- */ /* -- DEPRECATED aliases; remove them when there are no more users. -- */
#if KALEIDOSCOPE_ENABLE_V1_PLUGIN_API
void event_handler_hook_use(kaleidoscope::Kaleidoscope_::eventHandlerHook hook) void event_handler_hook_use(kaleidoscope::Kaleidoscope_::eventHandlerHook hook)
DEPRECATED(EVENT_HANDLER_HOOK); DEPRECATED(EVENT_HANDLER_HOOK);
@ -218,6 +221,8 @@ void __USE_PLUGINS(kaleidoscope::Plugin *plugin, ...) DEPRECATED(USE);
#define USE_PLUGINS(...) __USE_PLUGINS(__VA_ARGS__, NULL) #define USE_PLUGINS(...) __USE_PLUGINS(__VA_ARGS__, NULL)
#endif
// Use this function macro to register plugins with Kaleidoscope's // Use this function macro to register plugins with Kaleidoscope's
// hooking system. The macro accepts a list of plugin instances that // hooking system. The macro accepts a list of plugin instances that
// must have been instantiated at global scope. // must have been instantiated at global scope.

Loading…
Cancel
Save