We can't register hooks from constructors, because there is no guaranteed order in which the objects will be created. So it may well happen that the Keyboardio object gets created later, and zeroes out everything. Or it gets created first, and registers the default handler as the first one, making all the others pointless. Instead, we create a KeyboardioPlugin class, that has a `begin` method. This is responsible for setting up the hooks and whatnot. To make things simpler (for some values of simple), a `Keyboardio.use` method is introduced, which, when given a NULL-terminated list of plugin object pointers, will call the begin method of each. All LED effects and other plugins that used to register a static object now use an extern, and had their initialization moved to the `begin` method. The end result is not the nicest thing, but it works. We can try figuring out something nicer later. Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>pull/68/head
parent
15e9be25bb
commit
afac5ed6f2
@ -1,14 +1,14 @@
|
||||
#include "LED-BreatheEffect.h"
|
||||
|
||||
LEDBreatheEffect::LEDBreatheEffect (void) {
|
||||
LEDBreatheEffect_::LEDBreatheEffect_ (void) {
|
||||
state.brightness = 0;
|
||||
state.fadeAmount = 1;
|
||||
|
||||
LEDControl.mode_add (this);
|
||||
}
|
||||
|
||||
void
|
||||
LEDBreatheEffect::update (void) {
|
||||
LEDBreatheEffect_::update (void) {
|
||||
cRGB color = breath_compute (&state);
|
||||
LEDControl.set_all_leds_to (color);
|
||||
}
|
||||
|
||||
LEDBreatheEffect_ LEDBreatheEffect;
|
||||
|
@ -0,0 +1,3 @@
|
||||
#include "LED-Off.h"
|
||||
|
||||
LEDOff_ LEDOff;
|
@ -0,0 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
class KeyboardioPlugin {
|
||||
public:
|
||||
virtual void begin(void) = 0;
|
||||
};
|
||||
|
Loading…
Reference in new issue